Codebase list orthanc-dicomweb / c12a0b6
New upstream version 1.2+dfsg jodogne-guest 3 years ago
23 changed file(s) with 8524 addition(s) and 15239 deletion(s). Raw diff Collapse all Expand all
00 repo: d5f45924411123cfd02d035fd50b8e37536eadef
1 node: 1e19bf059f49747d3f28ab8e3cf24607c7a64689
2 branch: OrthancDicomWeb-1.1
1 node: 76233f8f867fe027b31698fe8596e727d1e4dd67
2 branch: OrthancDicomWeb-1.2
33 latesttag: null
4 latesttagdistance: 380
5 changessincelatesttag: 398
4 latesttagdistance: 400
5 changessincelatesttag: 429
2020
2121 project(OrthancDicomWeb)
2222
23 set(ORTHANC_DICOM_WEB_VERSION "1.1")
23 set(ORTHANC_DICOM_WEB_VERSION "1.2")
2424
2525 if (ORTHANC_DICOM_WEB_VERSION STREQUAL "mainline")
2626 set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "mainline")
2727 set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
2828 else()
29 set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "ae0e3fd609df") # This is pre-1.6.0
29 set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "1.7.0")
3030 set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
3131 endif()
3232
4040 set(ORTHANC_FRAMEWORK_ROOT "" CACHE STRING "Path to the Orthanc source directory, if ORTHANC_FRAMEWORK_SOURCE is \"path\"")
4141
4242 # Advanced parameters to fine-tune linking against system libraries
43 set(USE_SYSTEM_GDCM ON CACHE BOOL "Use the system version of Grassroot DICOM (GDCM)")
4443 set(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK")
45 set(ORTHANC_SDK_VERSION "1.5.7" CACHE STRING "Version of the Orthanc plugin SDK to use, if not using the system version (can be \"1.5.4\", \"1.5.7\", or \"framework\")")
44 set(ORTHANC_SDK_VERSION "1.7.0" CACHE STRING "Version of the Orthanc plugin SDK to use, if not using the system version (can be \"1.7.0\", or \"framework\")")
4645
4746
4847 set(BUILD_BOOTSTRAP_VUE OFF CACHE BOOL "Compile Bootstrap-Vue from sources")
6564 include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkConfiguration.cmake)
6665 include_directories(${ORTHANC_ROOT})
6766
68 include(${CMAKE_SOURCE_DIR}/Resources/CMake/GdcmConfiguration.cmake)
6967 include(${CMAKE_SOURCE_DIR}/Resources/CMake/JavaScriptLibraries.cmake)
7068
7169
7270 if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK)
73 if (ORTHANC_SDK_VERSION STREQUAL "1.5.4")
74 include_directories(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-1.5.4)
75 elseif (ORTHANC_SDK_VERSION STREQUAL "1.5.7")
76 include_directories(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-1.5.7)
71 if (ORTHANC_SDK_VERSION STREQUAL "1.7.0")
72 include_directories(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-1.7.0)
7773 elseif (ORTHANC_SDK_VERSION STREQUAL "framework")
7874 include_directories(${ORTHANC_ROOT}/Plugins/Include)
7975 else()
145141
146142 set(CORE_SOURCES
147143 Plugin/Configuration.cpp
148 Plugin/GdcmParsedDicomFile.cpp
149144
150145 ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
151146 ${ORTHANC_CORE_SOURCES}
164159 ${CMAKE_SOURCE_DIR}/Plugin/WadoUri.cpp
165160 ${AUTOGENERATED_SOURCES}
166161 )
167
168 target_link_libraries(OrthancDicomWeb ${GDCM_LIBRARIES})
169162
170163 message("Setting the version of the library to ${ORTHANC_DICOM_WEB_VERSION}")
171164
190183 )
191184
192185 target_link_libraries(UnitTests
193 ${GDCM_LIBRARIES}
194186 ${GOOGLE_TEST_LIBRARIES}
195187 )
196
197 if (STATIC_BUILD OR NOT USE_SYSTEM_GDCM)
198 add_dependencies(OrthancDicomWeb GDCM)
199 add_dependencies(UnitTests GDCM)
200 endif()
00 Pending changes in the mainline
11 ===============================
2
3
4
5 Version 1.2 (2020-05-26)
6 ========================
7
8 => Minimum SDK version: 1.7.0 <=
9
10 * Removed dependency on GDCM
11 * "QidoCaseSensitive" defaults to "CaseSensitivePN" of Orthanc configuration (instead of "true")
212
313
414 Version 1.1 (2020-03-04)
333333 }
334334
335335
336 bool LookupBooleanValue(bool& target,
337 const std::string& key)
338 {
339 assert(configuration_.get() != NULL);
340 return configuration_->LookupBooleanValue(target, key);
341 }
342
343
336344 unsigned int GetUnsignedIntegerValue(const std::string& key,
337345 unsigned int defaultValue)
338346 {
9191 {
9292 void Initialize();
9393
94 std::string GetStringValue(const std::string& key,
95 const std::string& defaultValue);
96
94 bool HasKey(const std::string& key);
95
9796 bool GetBooleanValue(const std::string& key,
9897 bool defaultValue);
98
99 bool LookupBooleanValue(bool& target,
100 const std::string& key);
99101
100102 unsigned int GetUnsignedIntegerValue(const std::string& key,
101103 unsigned int defaultValue);
4646 const uint32_t *levelIndex,
4747 uint16_t tagGroup,
4848 uint16_t tagElement,
49 OrthancPluginValueRepresentation vr)
50 {
51 const DicomWebFormatter& that = GetSingleton();
49 OrthancPluginValueRepresentation vr,
50 void* payload)
51 {
52 const DicomWebFormatter& that = *reinterpret_cast<const DicomWebFormatter*>(payload);
5253
5354 switch (that.mode_)
5455 {
5960
6061 case OrthancPluginDicomWebBinaryMode_BulkDataUri:
6162 {
62 std::string uri = GetSingleton().bulkRoot_;
63 std::string uri = that.bulkRoot_;
6364
6465 for (size_t i = 0; i < levelDepth; i++)
6566 {
7677 }
7778
7879
79 DicomWebFormatter::Locker::Locker(OrthancPluginDicomWebBinaryMode mode,
80 const std::string& bulkRoot) :
81 that_(GetSingleton()),
82 lock_(that_.mutex_)
83 {
84 that_.mode_ = mode;
85 that_.bulkRoot_ = bulkRoot;
86 }
87
88
89 void DicomWebFormatter::Locker::Apply(std::string& target,
90 OrthancPluginContext* context,
91 const void* data,
92 size_t size,
93 bool xml)
94 {
80 void DicomWebFormatter::Apply(std::string& target,
81 OrthancPluginContext* context,
82 const void* data,
83 size_t size,
84 bool xml,
85 OrthancPluginDicomWebBinaryMode mode,
86 const std::string& bulkRoot)
87 {
88 DicomWebFormatter payload(mode, bulkRoot);
89
9590 OrthancString s;
9691
9792 if (xml)
9893 {
99 s.Assign(OrthancPluginEncodeDicomWebXml(context, data, size, Callback));
100 }
101 else
102 {
103 s.Assign(OrthancPluginEncodeDicomWebJson(context, data, size, Callback));
94 s.Assign(OrthancPluginEncodeDicomWebXml2(context, data, size, Callback, &payload));
95 }
96 else
97 {
98 s.Assign(OrthancPluginEncodeDicomWebJson2(context, data, size, Callback, &payload));
10499 }
105100
106101 if (s.GetContent() == NULL)
115110 }
116111
117112
118 void DicomWebFormatter::Locker::Apply(std::string& target,
119 OrthancPluginContext* context,
120 const Json::Value& value,
121 bool xml)
113 void DicomWebFormatter::Apply(std::string& target,
114 OrthancPluginContext* context,
115 const Json::Value& value,
116 bool xml,
117 OrthancPluginDicomWebBinaryMode mode,
118 const std::string& bulkRoot)
122119 {
123120 MemoryBuffer dicom;
124121 dicom.CreateDicom(value, OrthancPluginCreateDicomFlags_None);
125 Apply(target, context, dicom.GetData(), dicom.GetSize(), xml);
122 Apply(target, context, dicom.GetData(), dicom.GetSize(), xml, mode, bulkRoot);
126123 }
127124
128125
165162
166163 std::string item;
167164
168 {
169 // TODO - Avoid a global mutex => Need to change Orthanc SDK
170 OrthancPlugins::DicomWebFormatter::Locker locker(mode, bulkRoot);
171 locker.Apply(item, context_, dicom, size, isXml_);
172 }
165 OrthancPlugins::DicomWebFormatter::Apply(
166 item, context_, dicom, size, isXml_, mode, bulkRoot);
173167
174168 if (isXml_)
175169 {
2828 #include <json/value.h>
2929
3030 #include <boost/noncopyable.hpp>
31 #include <boost/thread/mutex.hpp>
3231
3332
3433 namespace OrthancPlugins
3635 class DicomWebFormatter : public boost::noncopyable
3736 {
3837 private:
39 boost::mutex mutex_;
4038 OrthancPluginDicomWebBinaryMode mode_;
4139 std::string bulkRoot_;
42
43 static DicomWebFormatter& GetSingleton()
44 {
45 static DicomWebFormatter formatter;
46 return formatter;
47 }
4840
4941 static void Callback(OrthancPluginDicomWebNode *node,
5042 OrthancPluginDicomWebSetBinaryNode setter,
5446 const uint32_t *levelIndex,
5547 uint16_t tagGroup,
5648 uint16_t tagElement,
57 OrthancPluginValueRepresentation vr);
49 OrthancPluginValueRepresentation vr,
50 void* payload);
5851
52 DicomWebFormatter(OrthancPluginDicomWebBinaryMode mode,
53 const std::string& bulkRoot) :
54 mode_(mode),
55 bulkRoot_(bulkRoot)
56 {
57 }
58
5959 public:
60 class Locker : public boost::noncopyable
61 {
62 private:
63 DicomWebFormatter& that_;
64 boost::mutex::scoped_lock lock_;
60 static void Apply(std::string& target,
61 OrthancPluginContext* context,
62 const void* data,
63 size_t size,
64 bool xml,
65 OrthancPluginDicomWebBinaryMode mode,
66 const std::string& bulkRoot);
6567
66 public:
67 Locker(OrthancPluginDicomWebBinaryMode mode,
68 const std::string& bulkRoot);
69
70 void Apply(std::string& target,
71 OrthancPluginContext* context,
72 const void* data,
73 size_t size,
74 bool xml);
75
76 void Apply(std::string& target,
77 OrthancPluginContext* context,
78 const Json::Value& value,
79 bool xml);
80 };
68 static void Apply(std::string& target,
69 OrthancPluginContext* context,
70 const Json::Value& value,
71 bool xml,
72 OrthancPluginDicomWebBinaryMode mode,
73 const std::string& bulkRoot);
8174
8275 class HttpWriter : public boost::noncopyable
8376 {
+0
-435
Plugin/GdcmParsedDicomFile.cpp less more
0 /**
1 * Orthanc - A Lightweight, RESTful DICOM Store
2 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3 * Department, University Hospital of Liege, Belgium
4 * Copyright (C) 2017-2020 Osimis S.A., Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20
21 #include "GdcmParsedDicomFile.h"
22
23 #include "ChunkedBuffer.h"
24
25 #include <Core/Toolbox.h>
26
27 #include <gdcmDict.h>
28 #include <gdcmDictEntry.h>
29 #include <gdcmDicts.h>
30 #include <gdcmGlobal.h>
31 #include <gdcmStringFilter.h>
32
33 #include <boost/lexical_cast.hpp>
34 #include <json/writer.h>
35
36
37 namespace OrthancPlugins
38 {
39 static const gdcm::Dict* dictionary_ = NULL;
40
41
42 void GdcmParsedDicomFile::Initialize()
43 {
44 if (dictionary_ != NULL)
45 {
46 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
47 }
48 else
49 {
50 dictionary_ = &gdcm::Global::GetInstance().GetDicts().GetPublicDict();
51
52 if (dictionary_ == NULL)
53 {
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
55 "Cannot initialize the DICOM dictionary of GDCM");
56 }
57 }
58 }
59
60
61 static std::string MyStripSpaces(const std::string& source)
62 {
63 size_t first = 0;
64
65 while (first < source.length() &&
66 (isspace(source[first]) ||
67 source[first] == '\0'))
68 {
69 first++;
70 }
71
72 if (first == source.length())
73 {
74 // String containing only spaces
75 return "";
76 }
77
78 size_t last = source.length();
79 while (last > first &&
80 (isspace(source[last - 1]) ||
81 source[last - 1] == '\0'))
82 {
83 last--;
84 }
85
86 assert(first <= last);
87 return source.substr(first, last - first);
88 }
89
90
91 static const char* GetVRName(bool& isSequence,
92 const gdcm::Tag& tag,
93 gdcm::VR vr)
94 {
95 if (dictionary_ == NULL)
96 {
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
98 "GDCM has not been initialized");
99 }
100
101 if (vr == gdcm::VR::INVALID)
102 {
103 const gdcm::DictEntry &entry = dictionary_->GetDictEntry(tag);
104 vr = entry.GetVR();
105
106 if (vr == gdcm::VR::OB_OW)
107 {
108 vr = gdcm::VR::OB;
109 }
110 }
111
112 isSequence = (vr == gdcm::VR::SQ);
113
114 const char* str = gdcm::VR::GetVRString(vr);
115 if (isSequence)
116 {
117 return str;
118 }
119
120 if (str == NULL ||
121 strlen(str) != 2 ||
122 !(str[0] >= 'A' && str[0] <= 'Z') ||
123 !(str[1] >= 'A' && str[1] <= 'Z'))
124 {
125 return "UN";
126 }
127 else
128 {
129 return str;
130 }
131 }
132
133
134 static const char* GetVRName(bool& isSequence,
135 const gdcm::DataElement& element)
136 {
137 return GetVRName(isSequence, element.GetTag(), element.GetVR());
138 }
139
140
141 template <int T>
142 static void ConvertNumberTag(std::string& target,
143 const gdcm::DataElement& source)
144 {
145 if (source.IsEmpty())
146 {
147 target.clear();
148 }
149 else
150 {
151 typename gdcm::Element<T, gdcm::VM::VM1_n> element;
152
153 element.Set(source.GetValue());
154
155 for (unsigned int i = 0; i < element.GetLength(); i++)
156 {
157 if (i != 0)
158 {
159 target += "\\";
160 }
161
162 target = boost::lexical_cast<std::string>(element.GetValue());
163 }
164 }
165 }
166
167
168 static bool ConvertDicomStringToUtf8(std::string& result,
169 const gdcm::DataElement& element,
170 const Orthanc::Encoding sourceEncoding)
171 {
172 const gdcm::ByteValue* data = element.GetByteValue();
173 if (!data)
174 {
175 return false;
176 }
177
178 bool isSequence;
179 std::string vr = GetVRName(isSequence, element);
180
181 if (!isSequence)
182 {
183 if (vr == "FL")
184 {
185 ConvertNumberTag<gdcm::VR::FL>(result, element);
186 return true;
187 }
188 else if (vr == "FD")
189 {
190 ConvertNumberTag<gdcm::VR::FD>(result, element);
191 return true;
192 }
193 else if (vr == "SL")
194 {
195 ConvertNumberTag<gdcm::VR::SL>(result, element);
196 return true;
197 }
198 else if (vr == "SS")
199 {
200 ConvertNumberTag<gdcm::VR::SS>(result, element);
201 return true;
202 }
203 else if (vr == "UL")
204 {
205 ConvertNumberTag<gdcm::VR::UL>(result, element);
206 return true;
207 }
208 else if (vr == "US")
209 {
210 ConvertNumberTag<gdcm::VR::US>(result, element);
211 return true;
212 }
213 }
214
215 if (sourceEncoding == Orthanc::Encoding_Utf8)
216 {
217 result.assign(data->GetPointer(), data->GetLength());
218 }
219 else
220 {
221 std::string tmp(data->GetPointer(), data->GetLength());
222 result = Orthanc::Toolbox::ConvertToUtf8(tmp, sourceEncoding, false);
223 }
224
225 result = MyStripSpaces(result);
226 return true;
227 }
228
229
230
231 void GdcmParsedDicomFile::Setup(const std::string& dicom)
232 {
233 // Prepare a memory stream over the DICOM instance
234 std::stringstream stream(dicom);
235
236 // Parse the DICOM instance using GDCM
237 reader_.SetStream(stream);
238
239 if (!reader_.Read())
240 {
241 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
242 "GDCM cannot decode this DICOM instance of length " +
243 boost::lexical_cast<std::string>(dicom.size()));
244 }
245 }
246
247
248 GdcmParsedDicomFile::GdcmParsedDicomFile(const OrthancPlugins::MemoryBuffer& buffer)
249 {
250 // TODO Avoid this unnecessary memcpy by defining a stream over the MemoryBuffer
251 std::string dicom(buffer.GetData(), buffer.GetData() + buffer.GetSize());
252 Setup(dicom);
253 }
254
255
256 static bool GetRawTag(std::string& result,
257 const gdcm::DataSet& dataset,
258 const gdcm::Tag& tag,
259 bool stripSpaces)
260 {
261 if (dataset.FindDataElement(tag))
262 {
263 const gdcm::ByteValue* value = dataset.GetDataElement(tag).GetByteValue();
264 if (value)
265 {
266 result.assign(value->GetPointer(), value->GetLength());
267
268 if (stripSpaces)
269 {
270 result = MyStripSpaces(result);
271 }
272
273 return true;
274 }
275 }
276
277 return false;
278 }
279
280
281 bool GdcmParsedDicomFile::GetRawTag(std::string& result,
282 const gdcm::Tag& tag,
283 bool stripSpaces) const
284 {
285 return OrthancPlugins::GetRawTag(result, GetDataSet(), tag, stripSpaces);
286 }
287
288
289 std::string GdcmParsedDicomFile::GetRawTagWithDefault(const gdcm::Tag& tag,
290 const std::string& defaultValue,
291 bool stripSpaces) const
292 {
293 std::string result;
294 if (!GetRawTag(result, tag, stripSpaces))
295 {
296 return defaultValue;
297 }
298 else
299 {
300 return result;
301 }
302 }
303
304
305 std::string GdcmParsedDicomFile::GetRawTagWithDefault(const Orthanc::DicomTag& tag,
306 const std::string& defaultValue,
307 bool stripSpaces) const
308 {
309 gdcm::Tag t(tag.GetGroup(), tag.GetElement());
310 return GetRawTagWithDefault(t, defaultValue, stripSpaces);
311 }
312
313
314 bool GdcmParsedDicomFile::GetStringTag(std::string& result,
315 const gdcm::Tag& tag,
316 bool stripSpaces) const
317 {
318 if (!GetDataSet().FindDataElement(tag))
319 {
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag);
321 }
322
323 const gdcm::DataElement& element = GetDataSet().GetDataElement(tag);
324
325 if (!ConvertDicomStringToUtf8(result, element, GetEncoding()))
326 {
327 return false;
328 }
329
330 if (stripSpaces)
331 {
332 result = MyStripSpaces(result);
333 }
334
335 return true;
336 }
337
338
339 bool GdcmParsedDicomFile::GetIntegerTag(int& result,
340 const gdcm::Tag& tag) const
341 {
342 std::string tmp;
343 if (!GetStringTag(tmp, tag, true))
344 {
345 return false;
346 }
347
348 try
349 {
350 result = boost::lexical_cast<int>(tmp);
351 return true;
352 }
353 catch (boost::bad_lexical_cast&)
354 {
355 return false;
356 }
357 }
358
359
360 std::string FormatTag(const gdcm::Tag& tag)
361 {
362 char tmp[16];
363 sprintf(tmp, "%04X%04X", tag.GetGroup(), tag.GetElement());
364 return std::string(tmp);
365 }
366
367
368 static std::string GetWadoUrl(const std::string& wadoBase,
369 const gdcm::DataSet& dicom)
370 {
371 static const gdcm::Tag DICOM_TAG_STUDY_INSTANCE_UID(0x0020, 0x000d);
372 static const gdcm::Tag DICOM_TAG_SERIES_INSTANCE_UID(0x0020, 0x000e);
373 static const gdcm::Tag DICOM_TAG_SOP_INSTANCE_UID(0x0008, 0x0018);
374
375 std::string study, series, instance;
376
377 if (!GetRawTag(study, dicom, DICOM_TAG_STUDY_INSTANCE_UID, true) ||
378 !GetRawTag(series, dicom, DICOM_TAG_SERIES_INSTANCE_UID, true) ||
379 !GetRawTag(instance, dicom, DICOM_TAG_SOP_INSTANCE_UID, true))
380 {
381 return "";
382 }
383 else
384 {
385 return Configuration::GetWadoUrl(wadoBase, study, series, instance);
386 }
387 }
388
389
390 static Orthanc::Encoding DetectEncoding(const gdcm::DataSet& dicom)
391 {
392 static const gdcm::Tag DICOM_TAG_SPECIFIC_CHARACTER_SET(0x0008, 0x0005);
393
394 if (!dicom.FindDataElement(DICOM_TAG_SPECIFIC_CHARACTER_SET))
395 {
396 return Orthanc::Encoding_Ascii;
397 }
398
399 const gdcm::DataElement& element =
400 dicom.GetDataElement(DICOM_TAG_SPECIFIC_CHARACTER_SET);
401
402 const gdcm::ByteValue* data = element.GetByteValue();
403 if (!data)
404 {
405 return Configuration::GetDefaultEncoding();
406 }
407
408 std::string tmp(data->GetPointer(), data->GetLength());
409 tmp = MyStripSpaces(tmp);
410
411 Orthanc::Encoding encoding;
412 if (Orthanc::GetDicomEncoding(encoding, tmp.c_str()))
413 {
414 return encoding;
415 }
416 else
417 {
418 return Configuration::GetDefaultEncoding();
419 }
420 }
421
422
423 Orthanc::Encoding GdcmParsedDicomFile::GetEncoding() const
424 {
425 return DetectEncoding(GetDataSet());
426 }
427
428
429 std::string GdcmParsedDicomFile::GetWadoUrl(const OrthancPluginHttpRequest* request) const
430 {
431 const std::string base = OrthancPlugins::Configuration::GetBaseUrl(request);
432 return OrthancPlugins::GetWadoUrl(base, GetDataSet());
433 }
434 }
+0
-89
Plugin/GdcmParsedDicomFile.h less more
0 /**
1 * Orthanc - A Lightweight, RESTful DICOM Store
2 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3 * Department, University Hospital of Liege, Belgium
4 * Copyright (C) 2017-2020 Osimis S.A., Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20
21 #pragma once
22
23 #include "Configuration.h"
24
25 #include <Core/ChunkedBuffer.h>
26 #include <Core/Enumerations.h>
27 #include <Core/DicomFormat/DicomTag.h>
28 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
29
30 #include <gdcmReader.h>
31 #include <gdcmDataSet.h>
32 #include <pugixml.hpp>
33 #include <list>
34
35
36 namespace OrthancPlugins
37 {
38 class GdcmParsedDicomFile : public boost::noncopyable
39 {
40 private:
41 gdcm::Reader reader_;
42
43 void Setup(const std::string& dicom);
44
45 Orthanc::Encoding GetEncoding() const;
46
47 public:
48 static void Initialize();
49
50 explicit GdcmParsedDicomFile(const OrthancPlugins::MemoryBuffer& item);
51
52 explicit GdcmParsedDicomFile(const std::string& dicom)
53 {
54 Setup(dicom);
55 }
56
57 const gdcm::File& GetFile() const
58 {
59 return reader_.GetFile();
60 }
61
62 const gdcm::DataSet& GetDataSet() const
63 {
64 return reader_.GetFile().GetDataSet();
65 }
66
67 bool GetRawTag(std::string& result,
68 const gdcm::Tag& tag,
69 bool stripSpaces) const;
70
71 std::string GetRawTagWithDefault(const gdcm::Tag& tag,
72 const std::string& defaultValue,
73 bool stripSpaces) const;
74
75 std::string GetRawTagWithDefault(const Orthanc::DicomTag& tag,
76 const std::string& defaultValue,
77 bool stripSpaces) const;
78
79 bool GetStringTag(std::string& result,
80 const gdcm::Tag& tag,
81 bool stripSpaces) const;
82
83 bool GetIntegerTag(int& result,
84 const gdcm::Tag& tag) const;
85
86 std::string GetWadoUrl(const OrthancPluginHttpRequest* request) const;
87 };
88 }
1919
2020 #include "DicomWebClient.h"
2121 #include "DicomWebServers.h"
22 #include "GdcmParsedDicomFile.h"
2322 #include "QidoRs.h"
2423 #include "StowRs.h"
2524 #include "WadoRs.h"
481480 {
482481 // Read the configuration
483482 OrthancPlugins::Configuration::Initialize();
484
485 // Initialize GDCM
486 OrthancPlugins::GdcmParsedDicomFile::Initialize();
487483
488484 // Configure the DICOMweb callbacks
489485 if (OrthancPlugins::Configuration::GetBooleanValue("Enable", true))
512508 OrthancPlugins::RegisterRestCallback<RetrieveBulkData>(root + "studies/([^/]*)/series/([^/]*)/instances/([^/]*)/bulk/(.*)", true);
513509 OrthancPlugins::RegisterRestCallback<RetrieveInstanceMetadata>(root + "studies/([^/]*)/series/([^/]*)/instances/([^/]*)/metadata", true);
514510 OrthancPlugins::RegisterRestCallback<RetrieveSeriesMetadata>(root + "studies/([^/]*)/series/([^/]*)/metadata", true);
515 OrthancPlugins::RegisterRestCallback<RetrieveFrames>(root + "studies/([^/]*)/series/([^/]*)/instances/([^/]*)/frames", true);
516 OrthancPlugins::RegisterRestCallback<RetrieveFrames>(root + "studies/([^/]*)/series/([^/]*)/instances/([^/]*)/frames/([^/]*)", true);
511 OrthancPlugins::RegisterRestCallback<RetrieveAllFrames>(root + "studies/([^/]*)/series/([^/]*)/instances/([^/]*)/frames", true);
512 OrthancPlugins::RegisterRestCallback<RetrieveSelectedFrames>(root + "studies/([^/]*)/series/([^/]*)/instances/([^/]*)/frames/([^/]*)", true);
517513
518514 OrthancPlugins::RegisterRestCallback<ListServers>(root + "servers", true);
519515 OrthancPlugins::RegisterRestCallback<ListServerOperations>(root + "servers/([^/]*)", true);
264264 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
265265 }
266266
267 bool caseSensitive;
268 if (OrthancPlugins::Configuration::LookupBooleanValue(caseSensitive, "QidoCaseSensitive"))
269 {
270 result["CaseSensitive"] = caseSensitive;
271 }
272
267273 result["Expand"] = false;
268 result["CaseSensitive"] = OrthancPlugins::Configuration::GetBooleanValue("QidoCaseSensitive", true);
269274 result["Query"] = Json::objectValue;
270275 result["Limit"] = limit_;
271276 result["Since"] = offset_;
482487 Json::Value find;
483488 matcher.ConvertToOrthanc(find, level);
484489
490 LOG(INFO) << "Body of the call from QIDO-RS to /tools/find: " << find.toStyledString();
491
485492 std::string body;
486493
487494 {
190190
191191 std::string answer;
192192
193 {
194 DicomWebFormatter::Locker locker(OrthancPluginDicomWebBinaryMode_Ignore, "");
195 locker.Apply(answer, context_, result_, xml_);
196 }
193 DicomWebFormatter::Apply(answer, context_, result_, xml_,
194 OrthancPluginDicomWebBinaryMode_Ignore, "");
197195
198196 OrthancPluginAnswerBuffer(context_, output, answer.c_str(), answer.size(),
199197 xml_ ? "application/dicom+xml" : "application/dicom+json");
691691 std::string dicomweb;
692692 {
693693 // TODO - Avoid a global mutex => Need to change Orthanc SDK
694 OrthancPlugins::DicomWebFormatter::Locker locker(OrthancPluginDicomWebBinaryMode_Ignore, "");
695 locker.Apply(dicomweb, OrthancPlugins::GetGlobalContext(),
696 buffer.GetData(), buffer.GetSize(), false /* JSON */);
694 OrthancPlugins::DicomWebFormatter::Apply(
695 dicomweb, OrthancPlugins::GetGlobalContext(), buffer.GetData(), buffer.GetSize(),
696 false /* JSON */, OrthancPluginDicomWebBinaryMode_Ignore, "");
697697 }
698698
699699 buffer.RestApiPut("/instances/" + orthancId + "/attachments/4444", dicomweb, false);
6969 const char* url,
7070 const OrthancPluginHttpRequest* request);
7171
72 void RetrieveFrames(OrthancPluginRestOutput* output,
73 const char* url,
74 const OrthancPluginHttpRequest* request);
72 void RetrieveAllFrames(OrthancPluginRestOutput* output,
73 const char* url,
74 const OrthancPluginHttpRequest* request);
75
76 void RetrieveSelectedFrames(OrthancPluginRestOutput* output,
77 const char* url,
78 const OrthancPluginHttpRequest* request);
7579
7680 void RetrieveInstanceRendered(OrthancPluginRestOutput* output,
7781 const char* url,
2020
2121 #include "WadoRs.h"
2222
23 #include "GdcmParsedDicomFile.h"
24
2523 #include <Core/Toolbox.h>
2624 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
2725
2826 #include <memory>
2927 #include <list>
30 #include <gdcmImageReader.h>
31 #include <gdcmImageWriter.h>
32 #include <gdcmImageChangeTransferSyntax.h>
3328 #include <boost/algorithm/string/replace.hpp>
3429 #include <boost/lexical_cast.hpp>
35
3630
3731
3832 static void TokenizeAndNormalize(std::vector<std::string>& tokens,
6155
6256
6357
64 static gdcm::TransferSyntax ParseTransferSyntax(const OrthancPluginHttpRequest* request,
65 gdcm::TransferSyntax sourceTransferSyntax)
58 static bool ParseTransferSyntax(Orthanc::DicomTransferSyntax& syntax,
59 const OrthancPluginHttpRequest* request)
6660 {
6761 for (uint32_t i = 0; i < request->headersCount; i++)
6862 {
7771 if (tokens.size() == 0 ||
7872 tokens[0] == "*/*")
7973 {
80 return gdcm::TransferSyntax::ExplicitVRLittleEndian;
74 syntax = Orthanc::DicomTransferSyntax_LittleEndianExplicit;
75 return true;
8176 }
8277
8378 if (tokens[0] != "multipart/related")
113108
114109 if (type == "application/octet-stream")
115110 {
116 if (transferSyntax.empty())
117 {
118 return gdcm::TransferSyntax(gdcm::TransferSyntax::ExplicitVRLittleEndian);
111 if (transferSyntax.empty() ||
112 transferSyntax == "1.2.840.10008.1.2.1")
113 {
114 syntax = Orthanc::DicomTransferSyntax_LittleEndianExplicit;
115 return true;
116 }
117 else if (transferSyntax == "1.2.840.10008.1.2")
118 {
119 syntax = Orthanc::DicomTransferSyntax_LittleEndianImplicit;
120 return true;
119121 }
120122 else if (transferSyntax == "*")
121123 {
122124 // New in DICOMweb plugin 1.1.0
123 return sourceTransferSyntax;
125 return false;
124126 }
125127 else
126128 {
139141 if (type == "image/jpeg" && (transferSyntax.empty() || // Default
140142 transferSyntax == "1.2.840.10008.1.2.4.70"))
141143 {
142 return gdcm::TransferSyntax::JPEGLosslessProcess14_1;
144 syntax = Orthanc::DicomTransferSyntax_JPEGProcess14SV1;
145 return true;
143146 }
144147 else if (type == "image/jpeg" && transferSyntax == "1.2.840.10008.1.2.4.50")
145148 {
146 return gdcm::TransferSyntax::JPEGBaselineProcess1;
149 syntax = Orthanc::DicomTransferSyntax_JPEGProcess1;
150 return true;
147151 }
148152 else if (type == "image/jpeg" && transferSyntax == "1.2.840.10008.1.2.4.51")
149153 {
150 return gdcm::TransferSyntax::JPEGExtendedProcess2_4;
154 syntax = Orthanc::DicomTransferSyntax_JPEGProcess2_4;
155 return true;
151156 }
152157 else if (type == "image/jpeg" && transferSyntax == "1.2.840.10008.1.2.4.57")
153158 {
154 return gdcm::TransferSyntax::JPEGLosslessProcess14;
159 syntax = Orthanc::DicomTransferSyntax_JPEGProcess14;
160 return true;
155161 }
156162 else if (type == "image/x-dicom-rle" && (transferSyntax.empty() || // Default
157163 transferSyntax == "1.2.840.10008.1.2.5"))
158164 {
159 return gdcm::TransferSyntax::RLELossless;
165 syntax = Orthanc::DicomTransferSyntax_RLELossless;
166 return true;
160167 }
161168 else if (type == "image/x-jls" && (transferSyntax.empty() || // Default
162169 transferSyntax == "1.2.840.10008.1.2.4.80"))
163170 {
164 return gdcm::TransferSyntax::JPEGLSLossless;
171 syntax = Orthanc::DicomTransferSyntax_JPEGLSLossless;
172 return true;
165173 }
166174 else if (type == "image/x-jls" && transferSyntax == "1.2.840.10008.1.2.4.81")
167175 {
168 return gdcm::TransferSyntax::JPEGLSNearLossless;
176 syntax = Orthanc::DicomTransferSyntax_JPEGLSLossy;
177 return true;
169178 }
170179 else if (type == "image/jp2" && (transferSyntax.empty() || // Default
171180 transferSyntax == "1.2.840.10008.1.2.4.90"))
172181 {
173 return gdcm::TransferSyntax::JPEG2000Lossless;
182 syntax = Orthanc::DicomTransferSyntax_JPEG2000LosslessOnly;
183 return true;
174184 }
175185 else if (type == "image/jp2" && transferSyntax == "1.2.840.10008.1.2.4.91")
176186 {
177 return gdcm::TransferSyntax::JPEG2000;
187 syntax = Orthanc::DicomTransferSyntax_JPEG2000;
188 return true;
178189 }
179190 else if (type == "image/jpx" && (transferSyntax.empty() || // Default
180191 transferSyntax == "1.2.840.10008.1.2.4.92"))
181192 {
182 return gdcm::TransferSyntax::JPEG2000Part2Lossless;
193 syntax = Orthanc::DicomTransferSyntax_JPEG2000MulticomponentLosslessOnly;
194 return true;
183195 }
184196 else if (type == "image/jpx" && transferSyntax == "1.2.840.10008.1.2.4.93")
185197 {
186 return gdcm::TransferSyntax::JPEG2000Part2;
198 syntax = Orthanc::DicomTransferSyntax_JPEG2000Multicomponent;
199 return true;
187200 }
188201
189202
193206 **/
194207 if (type == "image/dicom+jpeg" && transferSyntax == "1.2.840.10008.1.2.4.50")
195208 {
196 return gdcm::TransferSyntax::JPEGBaselineProcess1;
209 syntax = Orthanc::DicomTransferSyntax_JPEGProcess1;
210 return true;
197211 }
198212 else if (type == "image/dicom+jpeg" && transferSyntax == "1.2.840.10008.1.2.4.51")
199213 {
200 return gdcm::TransferSyntax::JPEGExtendedProcess2_4;
214 syntax = Orthanc::DicomTransferSyntax_JPEGProcess2_4;
215 return true;
201216 }
202217 else if (type == "image/dicom+jpeg" && transferSyntax == "1.2.840.10008.1.2.4.57")
203218 {
204 return gdcm::TransferSyntax::JPEGLosslessProcess14;
219 syntax = Orthanc::DicomTransferSyntax_JPEGProcess14;
220 return true;
205221 }
206222 else if (type == "image/dicom+jpeg" && (transferSyntax.empty() ||
207223 transferSyntax == "1.2.840.10008.1.2.4.70"))
208224 {
209 return gdcm::TransferSyntax::JPEGLosslessProcess14_1;
225 syntax = Orthanc::DicomTransferSyntax_JPEGProcess14SV1;
226 return true;
210227 }
211228 else if (type == "image/dicom+rle" && (transferSyntax.empty() ||
212229 transferSyntax == "1.2.840.10008.1.2.5"))
213230 {
214 return gdcm::TransferSyntax::RLELossless;
231 syntax = Orthanc::DicomTransferSyntax_RLELossless;
232 return true;
215233 }
216234 else if (type == "image/dicom+jpeg-ls" && (transferSyntax.empty() ||
217235 transferSyntax == "1.2.840.10008.1.2.4.80"))
218236 {
219 return gdcm::TransferSyntax::JPEGLSLossless;
237 syntax = Orthanc::DicomTransferSyntax_JPEGLSLossless;
238 return true;
220239 }
221240 else if (type == "image/dicom+jpeg-ls" && transferSyntax == "1.2.840.10008.1.2.4.81")
222241 {
223 return gdcm::TransferSyntax::JPEGLSNearLossless;
242 syntax = Orthanc::DicomTransferSyntax_JPEGLSLossy;
243 return true;
224244 }
225245 else if (type == "image/dicom+jp2" && (transferSyntax.empty() ||
226246 transferSyntax == "1.2.840.10008.1.2.4.90"))
227247 {
228 return gdcm::TransferSyntax::JPEG2000Lossless;
248 syntax = Orthanc::DicomTransferSyntax_JPEG2000LosslessOnly;
249 return true;
229250 }
230251 else if (type == "image/dicom+jp2" && transferSyntax == "1.2.840.10008.1.2.4.91")
231252 {
232 return gdcm::TransferSyntax::JPEG2000;
253 syntax = Orthanc::DicomTransferSyntax_JPEG2000;
254 return true;
233255 }
234256 else if (type == "image/dicom+jpx" && (transferSyntax.empty() ||
235257 transferSyntax == "1.2.840.10008.1.2.4.92"))
236258 {
237 return gdcm::TransferSyntax::JPEG2000Part2Lossless;
259 syntax = Orthanc::DicomTransferSyntax_JPEG2000MulticomponentLosslessOnly;
260 return true;
238261 }
239262 else if (type == "image/dicom+jpx" && transferSyntax == "1.2.840.10008.1.2.4.93")
240263 {
241 return gdcm::TransferSyntax::JPEG2000Part2;
264 syntax = Orthanc::DicomTransferSyntax_JPEG2000Multicomponent;
265 return true;
242266 }
243267
244268 throw Orthanc::OrthancException(
250274 }
251275
252276 // By default, DICOMweb expectes Little Endian uncompressed pixel data
253 return gdcm::TransferSyntax::ExplicitVRLittleEndian;
277 syntax = Orthanc::DicomTransferSyntax_LittleEndianExplicit;
278 return true;
254279 }
255280
256281
286311 }
287312
288313
289
290 static const char* GetMimeType(const gdcm::TransferSyntax& syntax)
314 static const char* GetMimeType(const Orthanc::DicomTransferSyntax& syntax)
291315 {
292316 // http://dicom.nema.org/medical/dicom/current/output/html/part18.html#table_6.1.1.8-3b
293317 // http://dicom.nema.org/MEDICAL/dicom/2019a/output/chtml/part18/chapter_6.html#table_6.1.1.8-3b
294318
295319 switch (syntax)
296320 {
297 case gdcm::TransferSyntax::ImplicitVRLittleEndian:
321 case Orthanc::DicomTransferSyntax_LittleEndianImplicit:
298322 // The "transfer-syntax" info was added in version 1.1 of the plugin
299323 return "application/octet-stream; transfer-syntax=1.2.840.10008.1.2";
300324
301 case gdcm::TransferSyntax::ExplicitVRLittleEndian:
325 case Orthanc::DicomTransferSyntax_LittleEndianExplicit:
302326 return "application/octet-stream; transfer-syntax=1.2.840.10008.1.2.1";
303327
304 case gdcm::TransferSyntax::JPEGBaselineProcess1:
328 case Orthanc::DicomTransferSyntax_JPEGProcess1:
305329 return "image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.50";
306330
307 case gdcm::TransferSyntax::JPEGExtendedProcess2_4:
331 case Orthanc::DicomTransferSyntax_JPEGProcess2_4:
308332 return "image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.51";
309333
310 case gdcm::TransferSyntax::JPEGLosslessProcess14:
334 case Orthanc::DicomTransferSyntax_JPEGProcess14:
311335 return "image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.57";
312336
313 case gdcm::TransferSyntax::JPEGLosslessProcess14_1:
314 return "image/jpeg; transferSyntax=1.2.840.10008.1.2.4.70";
337 case Orthanc::DicomTransferSyntax_JPEGProcess14SV1:
338 return "image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.70";
315339
316 case gdcm::TransferSyntax::RLELossless:
317 return "image/x-dicom-rle; transferSyntax=1.2.840.10008.1.2.5";
318
319 case gdcm::TransferSyntax::JPEGLSLossless:
320 return "image/x-jls; transferSyntax=1.2.840.10008.1.2.4.80";
321
322 case gdcm::TransferSyntax::JPEGLSNearLossless:
340 case Orthanc::DicomTransferSyntax_RLELossless:
341 return "image/x-dicom-rle; transfer-syntax=1.2.840.10008.1.2.5";
342
343 case Orthanc::DicomTransferSyntax_JPEGLSLossless:
344 return "image/x-jls; transfer-syntax=1.2.840.10008.1.2.4.80";
345
346 case Orthanc::DicomTransferSyntax_JPEGLSLossy:
323347 return "image/x-jls; transfer-syntax=1.2.840.10008.1.2.4.81";
324348
325 case gdcm::TransferSyntax::JPEG2000Lossless:
326 return "image/jp2; transferSyntax=1.2.840.10008.1.2.4.90";
327
328 case gdcm::TransferSyntax::JPEG2000:
349 case Orthanc::DicomTransferSyntax_JPEG2000LosslessOnly:
350 return "image/jp2; transfer-syntax=1.2.840.10008.1.2.4.90";
351
352 case Orthanc::DicomTransferSyntax_JPEG2000:
329353 return "image/jp2; transfer-syntax=1.2.840.10008.1.2.4.91";
330354
331 case gdcm::TransferSyntax::JPEG2000Part2Lossless:
332 return "image/jpx; transferSyntax=1.2.840.10008.1.2.4.92";
333
334 case gdcm::TransferSyntax::JPEG2000Part2:
355 case Orthanc::DicomTransferSyntax_JPEG2000MulticomponentLosslessOnly:
356 return "image/jpx; transfer-syntax=1.2.840.10008.1.2.4.92";
357
358 case Orthanc::DicomTransferSyntax_JPEG2000Multicomponent:
335359 return "image/jpx; transfer-syntax=1.2.840.10008.1.2.4.93";
336360
337361 default:
340364 }
341365
342366
343
344 static void ConvertYbrToRgb(uint8_t rgb[3],
345 const uint8_t ybr[3])
346 {
347 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.3.html#sect_C.7.6.3.1.2
348 // https://en.wikipedia.org/wiki/YCbCr#JPEG_conversion
367 static void AnswerFrames(OrthancPluginRestOutput* output,
368 const OrthancPluginHttpRequest* request,
369 const OrthancPlugins::DicomInstance& instance,
370 const std::string& studyInstanceUid,
371 const std::string& seriesInstanceUid,
372 const std::string& sopInstanceUid,
373 const std::list<unsigned int>& frames,
374 Orthanc::DicomTransferSyntax outputSyntax)
375 {
376 if (OrthancPluginStartMultipartAnswer(
377 OrthancPlugins::GetGlobalContext(),
378 output, "related", GetMimeType(outputSyntax)) != OrthancPluginErrorCode_Success)
379 {
380 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin,
381 "Cannot start a multipart answer");
382 }
383
384 const std::string base = OrthancPlugins::Configuration::GetBaseUrl(request);
349385
350 const float Y = ybr[0];
351 const float Cb = ybr[1];
352 const float Cr = ybr[2];
353
354 const float result[3] = {
355 Y + 1.402f * (Cr - 128.0f),
356 Y - 0.344136f * (Cb - 128.0f) - 0.714136f * (Cr - 128.0f),
357 Y + 1.772f * (Cb - 128.0f)
358 };
359
360 for (uint8_t i = 0; i < 3 ; i++)
361 {
362 if (result[i] < 0)
363 {
364 rgb[i] = 0;
365 }
366 else if (result[i] > 255)
367 {
368 rgb[i] = 255;
369 }
370 else
371 {
372 rgb[i] = static_cast<uint8_t>(result[i]);
373 }
374 }
375 }
376
377
378 static void AnswerSingleFrame(OrthancPluginRestOutput* output,
379 const OrthancPluginHttpRequest* request,
380 const OrthancPlugins::GdcmParsedDicomFile& dicom,
381 const char* frame,
382 size_t size,
383 unsigned int frameIndex,
384 bool convertYbr)
385 {
386 /**
387 * Fix the photometric interpretation, typically needed for some
388 * multiframe US images (as the one in issue 164). Also check out
389 * the "Plugins/Samples/GdcmDecoder/GdcmImageDecoder.cpp" file in
390 * the source distribution of Orthanc, and Osimis issue WVB-319
391 * ("Some images are not loading in US_MF").
392 **/
393
394 std::vector<uint8_t> copied; // Don't move this variable inside the
395 // "if", as "frame" might point to it
396
397 if (convertYbr &&
398 size > 0)
399 {
400 copied.resize(size);
401 memcpy(&copied[0], frame, size);
402
403 uint8_t *p = &copied[0];
404 for (size_t i = 0; i < size / 3; i++)
405 {
406 uint8_t ybr[3], rgb[3];
407 ybr[0] = p[0];
408 ybr[1] = p[1];
409 ybr[2] = p[2];
410
411 ConvertYbrToRgb(rgb, ybr);
412 p[0] = rgb[0];
413 p[1] = rgb[1];
414 p[2] = rgb[2];
415
416 p += 3;
417 }
418
419 frame = reinterpret_cast<const char*>(&copied[0]);
420 }
421
422
423 OrthancPluginErrorCode error;
386 for (std::list<unsigned int>::const_iterator
387 frame = frames.begin(); frame != frames.end(); ++frame)
388 {
389 std::string content;
390 instance.GetRawFrame(content, *frame);
391
392 const char* data = content.empty() ? NULL : content.c_str();
393 size_t size = content.size();
394
395 OrthancPluginErrorCode error;
424396
425397 #if HAS_SEND_MULTIPART_ITEM_2 == 1
426 std::string location = dicom.GetWadoUrl(request) + "frames/" + boost::lexical_cast<std::string>(frameIndex + 1);
427 const char *keys[] = { "Content-Location" };
428 const char *values[] = { location.c_str() };
429 error = OrthancPluginSendMultipartItem2(OrthancPlugins::GetGlobalContext(), output, frame, size, 1, keys, values);
398 std::string location = (
399 OrthancPlugins::Configuration::GetWadoUrl(base, studyInstanceUid, seriesInstanceUid, sopInstanceUid) +
400 "frames/" + boost::lexical_cast<std::string>(*frame + 1));
401 const char *keys[] = { "Content-Location" };
402 const char *values[] = { location.c_str() };
403 error = OrthancPluginSendMultipartItem2(OrthancPlugins::GetGlobalContext(), output, data, size, 1, keys, values);
430404 #else
431 error = OrthancPluginSendMultipartItem(OrthancPlugins::GetGlobalContext(), output, frame, size);
405 error = OrthancPluginSendMultipartItem(OrthancPlugins::GetGlobalContext(), output, data, size);
432406 #endif
433407
434 if (error != OrthancPluginErrorCode_Success)
435 {
436 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
437 }
438 }
439
440
441 static bool AnswerFrames(OrthancPluginRestOutput* output,
442 const OrthancPluginHttpRequest* request,
443 const OrthancPlugins::GdcmParsedDicomFile& dicom,
444 const gdcm::TransferSyntax& syntax,
445 std::list<unsigned int>& frames)
446 {
447 static const gdcm::Tag DICOM_TAG_BITS_ALLOCATED(0x0028, 0x0100);
448 static const gdcm::Tag DICOM_TAG_COLUMNS(0x0028, 0x0011);
449 static const gdcm::Tag DICOM_TAG_PIXEL_DATA(0x7fe0, 0x0010);
450 static const gdcm::Tag DICOM_TAG_ROWS(0x0028, 0x0010);
451 static const gdcm::Tag DICOM_TAG_SAMPLES_PER_PIXEL(0x0028, 0x0002);
452 static const gdcm::Tag DICOM_TAG_PHOTOMETRIC_INTERPRETATION(0x0028, 0x0004);
453
454 if (!dicom.GetDataSet().FindDataElement(DICOM_TAG_PIXEL_DATA))
455 {
456 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
457 }
458
459 const gdcm::DataElement& pixelData = dicom.GetDataSet().GetDataElement(DICOM_TAG_PIXEL_DATA);
460 const gdcm::SequenceOfFragments* fragments = pixelData.GetSequenceOfFragments();
461
462 if (OrthancPluginStartMultipartAnswer(OrthancPlugins::GetGlobalContext(),
463 output, "related", GetMimeType(syntax)) != OrthancPluginErrorCode_Success)
464 {
465 return false;
466 }
467
468 int samplesPerPixel;
469
470 if (!dicom.GetIntegerTag(samplesPerPixel, DICOM_TAG_SAMPLES_PER_PIXEL))
471 {
472 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
473 }
474
475 bool convertYbr = false;
476
477 {
478 std::string photometric;
479 if (samplesPerPixel == 3 &&
480 dicom.GetStringTag(photometric, DICOM_TAG_PHOTOMETRIC_INTERPRETATION, true) &&
481 photometric == "YBR_FULL")
482 {
483 convertYbr = true;
484 }
485 }
486
487 if (fragments == NULL)
488 {
489 // Single-fragment image
490
491 if (pixelData.GetByteValue() == NULL)
492 {
493 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
494 "Image was not properly decoded");
495 }
496
497 int width, height, bits;
498
499 if (!dicom.GetIntegerTag(height, DICOM_TAG_ROWS) ||
500 !dicom.GetIntegerTag(width, DICOM_TAG_COLUMNS) ||
501 !dicom.GetIntegerTag(bits, DICOM_TAG_BITS_ALLOCATED))
502 {
503 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
504 }
505
506 size_t frameSize = height * width * bits * samplesPerPixel / 8;
507
508 if (frameSize == 0)
509 {
510 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
511 }
512
513 /**
514 * The number of bytes in "pixelData" might not be divisible by
515 * "frameSize", because "pixelData" might contain one padding byte
516 * to have an even number of bytes.
517 * https://bitbucket.org/sjodogne/orthanc/issues/164/
518 **/
519
520 if (pixelData.GetByteValue()->GetLength() % frameSize != 0 &&
521 (/* allow one padding byte to be present */
522 pixelData.GetByteValue()->GetLength() % 2 == 0 &&
523 pixelData.GetByteValue()->GetLength() % frameSize != 1))
524 {
525 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
526 }
527
528 size_t framesCount = pixelData.GetByteValue()->GetLength() / frameSize;
529
530 if (frames.empty())
531 {
532 // If no frame is provided, return all the frames (this is an extension)
533 for (size_t i = 0; i < framesCount; i++)
534 {
535 frames.push_back(i);
536 }
537 }
538
539 const char* buffer = pixelData.GetByteValue()->GetPointer();
540 assert(sizeof(char) == 1);
541
542 for (std::list<unsigned int>::const_iterator
543 frame = frames.begin(); frame != frames.end(); ++frame)
544 {
545 if (*frame >= framesCount)
546 {
547 throw Orthanc::OrthancException(
548 Orthanc::ErrorCode_ParameterOutOfRange,
549 "Trying to access frame number " + boost::lexical_cast<std::string>(*frame + 1) +
550 " of an image with " + boost::lexical_cast<std::string>(framesCount) + " frames");
551 }
552 else
553 {
554 const char* p = buffer + (*frame) * frameSize;
555 AnswerSingleFrame(output, request, dicom, p, frameSize, *frame, convertYbr);
556 }
557 }
558 }
559 else
560 {
561 // Multi-fragment image, we assume that each fragment corresponds to one frame
562
563 if (frames.empty())
564 {
565 // If no frame is provided, return all the frames (this is an extension)
566 for (size_t i = 0; i < fragments->GetNumberOfFragments(); i++)
567 {
568 frames.push_back(i);
569 }
570 }
571
572 for (std::list<unsigned int>::const_iterator
573 frame = frames.begin(); frame != frames.end(); ++frame)
574 {
575 if (*frame >= fragments->GetNumberOfFragments())
576 {
577 // TODO A frame is not a fragment, looks like a bug
578 throw Orthanc::OrthancException(
579 Orthanc::ErrorCode_ParameterOutOfRange,
580 "Trying to access frame number " +
581 boost::lexical_cast<std::string>(*frame + 1) +
582 " of an image with " +
583 boost::lexical_cast<std::string>(fragments->GetNumberOfFragments()) +
584 " frames");
585 }
586 else
587 {
588 AnswerSingleFrame(output, request, dicom,
589 fragments->GetFragment(*frame).GetByteValue()->GetPointer(),
590 fragments->GetFragment(*frame).GetByteValue()->GetLength(),
591 *frame, convertYbr);
592 }
593 }
594 }
595
596 return true;
597 }
598
599
600
601 void RetrieveFrames(OrthancPluginRestOutput* output,
602 const char* url,
603 const OrthancPluginHttpRequest* request)
604 {
605 std::list<unsigned int> frames;
606 ParseFrameList(frames, request);
607
608 Json::Value header;
408 if (error != OrthancPluginErrorCode_Success)
409 {
410 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
411 }
412 }
413 }
414
415
416 static void RetrieveFrames(OrthancPluginRestOutput* output,
417 const OrthancPluginHttpRequest* request,
418 bool allFrames,
419 std::list<unsigned int>& frames)
420 {
609421 std::string orthancId, studyInstanceUid, seriesInstanceUid, sopInstanceUid;
610422 OrthancPlugins::MemoryBuffer content;
611423 if (LocateInstance(output, orthancId, studyInstanceUid, seriesInstanceUid, sopInstanceUid, request) &&
612 content.RestApiGet("/instances/" + orthancId + "/file", false) &&
613 OrthancPlugins::RestApiGet(header, "/instances/" + orthancId + "/header?simplify", false))
614 {
424 content.RestApiGet("/instances/" + orthancId + "/file", false))
425 {
426 if (allFrames)
427 {
428 OrthancPlugins::LogInfo("DICOMweb RetrieveFrames on " + orthancId + ", all frames");
429 }
430 else
615431 {
616432 std::string s = "DICOMweb RetrieveFrames on " + orthancId + ", frames: ";
617433 for (std::list<unsigned int>::const_iterator
623439 OrthancPlugins::LogInfo(s);
624440 }
625441
626 std::auto_ptr<OrthancPlugins::GdcmParsedDicomFile> source;
627
628 gdcm::TransferSyntax sourceSyntax;
629
630 if (header.type() == Json::objectValue &&
631 header.isMember("TransferSyntaxUID"))
632 {
633 sourceSyntax = gdcm::TransferSyntax::GetTSType(header["TransferSyntaxUID"].asCString());
442 Orthanc::DicomTransferSyntax targetSyntax;
443
444 std::unique_ptr<OrthancPlugins::DicomInstance> instance;
445 if (ParseTransferSyntax(targetSyntax, request))
446 {
447 OrthancPlugins::LogInfo("DICOMweb RetrieveFrames: Transcoding instance " + orthancId +
448 " to transfer syntax " + Orthanc::GetTransferSyntaxUid(targetSyntax));
449
450 instance.reset(OrthancPlugins::DicomInstance::Transcode(
451 content.GetData(), content.GetSize(), GetTransferSyntaxUid(targetSyntax)));
634452 }
635453 else
636454 {
637 source.reset(new OrthancPlugins::GdcmParsedDicomFile(content));
638 sourceSyntax = source->GetFile().GetHeader().GetDataSetTransferSyntax();
639 }
640
641 gdcm::TransferSyntax targetSyntax(ParseTransferSyntax(request, sourceSyntax));
642
643 if (sourceSyntax == targetSyntax)
644 {
645 // No need to change the transfer syntax
646
647 if (source.get() == NULL)
648 {
649 source.reset(new OrthancPlugins::GdcmParsedDicomFile(content));
650 }
651
652 AnswerFrames(output, request, *source, targetSyntax, frames);
653 }
654 else
655 {
656 // Need to convert the transfer syntax
657
658 {
659 OrthancPlugins::LogInfo("DICOMweb RetrieveFrames: Transcoding instance " + orthancId +
660 " from transfer syntax " + std::string(sourceSyntax.GetString()) +
661 " to " + std::string(targetSyntax.GetString()));
662 }
663
664 gdcm::ImageChangeTransferSyntax change;
665 change.SetTransferSyntax(targetSyntax);
666
667 // TODO Avoid this unnecessary memcpy by defining a stream over the MemoryBuffer
668 std::string dicom(content.GetData(), content.GetData() + content.GetSize());
669 std::stringstream stream(dicom);
670
671 gdcm::ImageReader reader;
672 reader.SetStream(stream);
673 if (!reader.Read())
674 {
675 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
676 "Cannot decode the image");
677 }
678
679 change.SetInput(reader.GetImage());
680 if (!change.Change())
681 {
682 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
683 "Cannot change the transfer syntax of the image");
684 }
685
686 gdcm::ImageWriter writer;
687 writer.SetImage(change.GetOutput());
688 writer.SetFile(reader.GetFile());
689
690 std::stringstream ss;
691 writer.SetStream(ss);
692 if (!writer.Write())
693 {
694 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory);
695 }
696
697 OrthancPlugins::GdcmParsedDicomFile transcoded(ss.str());
698 AnswerFrames(output, request, transcoded, targetSyntax, frames);
699 }
455 instance.reset(new OrthancPlugins::DicomInstance(content.GetData(), content.GetSize()));
456 }
457
458 if (instance.get() == NULL)
459 {
460 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
461 }
462
463 if (allFrames)
464 {
465 frames.clear();
466 for (unsigned int i = 0; i < instance->GetFramesCount(); i++)
467 {
468 frames.push_back(i + 1); // Frames are numbered starting from 1
469 }
470 }
471
472 AnswerFrames(output, request, *instance, studyInstanceUid, seriesInstanceUid,
473 sopInstanceUid, frames, targetSyntax);
700474 }
701475 }
476
477
478 void RetrieveAllFrames(OrthancPluginRestOutput* output,
479 const char* url,
480 const OrthancPluginHttpRequest* request)
481 {
482 std::list<unsigned int> frames;
483 RetrieveFrames(output, request, true, frames);
484 }
485
486
487 void RetrieveSelectedFrames(OrthancPluginRestOutput* output,
488 const char* url,
489 const OrthancPluginHttpRequest* request)
490 {
491 std::list<unsigned int> frames;
492 ParseFrameList(frames, request);
493 RetrieveFrames(output, request, false, frames);
494 }
+0
-144
Resources/CMake/GdcmConfiguration.cmake less more
0 # Orthanc - A Lightweight, RESTful DICOM Store
1 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2 # Department, University Hospital of Liege, Belgium
3 # Copyright (C) 2017-2020 Osimis S.A., Belgium
4 #
5 # This program is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Affero General Public License
7 # as published by the Free Software Foundation, either version 3 of
8 # the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19 if (STATIC_BUILD OR NOT USE_SYSTEM_GDCM)
20 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
21 ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
22 ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
23 # If using gcc, build GDCM with the "-fPIC" argument to allow its
24 # embedding into the shared library containing the Orthanc plugin
25 set(AdditionalFlags "-fPIC")
26 elseif (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
27 # This definition is necessary to compile
28 # "Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx"
29 set(AdditionalFlags "-Doff64_t=off_t")
30 endif()
31
32 set(Flags
33 "-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} ${AdditionalFlags}"
34 "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} ${AdditionalFlags}"
35 -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
36 -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
37 -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
38 -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
39 -DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
40 -DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL}
41 -DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
42 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
43 )
44
45 if (CMAKE_TOOLCHAIN_FILE)
46 # Take absolute path to the toolchain
47 get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR})
48 list(APPEND Flags -DCMAKE_TOOLCHAIN_FILE=${TMP})
49 endif()
50
51 # Don't build manpages (since gdcm 2.8.4)
52 list(APPEND Flags -DGDCM_BUILD_DOCBOOK_MANPAGES=OFF)
53
54 if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
55 # Trick to disable the compilation of socket++ by gdcm, which is
56 # incompatible with LSB, but fortunately only required for DICOM
57 # Networking
58 list(APPEND Flags -DGDCM_USE_SYSTEM_SOCKETXX=ON)
59
60 # Detect the number of CPU cores to run "make" with as much
61 # parallelism as possible
62 include(ProcessorCount)
63 ProcessorCount(N)
64 if (NOT N EQUAL 0)
65 set(MAKE_PARALLEL -j${N})
66 endif()
67
68 # For Linux Standard Base, avoid building incompatible target gdcmMEXD (*)
69 set(BUILD_COMMAND BUILD_COMMAND
70 ${CMAKE_MAKE_PROGRAM} ${MAKE_PARALLEL}
71 gdcmMSFF gdcmcharls gdcmDICT gdcmDSED gdcmIOD gdcmjpeg8
72 gdcmjpeg12 gdcmjpeg16 gdcmopenjp2 gdcmzlib gdcmCommon gdcmexpat gdcmuuid)
73 endif()
74
75 include(ExternalProject)
76 externalproject_add(GDCM
77 URL "http://orthanc.osimis.io/ThirdPartyDownloads/gdcm-3.0.4.tar.gz"
78 URL_MD5 "f12dbded708356d5fa0b5ed37ccdb66e"
79 TIMEOUT 60
80 CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} ${Flags}
81 ${BUILD_COMMAND} # Customize "make", only for Linux Standard Base (*)
82 INSTALL_COMMAND "" # Skip the install step
83 )
84
85 if(MSVC)
86 set(Suffix ".lib")
87 set(Prefix "")
88 else()
89 set(Suffix ".a")
90 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
91 endif()
92
93 set(GDCM_LIBRARIES
94 # WARNING: The order of the libraries below *is* important!
95 ${Prefix}gdcmMSFF${Suffix}
96 ${Prefix}gdcmcharls${Suffix}
97 ${Prefix}gdcmDICT${Suffix}
98 ${Prefix}gdcmDSED${Suffix}
99 ${Prefix}gdcmIOD${Suffix}
100 ${Prefix}gdcmjpeg8${Suffix}
101 ${Prefix}gdcmjpeg12${Suffix}
102 ${Prefix}gdcmjpeg16${Suffix}
103 ${Prefix}gdcmopenjp2${Suffix}
104 ${Prefix}gdcmzlib${Suffix}
105 ${Prefix}gdcmCommon${Suffix}
106 ${Prefix}gdcmexpat${Suffix}
107
108 #${Prefix}socketxx${Suffix}
109 #${Prefix}gdcmMEXD${Suffix} # DICOM Networking, unneeded by Orthanc plugins
110 #${Prefix}gdcmgetopt${Suffix}
111 )
112
113 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
114 list(APPEND GDCM_LIBRARIES
115 rpcrt4 # For UUID stuff
116 )
117 else()
118 list(APPEND GDCM_LIBRARIES
119 ${Prefix}gdcmuuid${Suffix}
120 )
121 endif()
122
123 ExternalProject_Get_Property(GDCM binary_dir)
124 include_directories(${binary_dir}/Source/Common)
125 link_directories(${binary_dir}/bin)
126
127 ExternalProject_Get_Property(GDCM source_dir)
128 include_directories(
129 ${source_dir}/Source/Common
130 ${source_dir}/Source/DataDictionary
131 ${source_dir}/Source/MediaStorageAndFileFormat
132 ${source_dir}/Source/DataStructureAndEncodingDefinition
133 )
134
135 else()
136 find_package(GDCM REQUIRED)
137 if (GDCM_FOUND)
138 include(${GDCM_USE_FILE})
139 set(GDCM_LIBRARIES gdcmCommon gdcmMSFF)
140 else(GDCM_FOUND)
141 message(FATAL_ERROR "Cannot find GDCM, did you set GDCM_DIR?")
142 endif(GDCM_FOUND)
143 endif()
111111 set(ORTHANC_FRAMEWORK_MD5 "e1b76f01116d9b5d4ac8cc39980560e3")
112112 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.8")
113113 set(ORTHANC_FRAMEWORK_MD5 "82323e8c49a667f658a3639ea4dbc336")
114 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.6.0")
115 set(ORTHANC_FRAMEWORK_MD5 "eab428d6e53f61e847fa360bb17ebe25")
116 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.6.1")
117 set(ORTHANC_FRAMEWORK_MD5 "3971f5de96ba71dc9d3f3690afeaa7c0")
118 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.7.0")
119 set(ORTHANC_FRAMEWORK_MD5 "ce5f689e852b01d3672bd3d2f952a5ef")
114120
115121 # Below this point are development snapshots that were used to
116122 # release some plugin, before an official release of the Orthanc
213219 else()
214220 message("Forking the Orthanc source repository using Mercurial")
215221 execute_process(
216 COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://bitbucket.org/sjodogne/orthanc"
222 COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://hg.orthanc-server.com/orthanc/"
217223 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
218224 RESULT_VARIABLE Failure
219225 )
0 # LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON -DUSE_LEGACY_LIBICU=ON -DBOOST_LOCALE_BACKEND=icu
0 #
1 # Full build, as used on the BuildBot CIS:
2 #
3 # $ LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON -DUSE_LEGACY_LIBICU=ON -DBOOST_LOCALE_BACKEND=icu -DENABLE_PKCS11=ON -G Ninja
4 #
5 # Or, more lightweight version (without libp11 and ICU):
6 #
7 # $ LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON -G Ninja
8 #
19
210 INCLUDE(CMakeForceCompiler)
311
4 SET(LSB_PATH $ENV{LSB_PATH})
5 SET(LSB_CC $ENV{LSB_CC})
6 SET(LSB_CXX $ENV{LSB_CXX})
7 SET(LSB_TARGET_VERSION "4.0")
12 SET(LSB_PATH $ENV{LSB_PATH} CACHE STRING "")
13 SET(LSB_CC $ENV{LSB_CC} CACHE STRING "")
14 SET(LSB_CXX $ENV{LSB_CXX} CACHE STRING "")
15 SET(LSB_TARGET_VERSION "4.0" CACHE STRING "")
816
917 IF ("${LSB_PATH}" STREQUAL "")
1018 SET(LSB_PATH "/opt/lsb")
+0
-6802
Resources/Orthanc/Sdk-1.5.4/orthanc/OrthancCPlugin.h less more
0 /**
1 * \mainpage
2 *
3 * This C/C++ SDK allows external developers to create plugins that
4 * can be loaded into Orthanc to extend its functionality. Each
5 * Orthanc plugin must expose 4 public functions with the following
6 * signatures:
7 *
8 * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>:
9 * This function is invoked by Orthanc when it loads the plugin on startup.
10 * The plugin must:
11 * - Check its compatibility with the Orthanc version using
12 * ::OrthancPluginCheckVersion().
13 * - Store the context pointer so that it can use the plugin
14 * services of Orthanc.
15 * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback().
16 * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback().
17 * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback().
18 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea().
19 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2().
20 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback().
21 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback().
22 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback().
23 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback().
24 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2().
25 * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer().
26 * - Possibly register a callback to refresh its metrics using OrthancPluginRegisterRefreshMetricsCallback().
27 * -# <tt>void OrthancPluginFinalize()</tt>:
28 * This function is invoked by Orthanc during its shutdown. The plugin
29 * must free all its memory.
30 * -# <tt>const char* OrthancPluginGetName()</tt>:
31 * The plugin must return a short string to identify itself.
32 * -# <tt>const char* OrthancPluginGetVersion()</tt>:
33 * The plugin must return a string containing its version number.
34 *
35 * The name and the version of a plugin is only used to prevent it
36 * from being loaded twice. Note that, in C++, it is mandatory to
37 * declare these functions within an <tt>extern "C"</tt> section.
38 *
39 * To ensure multi-threading safety, the various REST callbacks are
40 * guaranteed to be executed in mutual exclusion since Orthanc
41 * 0.8.5. If this feature is undesired (notably when developing
42 * high-performance plugins handling simultaneous requests), use
43 * ::OrthancPluginRegisterRestCallbackNoLock().
44 **/
45
46
47
48 /**
49 * @defgroup Images Images and compression
50 * @brief Functions to deal with images and compressed buffers.
51 *
52 * @defgroup REST REST
53 * @brief Functions to answer REST requests in a callback.
54 *
55 * @defgroup Callbacks Callbacks
56 * @brief Functions to register and manage callbacks by the plugins.
57 *
58 * @defgroup DicomCallbacks DicomCallbacks
59 * @brief Functions to register and manage DICOM callbacks (worklists, C-Find, C-MOVE).
60 *
61 * @defgroup Orthanc Orthanc
62 * @brief Functions to access the content of the Orthanc server.
63 **/
64
65
66
67 /**
68 * @defgroup Toolbox Toolbox
69 * @brief Generic functions to help with the creation of plugins.
70 **/
71
72
73
74 /**
75 * Orthanc - A Lightweight, RESTful DICOM Store
76 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
77 * Department, University Hospital of Liege, Belgium
78 * Copyright (C) 2017-2020 Osimis S.A., Belgium
79 *
80 * This program is free software: you can redistribute it and/or
81 * modify it under the terms of the GNU General Public License as
82 * published by the Free Software Foundation, either version 3 of the
83 * License, or (at your option) any later version.
84 *
85 * In addition, as a special exception, the copyright holders of this
86 * program give permission to link the code of its release with the
87 * OpenSSL project's "OpenSSL" library (or with modified versions of it
88 * that use the same license as the "OpenSSL" library), and distribute
89 * the linked executables. You must obey the GNU General Public License
90 * in all respects for all of the code used other than "OpenSSL". If you
91 * modify file(s) with this exception, you may extend this exception to
92 * your version of the file(s), but you are not obligated to do so. If
93 * you do not wish to do so, delete this exception statement from your
94 * version. If you delete this exception statement from all source files
95 * in the program, then also delete it here.
96 *
97 * This program is distributed in the hope that it will be useful, but
98 * WITHOUT ANY WARRANTY; without even the implied warranty of
99 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
100 * General Public License for more details.
101 *
102 * You should have received a copy of the GNU General Public License
103 * along with this program. If not, see <http://www.gnu.org/licenses/>.
104 **/
105
106
107
108 #pragma once
109
110
111 #include <stdio.h>
112 #include <string.h>
113
114 #ifdef WIN32
115 #define ORTHANC_PLUGINS_API __declspec(dllexport)
116 #else
117 #define ORTHANC_PLUGINS_API
118 #endif
119
120 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1
121 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 5
122 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 4
123
124
125 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
126 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \
127 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \
128 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \
129 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \
130 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \
131 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision))))
132 #endif
133
134
135
136 /********************************************************************
137 ** Check that function inlining is properly supported. The use of
138 ** inlining is required, to avoid the duplication of object code
139 ** between two compilation modules that would use the Orthanc Plugin
140 ** API.
141 ********************************************************************/
142
143 /* If the auto-detection of the "inline" keyword below does not work
144 automatically and that your compiler is known to properly support
145 inlining, uncomment the following #define and adapt the definition
146 of "static inline". */
147
148 /* #define ORTHANC_PLUGIN_INLINE static inline */
149
150 #ifndef ORTHANC_PLUGIN_INLINE
151 # if __STDC_VERSION__ >= 199901L
152 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
153 # define ORTHANC_PLUGIN_INLINE static inline
154 # elif defined(__cplusplus)
155 /* This is C++ */
156 # define ORTHANC_PLUGIN_INLINE static inline
157 # elif defined(__GNUC__)
158 /* This is GCC running in C89 mode */
159 # define ORTHANC_PLUGIN_INLINE static __inline
160 # elif defined(_MSC_VER)
161 /* This is Visual Studio running in C89 mode */
162 # define ORTHANC_PLUGIN_INLINE static __inline
163 # else
164 # error Your compiler is not known to support the "inline" keyword
165 # endif
166 #endif
167
168
169
170 /********************************************************************
171 ** Inclusion of standard libraries.
172 ********************************************************************/
173
174 /**
175 * For Microsoft Visual Studio, a compatibility "stdint.h" can be
176 * downloaded at the following URL:
177 * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h
178 **/
179 #include <stdint.h>
180
181 #include <stdlib.h>
182
183
184
185 /********************************************************************
186 ** Definition of the Orthanc Plugin API.
187 ********************************************************************/
188
189 /** @{ */
190
191 #ifdef __cplusplus
192 extern "C"
193 {
194 #endif
195
196 /**
197 * The various error codes that can be returned by the Orthanc core.
198 **/
199 typedef enum
200 {
201 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */,
202 OrthancPluginErrorCode_Success = 0 /*!< Success */,
203 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */,
204 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */,
205 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */,
206 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */,
207 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */,
208 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */,
209 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */,
210 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */,
211 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */,
212 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */,
213 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */,
214 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */,
215 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */,
216 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */,
217 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */,
218 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */,
219 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */,
220 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */,
221 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */,
222 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */,
223 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */,
224 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */,
225 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */,
226 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */,
227 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */,
228 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */,
229 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */,
230 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */,
231 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */,
232 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */,
233 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */,
234 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */,
235 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */,
236 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */,
237 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */,
238 OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */,
239 OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */,
240 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */,
241 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */,
242 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */,
243 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */,
244 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */,
245 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */,
246 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */,
247 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */,
248 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */,
249 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */,
250 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */,
251 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */,
252 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */,
253 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */,
254 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */,
255 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */,
256 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */,
257 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */,
258 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */,
259 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */,
260 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */,
261 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */,
262 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */,
263 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */,
264 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */,
265 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */,
266 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */,
267 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */,
268 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */,
269 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */,
270 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */,
271 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */,
272 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */,
273 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */,
274 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */,
275 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */,
276 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */,
277 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */,
278 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */,
279 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */,
280 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */,
281 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */,
282 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */,
283 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */,
284 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */,
285 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */,
286 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */,
287 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */,
288 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */,
289 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */,
290 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */,
291 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */,
292 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */,
293 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */,
294 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */,
295 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */,
296 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */,
297 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */,
298 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */,
299
300 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff
301 } OrthancPluginErrorCode;
302
303
304 /**
305 * Forward declaration of one of the mandatory functions for Orthanc
306 * plugins.
307 **/
308 ORTHANC_PLUGINS_API const char* OrthancPluginGetName();
309
310
311 /**
312 * The various HTTP methods for a REST call.
313 **/
314 typedef enum
315 {
316 OrthancPluginHttpMethod_Get = 1, /*!< GET request */
317 OrthancPluginHttpMethod_Post = 2, /*!< POST request */
318 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
319 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */
320
321 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff
322 } OrthancPluginHttpMethod;
323
324
325 /**
326 * @brief The parameters of a REST request.
327 * @ingroup Callbacks
328 **/
329 typedef struct
330 {
331 /**
332 * @brief The HTTP method.
333 **/
334 OrthancPluginHttpMethod method;
335
336 /**
337 * @brief The number of groups of the regular expression.
338 **/
339 uint32_t groupsCount;
340
341 /**
342 * @brief The matched values for the groups of the regular expression.
343 **/
344 const char* const* groups;
345
346 /**
347 * @brief For a GET request, the number of GET parameters.
348 **/
349 uint32_t getCount;
350
351 /**
352 * @brief For a GET request, the keys of the GET parameters.
353 **/
354 const char* const* getKeys;
355
356 /**
357 * @brief For a GET request, the values of the GET parameters.
358 **/
359 const char* const* getValues;
360
361 /**
362 * @brief For a PUT or POST request, the content of the body.
363 **/
364 const char* body;
365
366 /**
367 * @brief For a PUT or POST request, the number of bytes of the body.
368 **/
369 uint32_t bodySize;
370
371
372 /* --------------------------------------------------
373 New in version 0.8.1
374 -------------------------------------------------- */
375
376 /**
377 * @brief The number of HTTP headers.
378 **/
379 uint32_t headersCount;
380
381 /**
382 * @brief The keys of the HTTP headers (always converted to low-case).
383 **/
384 const char* const* headersKeys;
385
386 /**
387 * @brief The values of the HTTP headers.
388 **/
389 const char* const* headersValues;
390
391 } OrthancPluginHttpRequest;
392
393
394 typedef enum
395 {
396 /* Generic services */
397 _OrthancPluginService_LogInfo = 1,
398 _OrthancPluginService_LogWarning = 2,
399 _OrthancPluginService_LogError = 3,
400 _OrthancPluginService_GetOrthancPath = 4,
401 _OrthancPluginService_GetOrthancDirectory = 5,
402 _OrthancPluginService_GetConfigurationPath = 6,
403 _OrthancPluginService_SetPluginProperty = 7,
404 _OrthancPluginService_GetGlobalProperty = 8,
405 _OrthancPluginService_SetGlobalProperty = 9,
406 _OrthancPluginService_GetCommandLineArgumentsCount = 10,
407 _OrthancPluginService_GetCommandLineArgument = 11,
408 _OrthancPluginService_GetExpectedDatabaseVersion = 12,
409 _OrthancPluginService_GetConfiguration = 13,
410 _OrthancPluginService_BufferCompression = 14,
411 _OrthancPluginService_ReadFile = 15,
412 _OrthancPluginService_WriteFile = 16,
413 _OrthancPluginService_GetErrorDescription = 17,
414 _OrthancPluginService_CallHttpClient = 18,
415 _OrthancPluginService_RegisterErrorCode = 19,
416 _OrthancPluginService_RegisterDictionaryTag = 20,
417 _OrthancPluginService_DicomBufferToJson = 21,
418 _OrthancPluginService_DicomInstanceToJson = 22,
419 _OrthancPluginService_CreateDicom = 23,
420 _OrthancPluginService_ComputeMd5 = 24,
421 _OrthancPluginService_ComputeSha1 = 25,
422 _OrthancPluginService_LookupDictionary = 26,
423 _OrthancPluginService_CallHttpClient2 = 27,
424 _OrthancPluginService_GenerateUuid = 28,
425 _OrthancPluginService_RegisterPrivateDictionaryTag = 29,
426 _OrthancPluginService_AutodetectMimeType = 30,
427 _OrthancPluginService_SetMetricsValue = 31,
428 _OrthancPluginService_EncodeDicomWebJson = 32,
429 _OrthancPluginService_EncodeDicomWebXml = 33,
430
431 /* Registration of callbacks */
432 _OrthancPluginService_RegisterRestCallback = 1000,
433 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
434 _OrthancPluginService_RegisterStorageArea = 1002,
435 _OrthancPluginService_RegisterOnChangeCallback = 1003,
436 _OrthancPluginService_RegisterRestCallbackNoLock = 1004,
437 _OrthancPluginService_RegisterWorklistCallback = 1005,
438 _OrthancPluginService_RegisterDecodeImageCallback = 1006,
439 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007,
440 _OrthancPluginService_RegisterFindCallback = 1008,
441 _OrthancPluginService_RegisterMoveCallback = 1009,
442 _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010,
443 _OrthancPluginService_RegisterRefreshMetricsCallback = 1011,
444
445 /* Sending answers to REST calls */
446 _OrthancPluginService_AnswerBuffer = 2000,
447 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */
448 _OrthancPluginService_Redirect = 2002,
449 _OrthancPluginService_SendHttpStatusCode = 2003,
450 _OrthancPluginService_SendUnauthorized = 2004,
451 _OrthancPluginService_SendMethodNotAllowed = 2005,
452 _OrthancPluginService_SetCookie = 2006,
453 _OrthancPluginService_SetHttpHeader = 2007,
454 _OrthancPluginService_StartMultipartAnswer = 2008,
455 _OrthancPluginService_SendMultipartItem = 2009,
456 _OrthancPluginService_SendHttpStatus = 2010,
457 _OrthancPluginService_CompressAndAnswerImage = 2011,
458 _OrthancPluginService_SendMultipartItem2 = 2012,
459 _OrthancPluginService_SetHttpErrorDetails = 2013,
460
461 /* Access to the Orthanc database and API */
462 _OrthancPluginService_GetDicomForInstance = 3000,
463 _OrthancPluginService_RestApiGet = 3001,
464 _OrthancPluginService_RestApiPost = 3002,
465 _OrthancPluginService_RestApiDelete = 3003,
466 _OrthancPluginService_RestApiPut = 3004,
467 _OrthancPluginService_LookupPatient = 3005,
468 _OrthancPluginService_LookupStudy = 3006,
469 _OrthancPluginService_LookupSeries = 3007,
470 _OrthancPluginService_LookupInstance = 3008,
471 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
472 _OrthancPluginService_RestApiGetAfterPlugins = 3010,
473 _OrthancPluginService_RestApiPostAfterPlugins = 3011,
474 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012,
475 _OrthancPluginService_RestApiPutAfterPlugins = 3013,
476 _OrthancPluginService_ReconstructMainDicomTags = 3014,
477 _OrthancPluginService_RestApiGet2 = 3015,
478
479 /* Access to DICOM instances */
480 _OrthancPluginService_GetInstanceRemoteAet = 4000,
481 _OrthancPluginService_GetInstanceSize = 4001,
482 _OrthancPluginService_GetInstanceData = 4002,
483 _OrthancPluginService_GetInstanceJson = 4003,
484 _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
485 _OrthancPluginService_HasInstanceMetadata = 4005,
486 _OrthancPluginService_GetInstanceMetadata = 4006,
487 _OrthancPluginService_GetInstanceOrigin = 4007,
488
489 /* Services for plugins implementing a database back-end */
490 _OrthancPluginService_RegisterDatabaseBackend = 5000,
491 _OrthancPluginService_DatabaseAnswer = 5001,
492 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002,
493 _OrthancPluginService_StorageAreaCreate = 5003,
494 _OrthancPluginService_StorageAreaRead = 5004,
495 _OrthancPluginService_StorageAreaRemove = 5005,
496
497 /* Primitives for handling images */
498 _OrthancPluginService_GetImagePixelFormat = 6000,
499 _OrthancPluginService_GetImageWidth = 6001,
500 _OrthancPluginService_GetImageHeight = 6002,
501 _OrthancPluginService_GetImagePitch = 6003,
502 _OrthancPluginService_GetImageBuffer = 6004,
503 _OrthancPluginService_UncompressImage = 6005,
504 _OrthancPluginService_FreeImage = 6006,
505 _OrthancPluginService_CompressImage = 6007,
506 _OrthancPluginService_ConvertPixelFormat = 6008,
507 _OrthancPluginService_GetFontsCount = 6009,
508 _OrthancPluginService_GetFontInfo = 6010,
509 _OrthancPluginService_DrawText = 6011,
510 _OrthancPluginService_CreateImage = 6012,
511 _OrthancPluginService_CreateImageAccessor = 6013,
512 _OrthancPluginService_DecodeDicomImage = 6014,
513
514 /* Primitives for handling C-Find, C-Move and worklists */
515 _OrthancPluginService_WorklistAddAnswer = 7000,
516 _OrthancPluginService_WorklistMarkIncomplete = 7001,
517 _OrthancPluginService_WorklistIsMatch = 7002,
518 _OrthancPluginService_WorklistGetDicomQuery = 7003,
519 _OrthancPluginService_FindAddAnswer = 7004,
520 _OrthancPluginService_FindMarkIncomplete = 7005,
521 _OrthancPluginService_GetFindQuerySize = 7006,
522 _OrthancPluginService_GetFindQueryTag = 7007,
523 _OrthancPluginService_GetFindQueryTagName = 7008,
524 _OrthancPluginService_GetFindQueryValue = 7009,
525 _OrthancPluginService_CreateFindMatcher = 7010,
526 _OrthancPluginService_FreeFindMatcher = 7011,
527 _OrthancPluginService_FindMatcherIsMatch = 7012,
528
529 /* Primitives for accessing Orthanc Peers (new in 1.4.2) */
530 _OrthancPluginService_GetPeers = 8000,
531 _OrthancPluginService_FreePeers = 8001,
532 _OrthancPluginService_GetPeersCount = 8003,
533 _OrthancPluginService_GetPeerName = 8004,
534 _OrthancPluginService_GetPeerUrl = 8005,
535 _OrthancPluginService_CallPeerApi = 8006,
536 _OrthancPluginService_GetPeerUserProperty = 8007,
537
538 /* Primitives for handling jobs (new in 1.4.2) */
539 _OrthancPluginService_CreateJob = 9000,
540 _OrthancPluginService_FreeJob = 9001,
541 _OrthancPluginService_SubmitJob = 9002,
542 _OrthancPluginService_RegisterJobsUnserializer = 9003,
543
544 _OrthancPluginService_INTERNAL = 0x7fffffff
545 } _OrthancPluginService;
546
547
548 typedef enum
549 {
550 _OrthancPluginProperty_Description = 1,
551 _OrthancPluginProperty_RootUri = 2,
552 _OrthancPluginProperty_OrthancExplorer = 3,
553
554 _OrthancPluginProperty_INTERNAL = 0x7fffffff
555 } _OrthancPluginProperty;
556
557
558
559 /**
560 * The memory layout of the pixels of an image.
561 * @ingroup Images
562 **/
563 typedef enum
564 {
565 /**
566 * @brief Graylevel 8bpp image.
567 *
568 * The image is graylevel. Each pixel is unsigned and stored in
569 * one byte.
570 **/
571 OrthancPluginPixelFormat_Grayscale8 = 1,
572
573 /**
574 * @brief Graylevel, unsigned 16bpp image.
575 *
576 * The image is graylevel. Each pixel is unsigned and stored in
577 * two bytes.
578 **/
579 OrthancPluginPixelFormat_Grayscale16 = 2,
580
581 /**
582 * @brief Graylevel, signed 16bpp image.
583 *
584 * The image is graylevel. Each pixel is signed and stored in two
585 * bytes.
586 **/
587 OrthancPluginPixelFormat_SignedGrayscale16 = 3,
588
589 /**
590 * @brief Color image in RGB24 format.
591 *
592 * This format describes a color image. The pixels are stored in 3
593 * consecutive bytes. The memory layout is RGB.
594 **/
595 OrthancPluginPixelFormat_RGB24 = 4,
596
597 /**
598 * @brief Color image in RGBA32 format.
599 *
600 * This format describes a color image. The pixels are stored in 4
601 * consecutive bytes. The memory layout is RGBA.
602 **/
603 OrthancPluginPixelFormat_RGBA32 = 5,
604
605 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */
606
607 /**
608 * @brief Color image in RGB48 format.
609 *
610 * This format describes a color image. The pixels are stored in 6
611 * consecutive bytes. The memory layout is RRGGBB.
612 **/
613 OrthancPluginPixelFormat_RGB48 = 7,
614
615 /**
616 * @brief Graylevel, unsigned 32bpp image.
617 *
618 * The image is graylevel. Each pixel is unsigned and stored in
619 * four bytes.
620 **/
621 OrthancPluginPixelFormat_Grayscale32 = 8,
622
623 /**
624 * @brief Graylevel, floating-point 32bpp image.
625 *
626 * The image is graylevel. Each pixel is floating-point and stored
627 * in four bytes.
628 **/
629 OrthancPluginPixelFormat_Float32 = 9,
630
631 /**
632 * @brief Color image in BGRA32 format.
633 *
634 * This format describes a color image. The pixels are stored in 4
635 * consecutive bytes. The memory layout is BGRA.
636 **/
637 OrthancPluginPixelFormat_BGRA32 = 10,
638
639 /**
640 * @brief Graylevel, unsigned 64bpp image.
641 *
642 * The image is graylevel. Each pixel is unsigned and stored in
643 * eight bytes.
644 **/
645 OrthancPluginPixelFormat_Grayscale64 = 11,
646
647 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff
648 } OrthancPluginPixelFormat;
649
650
651
652 /**
653 * The content types that are supported by Orthanc plugins.
654 **/
655 typedef enum
656 {
657 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
658 OrthancPluginContentType_Dicom = 1, /*!< DICOM */
659 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */
660
661 _OrthancPluginContentType_INTERNAL = 0x7fffffff
662 } OrthancPluginContentType;
663
664
665
666 /**
667 * The supported types of DICOM resources.
668 **/
669 typedef enum
670 {
671 OrthancPluginResourceType_Patient = 0, /*!< Patient */
672 OrthancPluginResourceType_Study = 1, /*!< Study */
673 OrthancPluginResourceType_Series = 2, /*!< Series */
674 OrthancPluginResourceType_Instance = 3, /*!< Instance */
675 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */
676
677 _OrthancPluginResourceType_INTERNAL = 0x7fffffff
678 } OrthancPluginResourceType;
679
680
681
682 /**
683 * The supported types of changes that can happen to DICOM resources.
684 * @ingroup Callbacks
685 **/
686 typedef enum
687 {
688 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */
689 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */
690 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */
691 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */
692 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */
693 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */
694 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */
695 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */
696 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */
697 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */
698 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */
699 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */
700 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */
701 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */
702 OrthancPluginChangeType_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */
703 OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */
704
705 _OrthancPluginChangeType_INTERNAL = 0x7fffffff
706 } OrthancPluginChangeType;
707
708
709 /**
710 * The compression algorithms that are supported by the Orthanc core.
711 * @ingroup Images
712 **/
713 typedef enum
714 {
715 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */
716 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */
717 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */
718 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */
719
720 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff
721 } OrthancPluginCompressionType;
722
723
724 /**
725 * The image formats that are supported by the Orthanc core.
726 * @ingroup Images
727 **/
728 typedef enum
729 {
730 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */
731 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */
732 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */
733
734 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff
735 } OrthancPluginImageFormat;
736
737
738 /**
739 * The value representations present in the DICOM standard (version 2013).
740 * @ingroup Toolbox
741 **/
742 typedef enum
743 {
744 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */
745 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */
746 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */
747 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */
748 OrthancPluginValueRepresentation_DA = 5, /*!< Date */
749 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */
750 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */
751 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */
752 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */
753 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */
754 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */
755 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */
756 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */
757 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */
758 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */
759 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */
760 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */
761 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */
762 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */
763 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */
764 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */
765 OrthancPluginValueRepresentation_TM = 22, /*!< Time */
766 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */
767 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */
768 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */
769 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */
770 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */
771
772 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff
773 } OrthancPluginValueRepresentation;
774
775
776 /**
777 * The possible output formats for a DICOM-to-JSON conversion.
778 * @ingroup Toolbox
779 * @see OrthancPluginDicomToJson()
780 **/
781 typedef enum
782 {
783 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */
784 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */
785 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */
786
787 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff
788 } OrthancPluginDicomToJsonFormat;
789
790
791 /**
792 * Flags to customize a DICOM-to-JSON conversion. By default, binary
793 * tags are formatted using Data URI scheme.
794 * @ingroup Toolbox
795 **/
796 typedef enum
797 {
798 OrthancPluginDicomToJsonFlags_None = 0,
799 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */
800 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */
801 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */
802 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */
803 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */
804 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */
805
806 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff
807 } OrthancPluginDicomToJsonFlags;
808
809
810 /**
811 * Flags to the creation of a DICOM file.
812 * @ingroup Toolbox
813 * @see OrthancPluginCreateDicom()
814 **/
815 typedef enum
816 {
817 OrthancPluginCreateDicomFlags_None = 0,
818 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */
819 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */
820
821 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff
822 } OrthancPluginCreateDicomFlags;
823
824
825 /**
826 * The constraints on the DICOM identifiers that must be supported
827 * by the database plugins.
828 * @deprecated Plugins using OrthancPluginConstraintType will be faster
829 **/
830 typedef enum
831 {
832 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */
833 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */
834 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */
835 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */
836
837 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff
838 } OrthancPluginIdentifierConstraint;
839
840
841 /**
842 * The constraints on the tags (main DICOM tags and identifier tags)
843 * that must be supported by the database plugins.
844 **/
845 typedef enum
846 {
847 OrthancPluginConstraintType_Equal = 1, /*!< Equal */
848 OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */
849 OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */
850 OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */
851 OrthancPluginConstraintType_List = 5, /*!< List of values */
852
853 _OrthancPluginConstraintType_INTERNAL = 0x7fffffff
854 } OrthancPluginConstraintType;
855
856
857 /**
858 * The origin of a DICOM instance that has been received by Orthanc.
859 **/
860 typedef enum
861 {
862 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */
863 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */
864 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */
865 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */
866 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */
867
868 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff
869 } OrthancPluginInstanceOrigin;
870
871
872 /**
873 * The possible status for one single step of a job.
874 **/
875 typedef enum
876 {
877 OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */
878 OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */
879 OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */
880 } OrthancPluginJobStepStatus;
881
882
883 /**
884 * Explains why the job should stop and release the resources it has
885 * allocated. This is especially important to disambiguate between
886 * the "paused" condition and the "final" conditions (success,
887 * failure, or canceled).
888 **/
889 typedef enum
890 {
891 OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */
892 OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */
893 OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */
894 OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */
895 } OrthancPluginJobStopReason;
896
897
898 /**
899 * The available types of metrics.
900 **/
901 typedef enum
902 {
903 OrthancPluginMetricsType_Default, /*!< Default metrics */
904
905 /**
906 * This metrics represents a time duration. Orthanc will keep the
907 * maximum value of the metrics over a sliding window of ten
908 * seconds, which is useful if the metrics is sampled frequently.
909 **/
910 OrthancPluginMetricsType_Timer
911 } OrthancPluginMetricsType;
912
913
914 /**
915 * The available modes to export a binary DICOM tag into a DICOMweb
916 * JSON or XML document.
917 **/
918 typedef enum
919 {
920 OrthancPluginDicomWebBinaryMode_Ignore, /*!< Don't include binary tags */
921 OrthancPluginDicomWebBinaryMode_InlineBinary, /*!< Inline encoding using Base64 */
922 OrthancPluginDicomWebBinaryMode_BulkDataUri /*!< Use a bulk data URI field */
923 } OrthancPluginDicomWebBinaryMode;
924
925
926
927 /**
928 * @brief A memory buffer allocated by the core system of Orthanc.
929 *
930 * A memory buffer allocated by the core system of Orthanc. When the
931 * content of the buffer is not useful anymore, it must be free by a
932 * call to ::OrthancPluginFreeMemoryBuffer().
933 **/
934 typedef struct
935 {
936 /**
937 * @brief The content of the buffer.
938 **/
939 void* data;
940
941 /**
942 * @brief The number of bytes in the buffer.
943 **/
944 uint32_t size;
945 } OrthancPluginMemoryBuffer;
946
947
948
949
950 /**
951 * @brief Opaque structure that represents the HTTP connection to the client application.
952 * @ingroup Callback
953 **/
954 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
955
956
957
958 /**
959 * @brief Opaque structure that represents a DICOM instance received by Orthanc.
960 **/
961 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
962
963
964
965 /**
966 * @brief Opaque structure that represents an image that is uncompressed in memory.
967 * @ingroup Images
968 **/
969 typedef struct _OrthancPluginImage_t OrthancPluginImage;
970
971
972
973 /**
974 * @brief Opaque structure that represents the storage area that is actually used by Orthanc.
975 * @ingroup Images
976 **/
977 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea;
978
979
980
981 /**
982 * @brief Opaque structure to an object that represents a C-Find query for worklists.
983 * @ingroup DicomCallbacks
984 **/
985 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery;
986
987
988
989 /**
990 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
991 * @ingroup DicomCallbacks
992 **/
993 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers;
994
995
996
997 /**
998 * @brief Opaque structure to an object that represents a C-Find query.
999 * @ingroup DicomCallbacks
1000 **/
1001 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery;
1002
1003
1004
1005 /**
1006 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
1007 * @ingroup DicomCallbacks
1008 **/
1009 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers;
1010
1011
1012
1013 /**
1014 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query.
1015 * @ingroup Toolbox
1016 **/
1017 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindMatcher;
1018
1019
1020
1021 /**
1022 * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server.
1023 * @ingroup Toolbox
1024 **/
1025 typedef struct _OrthancPluginPeers_t OrthancPluginPeers;
1026
1027
1028
1029 /**
1030 * @brief Opaque structure to a job to be executed by Orthanc.
1031 * @ingroup Toolbox
1032 **/
1033 typedef struct _OrthancPluginJob_t OrthancPluginJob;
1034
1035
1036
1037 /**
1038 * @brief Opaque structure that represents a node in a JSON or XML
1039 * document used in DICOMweb.
1040 * @ingroup Toolbox
1041 **/
1042 typedef struct _OrthancPluginDicomWebNode_t OrthancPluginDicomWebNode;
1043
1044
1045
1046 /**
1047 * @brief Signature of a callback function that answers to a REST request.
1048 * @ingroup Callbacks
1049 **/
1050 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) (
1051 OrthancPluginRestOutput* output,
1052 const char* url,
1053 const OrthancPluginHttpRequest* request);
1054
1055
1056
1057 /**
1058 * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance.
1059 * @ingroup Callbacks
1060 **/
1061 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) (
1062 OrthancPluginDicomInstance* instance,
1063 const char* instanceId);
1064
1065
1066
1067 /**
1068 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
1069 * @ingroup Callbacks
1070 **/
1071 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) (
1072 OrthancPluginChangeType changeType,
1073 OrthancPluginResourceType resourceType,
1074 const char* resourceId);
1075
1076
1077
1078 /**
1079 * @brief Signature of a callback function to decode a DICOM instance as an image.
1080 * @ingroup Callbacks
1081 **/
1082 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) (
1083 OrthancPluginImage** target,
1084 const void* dicom,
1085 const uint32_t size,
1086 uint32_t frameIndex);
1087
1088
1089
1090 /**
1091 * @brief Signature of a function to free dynamic memory.
1092 * @ingroup Callbacks
1093 **/
1094 typedef void (*OrthancPluginFree) (void* buffer);
1095
1096
1097
1098 /**
1099 * @brief Signature of a function to set the content of a node
1100 * encoding a binary DICOM tag, into a JSON or XML document
1101 * generated for DICOMweb.
1102 * @ingroup Callbacks
1103 **/
1104 typedef void (*OrthancPluginDicomWebSetBinaryNode) (
1105 OrthancPluginDicomWebNode* node,
1106 OrthancPluginDicomWebBinaryMode mode,
1107 const char* bulkDataUri);
1108
1109
1110
1111 /**
1112 * @brief Callback for writing to the storage area.
1113 *
1114 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
1115 *
1116 * @param uuid The UUID of the file.
1117 * @param content The content of the file.
1118 * @param size The size of the file.
1119 * @param type The content type corresponding to this file.
1120 * @return 0 if success, other value if error.
1121 * @ingroup Callbacks
1122 **/
1123 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) (
1124 const char* uuid,
1125 const void* content,
1126 int64_t size,
1127 OrthancPluginContentType type);
1128
1129
1130
1131 /**
1132 * @brief Callback for reading from the storage area.
1133 *
1134 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
1135 *
1136 * @param content The content of the file (output).
1137 * @param size The size of the file (output).
1138 * @param uuid The UUID of the file of interest.
1139 * @param type The content type corresponding to this file.
1140 * @return 0 if success, other value if error.
1141 * @ingroup Callbacks
1142 **/
1143 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) (
1144 void** content,
1145 int64_t* size,
1146 const char* uuid,
1147 OrthancPluginContentType type);
1148
1149
1150
1151 /**
1152 * @brief Callback for removing a file from the storage area.
1153 *
1154 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
1155 *
1156 * @param uuid The UUID of the file to be removed.
1157 * @param type The content type corresponding to this file.
1158 * @return 0 if success, other value if error.
1159 * @ingroup Callbacks
1160 **/
1161 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) (
1162 const char* uuid,
1163 OrthancPluginContentType type);
1164
1165
1166
1167 /**
1168 * @brief Callback to handle the C-Find SCP requests for worklists.
1169 *
1170 * Signature of a callback function that is triggered when Orthanc
1171 * receives a C-Find SCP request against modality worklists.
1172 *
1173 * @param answers The target structure where answers must be stored.
1174 * @param query The worklist query.
1175 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1176 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1177 * @return 0 if success, other value if error.
1178 * @ingroup DicomCallbacks
1179 **/
1180 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) (
1181 OrthancPluginWorklistAnswers* answers,
1182 const OrthancPluginWorklistQuery* query,
1183 const char* issuerAet,
1184 const char* calledAet);
1185
1186
1187
1188 /**
1189 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1190 *
1191 * Signature of a callback function that is triggered whenever
1192 * Orthanc receives an HTTP/REST request, and that answers whether
1193 * this request should be allowed. If the callback returns "0"
1194 * ("false"), the server answers with HTTP status code 403
1195 * (Forbidden).
1196 *
1197 * @param method The HTTP method used by the request.
1198 * @param uri The URI of interest.
1199 * @param ip The IP address of the HTTP client.
1200 * @param headersCount The number of HTTP headers.
1201 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1202 * @param headersValues The values of the HTTP headers.
1203 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1204 * @ingroup Callback
1205 * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2()
1206 **/
1207 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) (
1208 OrthancPluginHttpMethod method,
1209 const char* uri,
1210 const char* ip,
1211 uint32_t headersCount,
1212 const char* const* headersKeys,
1213 const char* const* headersValues);
1214
1215
1216
1217 /**
1218 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1219 *
1220 * Signature of a callback function that is triggered whenever
1221 * Orthanc receives an HTTP/REST request, and that answers whether
1222 * this request should be allowed. If the callback returns "0"
1223 * ("false"), the server answers with HTTP status code 403
1224 * (Forbidden).
1225 *
1226 * @param method The HTTP method used by the request.
1227 * @param uri The URI of interest.
1228 * @param ip The IP address of the HTTP client.
1229 * @param headersCount The number of HTTP headers.
1230 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1231 * @param headersValues The values of the HTTP headers.
1232 * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method).
1233 * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method).
1234 * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method).
1235 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1236 * @ingroup Callback
1237 **/
1238 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) (
1239 OrthancPluginHttpMethod method,
1240 const char* uri,
1241 const char* ip,
1242 uint32_t headersCount,
1243 const char* const* headersKeys,
1244 const char* const* headersValues,
1245 uint32_t getArgumentsCount,
1246 const char* const* getArgumentsKeys,
1247 const char* const* getArgumentsValues);
1248
1249
1250
1251 /**
1252 * @brief Callback to handle incoming C-Find SCP requests.
1253 *
1254 * Signature of a callback function that is triggered whenever
1255 * Orthanc receives a C-Find SCP request not concerning modality
1256 * worklists.
1257 *
1258 * @param answers The target structure where answers must be stored.
1259 * @param query The worklist query.
1260 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1261 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1262 * @return 0 if success, other value if error.
1263 * @ingroup DicomCallbacks
1264 **/
1265 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) (
1266 OrthancPluginFindAnswers* answers,
1267 const OrthancPluginFindQuery* query,
1268 const char* issuerAet,
1269 const char* calledAet);
1270
1271
1272
1273 /**
1274 * @brief Callback to handle incoming C-Move SCP requests.
1275 *
1276 * Signature of a callback function that is triggered whenever
1277 * Orthanc receives a C-Move SCP request. The callback receives the
1278 * type of the resource of interest (study, series, instance...)
1279 * together with the DICOM tags containing its identifiers. In turn,
1280 * the plugin must create a driver object that will be responsible
1281 * for driving the successive move suboperations.
1282 *
1283 * @param resourceType The type of the resource of interest. Note
1284 * that this might be set to ResourceType_None if the
1285 * QueryRetrieveLevel (0008,0052) tag was not provided by the
1286 * issuer (i.e. the originator modality).
1287 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL.
1288 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL.
1289 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL.
1290 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL.
1291 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL.
1292 * @param originatorAet The Application Entity Title (AET) of the
1293 * modality from which the request originates.
1294 * @param sourceAet The Application Entity Title (AET) of the
1295 * modality that should send its DICOM files to another modality.
1296 * @param targetAet The Application Entity Title (AET) of the
1297 * modality that should receive the DICOM files.
1298 * @param originatorId The Message ID issued by the originator modality,
1299 * as found in tag (0000,0110) of the DICOM query emitted by the issuer.
1300 *
1301 * @return The NULL value if the plugin cannot deal with this query,
1302 * or a pointer to the driver object that is responsible for
1303 * handling the successive move suboperations.
1304 *
1305 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation.
1306 * @ingroup DicomCallbacks
1307 **/
1308 typedef void* (*OrthancPluginMoveCallback) (
1309 OrthancPluginResourceType resourceType,
1310 const char* patientId,
1311 const char* accessionNumber,
1312 const char* studyInstanceUid,
1313 const char* seriesInstanceUid,
1314 const char* sopInstanceUid,
1315 const char* originatorAet,
1316 const char* sourceAet,
1317 const char* targetAet,
1318 uint16_t originatorId);
1319
1320
1321 /**
1322 * @brief Callback to read the size of a C-Move driver.
1323 *
1324 * Signature of a callback function that returns the number of
1325 * C-Move suboperations that are to be achieved by the given C-Move
1326 * driver. This driver is the return value of a previous call to the
1327 * OrthancPluginMoveCallback() callback.
1328 *
1329 * @param moveDriver The C-Move driver of interest.
1330 * @return The number of suboperations.
1331 * @ingroup DicomCallbacks
1332 **/
1333 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver);
1334
1335
1336 /**
1337 * @brief Callback to apply one C-Move suboperation.
1338 *
1339 * Signature of a callback function that applies the next C-Move
1340 * suboperation that os to be achieved by the given C-Move
1341 * driver. This driver is the return value of a previous call to the
1342 * OrthancPluginMoveCallback() callback.
1343 *
1344 * @param moveDriver The C-Move driver of interest.
1345 * @return 0 if success, or the error code if failure.
1346 * @ingroup DicomCallbacks
1347 **/
1348 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver);
1349
1350
1351 /**
1352 * @brief Callback to free one C-Move driver.
1353 *
1354 * Signature of a callback function that releases the resources
1355 * allocated by the given C-Move driver. This driver is the return
1356 * value of a previous call to the OrthancPluginMoveCallback()
1357 * callback.
1358 *
1359 * @param moveDriver The C-Move driver of interest.
1360 * @ingroup DicomCallbacks
1361 **/
1362 typedef void (*OrthancPluginFreeMove) (void* moveDriver);
1363
1364
1365 /**
1366 * @brief Callback to finalize one custom job.
1367 *
1368 * Signature of a callback function that releases all the resources
1369 * allocated by the given job. This job is the argument provided to
1370 * OrthancPluginCreateJob().
1371 *
1372 * @param job The job of interest.
1373 * @ingroup Toolbox
1374 **/
1375 typedef void (*OrthancPluginJobFinalize) (void* job);
1376
1377
1378 /**
1379 * @brief Callback to check the progress of one custom job.
1380 *
1381 * Signature of a callback function that returns the progress of the
1382 * job.
1383 *
1384 * @param job The job of interest.
1385 * @return The progress, as a floating-point number ranging from 0 to 1.
1386 * @ingroup Toolbox
1387 **/
1388 typedef float (*OrthancPluginJobGetProgress) (void* job);
1389
1390
1391 /**
1392 * @brief Callback to retrieve the content of one custom job.
1393 *
1394 * Signature of a callback function that returns human-readable
1395 * statistics about the job. This statistics must be formatted as a
1396 * JSON object. This information is notably displayed in the "Jobs"
1397 * tab of "Orthanc Explorer".
1398 *
1399 * @param job The job of interest.
1400 * @return The statistics, as a JSON object encoded as a string.
1401 * @ingroup Toolbox
1402 **/
1403 typedef const char* (*OrthancPluginJobGetContent) (void* job);
1404
1405
1406 /**
1407 * @brief Callback to serialize one custom job.
1408 *
1409 * Signature of a callback function that returns a serialized
1410 * version of the job, formatted as a JSON object. This
1411 * serialization is stored in the Orthanc database, and is used to
1412 * reload the job on the restart of Orthanc. The "unserialization"
1413 * callback (with OrthancPluginJobsUnserializer signature) will
1414 * receive this serialized object.
1415 *
1416 * @param job The job of interest.
1417 * @return The serialized job, as a JSON object encoded as a string.
1418 * @see OrthancPluginRegisterJobsUnserializer()
1419 * @ingroup Toolbox
1420 **/
1421 typedef const char* (*OrthancPluginJobGetSerialized) (void* job);
1422
1423
1424 /**
1425 * @brief Callback to execute one step of a custom job.
1426 *
1427 * Signature of a callback function that executes one step in the
1428 * job. The jobs engine of Orthanc will make successive calls to
1429 * this method, as long as it returns
1430 * OrthancPluginJobStepStatus_Continue.
1431 *
1432 * @param job The job of interest.
1433 * @return The status of execution.
1434 * @ingroup Toolbox
1435 **/
1436 typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job);
1437
1438
1439 /**
1440 * @brief Callback executed once one custom job leaves the "running" state.
1441 *
1442 * Signature of a callback function that is invoked once a job
1443 * leaves the "running" state. This can happen if the previous call
1444 * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc
1445 * server is being stopped, or if the user manually tags the job as
1446 * paused/canceled. This callback allows the plugin to free
1447 * resources allocated for running this custom job (e.g. to stop
1448 * threads, or to remove temporary files).
1449 *
1450 * Note that handling pauses might involves a specific treatment
1451 * (such a stopping threads, but keeping temporary files on the
1452 * disk). This "paused" situation can be checked by looking at the
1453 * "reason" parameter.
1454 *
1455 * @param job The job of interest.
1456 * @param reason The reason for leaving the "running" state.
1457 * @return 0 if success, or the error code if failure.
1458 * @ingroup Toolbox
1459 **/
1460 typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job,
1461 OrthancPluginJobStopReason reason);
1462
1463
1464 /**
1465 * @brief Callback executed once one stopped custom job is started again.
1466 *
1467 * Signature of a callback function that is invoked once a job
1468 * leaves the "failure/canceled" state, to be started again. This
1469 * function will typically reset the progress to zero. Note that
1470 * before being actually executed, the job would first be tagged as
1471 * "pending" in the Orthanc jobs engine.
1472 *
1473 * @param job The job of interest.
1474 * @return 0 if success, or the error code if failure.
1475 * @ingroup Toolbox
1476 **/
1477 typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job);
1478
1479
1480 /**
1481 * @brief Callback executed to unserialize a custom job.
1482 *
1483 * Signature of a callback function that unserializes a job that was
1484 * saved in the Orthanc database.
1485 *
1486 * @param jobType The type of the job, as provided to OrthancPluginCreateJob().
1487 * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized.
1488 * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL
1489 * if this unserializer cannot handle this job type.
1490 * @see OrthancPluginRegisterJobsUnserializer()
1491 * @ingroup Callbacks
1492 **/
1493 typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType,
1494 const char* serialized);
1495
1496
1497
1498 /**
1499 * @brief Callback executed to update the metrics of the plugin.
1500 *
1501 * Signature of a callback function that is called by Orthanc
1502 * whenever a monitoring tool (such as Prometheus) asks the current
1503 * values of the metrics. This callback gives the plugin a chance to
1504 * update its metrics, by calling OrthancPluginSetMetricsValue().
1505 * This is typically useful for metrics that are expensive to
1506 * acquire.
1507 *
1508 * @see OrthancPluginRegisterRefreshMetrics()
1509 * @ingroup Callbacks
1510 **/
1511 typedef void (*OrthancPluginRefreshMetricsCallback) ();
1512
1513
1514
1515 /**
1516 * @brief Callback executed to encode a binary tag in DICOMweb.
1517 *
1518 * Signature of a callback function that is called by Orthanc
1519 * whenever a DICOM tag that contains a binary value must be written
1520 * to a JSON or XML node, while a DICOMweb document is being
1521 * generated. The value representation (VR) of the DICOM tag can be
1522 * OB, OD, OF, OL, OW, or UN.
1523 *
1524 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
1525 * @param node The node being generated, as provided by Orthanc.
1526 * @param setter The setter to be used to encode the content of the node. If
1527 * the setter is not called, the binary tag is not written to the output document.
1528 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences.
1529 * This parameter gives the number of elements in the "levelTagGroup",
1530 * "levelTagElement", and "levelIndex" arrays.
1531 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy.
1532 * @param levelTagElement The element of the parent DICOM tags in the hierarchy.
1533 * @param levelIndex The index of the node in the parent sequences of the hiearchy.
1534 * @param tagGroup The group of the DICOM tag of interest.
1535 * @param tagElement The element of the DICOM tag of interest.
1536 * @param vr The value representation of the binary DICOM node.
1537 * @ingroup Callbacks
1538 **/
1539 typedef void (*OrthancPluginDicomWebBinaryCallback) (
1540 OrthancPluginDicomWebNode* node,
1541 OrthancPluginDicomWebSetBinaryNode setter,
1542 uint32_t levelDepth,
1543 const uint16_t* levelTagGroup,
1544 const uint16_t* levelTagElement,
1545 const uint32_t* levelIndex,
1546 uint16_t tagGroup,
1547 uint16_t tagElement,
1548 OrthancPluginValueRepresentation vr);
1549
1550
1551
1552 /**
1553 * @brief Data structure that contains information about the Orthanc core.
1554 **/
1555 typedef struct _OrthancPluginContext_t
1556 {
1557 void* pluginsManager;
1558 const char* orthancVersion;
1559 OrthancPluginFree Free;
1560 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context,
1561 _OrthancPluginService service,
1562 const void* params);
1563 } OrthancPluginContext;
1564
1565
1566
1567 /**
1568 * @brief An entry in the dictionary of DICOM tags.
1569 **/
1570 typedef struct
1571 {
1572 uint16_t group; /*!< The group of the tag */
1573 uint16_t element; /*!< The element of the tag */
1574 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */
1575 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */
1576 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */
1577 } OrthancPluginDictionaryEntry;
1578
1579
1580
1581 /**
1582 * @brief Free a string.
1583 *
1584 * Free a string that was allocated by the core system of Orthanc.
1585 *
1586 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1587 * @param str The string to be freed.
1588 **/
1589 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
1590 OrthancPluginContext* context,
1591 char* str)
1592 {
1593 if (str != NULL)
1594 {
1595 context->Free(str);
1596 }
1597 }
1598
1599
1600 /**
1601 * @brief Check that the version of the hosting Orthanc is above a given version.
1602 *
1603 * This function checks whether the version of the Orthanc server
1604 * running this plugin, is above the given version. Contrarily to
1605 * OrthancPluginCheckVersion(), it is up to the developer of the
1606 * plugin to make sure that all the Orthanc SDK services called by
1607 * the plugin are actually implemented in the given version of
1608 * Orthanc.
1609 *
1610 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1611 * @param expectedMajor Expected major version.
1612 * @param expectedMinor Expected minor version.
1613 * @param expectedRevision Expected revision.
1614 * @return 1 if and only if the versions are compatible. If the
1615 * result is 0, the initialization of the plugin should fail.
1616 * @see OrthancPluginCheckVersion
1617 * @ingroup Callbacks
1618 **/
1619 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersionAdvanced(
1620 OrthancPluginContext* context,
1621 int expectedMajor,
1622 int expectedMinor,
1623 int expectedRevision)
1624 {
1625 int major, minor, revision;
1626
1627 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
1628 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
1629 sizeof(int32_t) != sizeof(_OrthancPluginService) ||
1630 sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
1631 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
1632 sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
1633 sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
1634 sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
1635 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
1636 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) ||
1637 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
1638 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
1639 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
1640 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) ||
1641 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
1642 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
1643 sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) ||
1644 sizeof(int32_t) != sizeof(OrthancPluginConstraintType) ||
1645 sizeof(int32_t) != sizeof(OrthancPluginMetricsType) ||
1646 sizeof(int32_t) != sizeof(OrthancPluginDicomWebBinaryMode))
1647 {
1648 /* Mismatch in the size of the enumerations */
1649 return 0;
1650 }
1651
1652 /* Assume compatibility with the mainline */
1653 if (!strcmp(context->orthancVersion, "mainline"))
1654 {
1655 return 1;
1656 }
1657
1658 /* Parse the version of the Orthanc core */
1659 if (
1660 #ifdef _MSC_VER
1661 sscanf_s
1662 #else
1663 sscanf
1664 #endif
1665 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3)
1666 {
1667 return 0;
1668 }
1669
1670 /* Check the major number of the version */
1671
1672 if (major > expectedMajor)
1673 {
1674 return 1;
1675 }
1676
1677 if (major < expectedMajor)
1678 {
1679 return 0;
1680 }
1681
1682 /* Check the minor number of the version */
1683
1684 if (minor > expectedMinor)
1685 {
1686 return 1;
1687 }
1688
1689 if (minor < expectedMinor)
1690 {
1691 return 0;
1692 }
1693
1694 /* Check the revision number of the version */
1695
1696 if (revision >= expectedRevision)
1697 {
1698 return 1;
1699 }
1700 else
1701 {
1702 return 0;
1703 }
1704 }
1705
1706
1707 /**
1708 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
1709 *
1710 * This function checks whether the version of the Orthanc server
1711 * running this plugin, is above the version of the current Orthanc
1712 * SDK header. This guarantees that the plugin is compatible with
1713 * the hosting Orthanc (i.e. it will not call unavailable services).
1714 * The result of this function should always be checked in the
1715 * OrthancPluginInitialize() entry point of the plugin.
1716 *
1717 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1718 * @return 1 if and only if the versions are compatible. If the
1719 * result is 0, the initialization of the plugin should fail.
1720 * @see OrthancPluginCheckVersionAdvanced
1721 * @ingroup Callbacks
1722 **/
1723 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion(
1724 OrthancPluginContext* context)
1725 {
1726 return OrthancPluginCheckVersionAdvanced(
1727 context,
1728 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
1729 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
1730 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1731 }
1732
1733
1734 /**
1735 * @brief Free a memory buffer.
1736 *
1737 * Free a memory buffer that was allocated by the core system of Orthanc.
1738 *
1739 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1740 * @param buffer The memory buffer to release.
1741 **/
1742 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
1743 OrthancPluginContext* context,
1744 OrthancPluginMemoryBuffer* buffer)
1745 {
1746 context->Free(buffer->data);
1747 }
1748
1749
1750 /**
1751 * @brief Log an error.
1752 *
1753 * Log an error message using the Orthanc logging system.
1754 *
1755 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1756 * @param message The message to be logged.
1757 **/
1758 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
1759 OrthancPluginContext* context,
1760 const char* message)
1761 {
1762 context->InvokeService(context, _OrthancPluginService_LogError, message);
1763 }
1764
1765
1766 /**
1767 * @brief Log a warning.
1768 *
1769 * Log a warning message using the Orthanc logging system.
1770 *
1771 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1772 * @param message The message to be logged.
1773 **/
1774 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
1775 OrthancPluginContext* context,
1776 const char* message)
1777 {
1778 context->InvokeService(context, _OrthancPluginService_LogWarning, message);
1779 }
1780
1781
1782 /**
1783 * @brief Log an information.
1784 *
1785 * Log an information message using the Orthanc logging system.
1786 *
1787 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1788 * @param message The message to be logged.
1789 **/
1790 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
1791 OrthancPluginContext* context,
1792 const char* message)
1793 {
1794 context->InvokeService(context, _OrthancPluginService_LogInfo, message);
1795 }
1796
1797
1798
1799 typedef struct
1800 {
1801 const char* pathRegularExpression;
1802 OrthancPluginRestCallback callback;
1803 } _OrthancPluginRestCallback;
1804
1805 /**
1806 * @brief Register a REST callback.
1807 *
1808 * This function registers a REST callback against a regular
1809 * expression for a URI. This function must be called during the
1810 * initialization of the plugin, i.e. inside the
1811 * OrthancPluginInitialize() public function.
1812 *
1813 * Each REST callback is guaranteed to run in mutual exclusion.
1814 *
1815 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1816 * @param pathRegularExpression Regular expression for the URI. May contain groups.
1817 * @param callback The callback function to handle the REST call.
1818 * @see OrthancPluginRegisterRestCallbackNoLock()
1819 *
1820 * @note
1821 * The regular expression is case sensitive and must follow the
1822 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
1823 *
1824 * @ingroup Callbacks
1825 **/
1826 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
1827 OrthancPluginContext* context,
1828 const char* pathRegularExpression,
1829 OrthancPluginRestCallback callback)
1830 {
1831 _OrthancPluginRestCallback params;
1832 params.pathRegularExpression = pathRegularExpression;
1833 params.callback = callback;
1834 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, &params);
1835 }
1836
1837
1838
1839 /**
1840 * @brief Register a REST callback, without locking.
1841 *
1842 * This function registers a REST callback against a regular
1843 * expression for a URI. This function must be called during the
1844 * initialization of the plugin, i.e. inside the
1845 * OrthancPluginInitialize() public function.
1846 *
1847 * Contrarily to OrthancPluginRegisterRestCallback(), the callback
1848 * will NOT be invoked in mutual exclusion. This can be useful for
1849 * high-performance plugins that must handle concurrent requests
1850 * (Orthanc uses a pool of threads, one thread being assigned to
1851 * each incoming HTTP request). Of course, if using this function,
1852 * it is up to the plugin to implement the required locking
1853 * mechanisms.
1854 *
1855 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1856 * @param pathRegularExpression Regular expression for the URI. May contain groups.
1857 * @param callback The callback function to handle the REST call.
1858 * @see OrthancPluginRegisterRestCallback()
1859 *
1860 * @note
1861 * The regular expression is case sensitive and must follow the
1862 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
1863 *
1864 * @ingroup Callbacks
1865 **/
1866 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock(
1867 OrthancPluginContext* context,
1868 const char* pathRegularExpression,
1869 OrthancPluginRestCallback callback)
1870 {
1871 _OrthancPluginRestCallback params;
1872 params.pathRegularExpression = pathRegularExpression;
1873 params.callback = callback;
1874 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, &params);
1875 }
1876
1877
1878
1879 typedef struct
1880 {
1881 OrthancPluginOnStoredInstanceCallback callback;
1882 } _OrthancPluginOnStoredInstanceCallback;
1883
1884 /**
1885 * @brief Register a callback for received instances.
1886 *
1887 * This function registers a callback function that is called
1888 * whenever a new DICOM instance is stored into the Orthanc core.
1889 *
1890 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1891 * @param callback The callback function.
1892 * @ingroup Callbacks
1893 **/
1894 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
1895 OrthancPluginContext* context,
1896 OrthancPluginOnStoredInstanceCallback callback)
1897 {
1898 _OrthancPluginOnStoredInstanceCallback params;
1899 params.callback = callback;
1900
1901 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, &params);
1902 }
1903
1904
1905
1906 typedef struct
1907 {
1908 OrthancPluginRestOutput* output;
1909 const char* answer;
1910 uint32_t answerSize;
1911 const char* mimeType;
1912 } _OrthancPluginAnswerBuffer;
1913
1914 /**
1915 * @brief Answer to a REST request.
1916 *
1917 * This function answers to a REST request with the content of a memory buffer.
1918 *
1919 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1920 * @param output The HTTP connection to the client application.
1921 * @param answer Pointer to the memory buffer containing the answer.
1922 * @param answerSize Number of bytes of the answer.
1923 * @param mimeType The MIME type of the answer.
1924 * @ingroup REST
1925 **/
1926 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
1927 OrthancPluginContext* context,
1928 OrthancPluginRestOutput* output,
1929 const char* answer,
1930 uint32_t answerSize,
1931 const char* mimeType)
1932 {
1933 _OrthancPluginAnswerBuffer params;
1934 params.output = output;
1935 params.answer = answer;
1936 params.answerSize = answerSize;
1937 params.mimeType = mimeType;
1938 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, &params);
1939 }
1940
1941
1942 typedef struct
1943 {
1944 OrthancPluginRestOutput* output;
1945 OrthancPluginPixelFormat format;
1946 uint32_t width;
1947 uint32_t height;
1948 uint32_t pitch;
1949 const void* buffer;
1950 } _OrthancPluginCompressAndAnswerPngImage;
1951
1952 typedef struct
1953 {
1954 OrthancPluginRestOutput* output;
1955 OrthancPluginImageFormat imageFormat;
1956 OrthancPluginPixelFormat pixelFormat;
1957 uint32_t width;
1958 uint32_t height;
1959 uint32_t pitch;
1960 const void* buffer;
1961 uint8_t quality;
1962 } _OrthancPluginCompressAndAnswerImage;
1963
1964
1965 /**
1966 * @brief Answer to a REST request with a PNG image.
1967 *
1968 * This function answers to a REST request with a PNG image. The
1969 * parameters of this function describe a memory buffer that
1970 * contains an uncompressed image. The image will be automatically compressed
1971 * as a PNG image by the core system of Orthanc.
1972 *
1973 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1974 * @param output The HTTP connection to the client application.
1975 * @param format The memory layout of the uncompressed image.
1976 * @param width The width of the image.
1977 * @param height The height of the image.
1978 * @param pitch The pitch of the image (i.e. the number of bytes
1979 * between 2 successive lines of the image in the memory buffer).
1980 * @param buffer The memory buffer containing the uncompressed image.
1981 * @ingroup REST
1982 **/
1983 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
1984 OrthancPluginContext* context,
1985 OrthancPluginRestOutput* output,
1986 OrthancPluginPixelFormat format,
1987 uint32_t width,
1988 uint32_t height,
1989 uint32_t pitch,
1990 const void* buffer)
1991 {
1992 _OrthancPluginCompressAndAnswerImage params;
1993 params.output = output;
1994 params.imageFormat = OrthancPluginImageFormat_Png;
1995 params.pixelFormat = format;
1996 params.width = width;
1997 params.height = height;
1998 params.pitch = pitch;
1999 params.buffer = buffer;
2000 params.quality = 0; /* No quality for PNG */
2001 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
2002 }
2003
2004
2005
2006 typedef struct
2007 {
2008 OrthancPluginMemoryBuffer* target;
2009 const char* instanceId;
2010 } _OrthancPluginGetDicomForInstance;
2011
2012 /**
2013 * @brief Retrieve a DICOM instance using its Orthanc identifier.
2014 *
2015 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM
2016 * file is stored into a newly allocated memory buffer.
2017 *
2018 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2019 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2020 * @param instanceId The Orthanc identifier of the DICOM instance of interest.
2021 * @return 0 if success, or the error code if failure.
2022 * @ingroup Orthanc
2023 **/
2024 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance(
2025 OrthancPluginContext* context,
2026 OrthancPluginMemoryBuffer* target,
2027 const char* instanceId)
2028 {
2029 _OrthancPluginGetDicomForInstance params;
2030 params.target = target;
2031 params.instanceId = instanceId;
2032 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, &params);
2033 }
2034
2035
2036
2037 typedef struct
2038 {
2039 OrthancPluginMemoryBuffer* target;
2040 const char* uri;
2041 } _OrthancPluginRestApiGet;
2042
2043 /**
2044 * @brief Make a GET call to the built-in Orthanc REST API.
2045 *
2046 * Make a GET call to the built-in Orthanc REST API. The result to
2047 * the query is stored into a newly allocated memory buffer.
2048 *
2049 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2050 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2051 * @param uri The URI in the built-in Orthanc API.
2052 * @return 0 if success, or the error code if failure.
2053 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2054 * @see OrthancPluginRestApiGetAfterPlugins
2055 * @ingroup Orthanc
2056 **/
2057 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet(
2058 OrthancPluginContext* context,
2059 OrthancPluginMemoryBuffer* target,
2060 const char* uri)
2061 {
2062 _OrthancPluginRestApiGet params;
2063 params.target = target;
2064 params.uri = uri;
2065 return context->InvokeService(context, _OrthancPluginService_RestApiGet, &params);
2066 }
2067
2068
2069
2070 /**
2071 * @brief Make a GET call to the REST API, as tainted by the plugins.
2072 *
2073 * Make a GET call to the Orthanc REST API, after all the plugins
2074 * are applied. In other words, if some plugin overrides or adds the
2075 * called URI to the built-in Orthanc REST API, this call will
2076 * return the result provided by this plugin. The result to the
2077 * query is stored into a newly allocated memory buffer.
2078 *
2079 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2080 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2081 * @param uri The URI in the built-in Orthanc API.
2082 * @return 0 if success, or the error code if failure.
2083 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2084 * @see OrthancPluginRestApiGet
2085 * @ingroup Orthanc
2086 **/
2087 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins(
2088 OrthancPluginContext* context,
2089 OrthancPluginMemoryBuffer* target,
2090 const char* uri)
2091 {
2092 _OrthancPluginRestApiGet params;
2093 params.target = target;
2094 params.uri = uri;
2095 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, &params);
2096 }
2097
2098
2099
2100 typedef struct
2101 {
2102 OrthancPluginMemoryBuffer* target;
2103 const char* uri;
2104 const char* body;
2105 uint32_t bodySize;
2106 } _OrthancPluginRestApiPostPut;
2107
2108 /**
2109 * @brief Make a POST call to the built-in Orthanc REST API.
2110 *
2111 * Make a POST call to the built-in Orthanc REST API. The result to
2112 * the query is stored into a newly allocated memory buffer.
2113 *
2114 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2115 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2116 * @param uri The URI in the built-in Orthanc API.
2117 * @param body The body of the POST request.
2118 * @param bodySize The size of the body.
2119 * @return 0 if success, or the error code if failure.
2120 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2121 * @see OrthancPluginRestApiPostAfterPlugins
2122 * @ingroup Orthanc
2123 **/
2124 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost(
2125 OrthancPluginContext* context,
2126 OrthancPluginMemoryBuffer* target,
2127 const char* uri,
2128 const char* body,
2129 uint32_t bodySize)
2130 {
2131 _OrthancPluginRestApiPostPut params;
2132 params.target = target;
2133 params.uri = uri;
2134 params.body = body;
2135 params.bodySize = bodySize;
2136 return context->InvokeService(context, _OrthancPluginService_RestApiPost, &params);
2137 }
2138
2139
2140 /**
2141 * @brief Make a POST call to the REST API, as tainted by the plugins.
2142 *
2143 * Make a POST call to the Orthanc REST API, after all the plugins
2144 * are applied. In other words, if some plugin overrides or adds the
2145 * called URI to the built-in Orthanc REST API, this call will
2146 * return the result provided by this plugin. The result to the
2147 * query is stored into a newly allocated memory buffer.
2148 *
2149 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2150 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2151 * @param uri The URI in the built-in Orthanc API.
2152 * @param body The body of the POST request.
2153 * @param bodySize The size of the body.
2154 * @return 0 if success, or the error code if failure.
2155 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2156 * @see OrthancPluginRestApiPost
2157 * @ingroup Orthanc
2158 **/
2159 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins(
2160 OrthancPluginContext* context,
2161 OrthancPluginMemoryBuffer* target,
2162 const char* uri,
2163 const char* body,
2164 uint32_t bodySize)
2165 {
2166 _OrthancPluginRestApiPostPut params;
2167 params.target = target;
2168 params.uri = uri;
2169 params.body = body;
2170 params.bodySize = bodySize;
2171 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, &params);
2172 }
2173
2174
2175
2176 /**
2177 * @brief Make a DELETE call to the built-in Orthanc REST API.
2178 *
2179 * Make a DELETE call to the built-in Orthanc REST API.
2180 *
2181 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2182 * @param uri The URI to delete in the built-in Orthanc API.
2183 * @return 0 if success, or the error code if failure.
2184 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2185 * @see OrthancPluginRestApiDeleteAfterPlugins
2186 * @ingroup Orthanc
2187 **/
2188 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete(
2189 OrthancPluginContext* context,
2190 const char* uri)
2191 {
2192 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
2193 }
2194
2195
2196 /**
2197 * @brief Make a DELETE call to the REST API, as tainted by the plugins.
2198 *
2199 * Make a DELETE call to the Orthanc REST API, after all the plugins
2200 * are applied. In other words, if some plugin overrides or adds the
2201 * called URI to the built-in Orthanc REST API, this call will
2202 * return the result provided by this plugin.
2203 *
2204 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2205 * @param uri The URI to delete in the built-in Orthanc API.
2206 * @return 0 if success, or the error code if failure.
2207 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2208 * @see OrthancPluginRestApiDelete
2209 * @ingroup Orthanc
2210 **/
2211 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins(
2212 OrthancPluginContext* context,
2213 const char* uri)
2214 {
2215 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri);
2216 }
2217
2218
2219
2220 /**
2221 * @brief Make a PUT call to the built-in Orthanc REST API.
2222 *
2223 * Make a PUT call to the built-in Orthanc REST API. The result to
2224 * the query is stored into a newly allocated memory buffer.
2225 *
2226 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2227 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2228 * @param uri The URI in the built-in Orthanc API.
2229 * @param body The body of the PUT request.
2230 * @param bodySize The size of the body.
2231 * @return 0 if success, or the error code if failure.
2232 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2233 * @see OrthancPluginRestApiPutAfterPlugins
2234 * @ingroup Orthanc
2235 **/
2236 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut(
2237 OrthancPluginContext* context,
2238 OrthancPluginMemoryBuffer* target,
2239 const char* uri,
2240 const char* body,
2241 uint32_t bodySize)
2242 {
2243 _OrthancPluginRestApiPostPut params;
2244 params.target = target;
2245 params.uri = uri;
2246 params.body = body;
2247 params.bodySize = bodySize;
2248 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
2249 }
2250
2251
2252
2253 /**
2254 * @brief Make a PUT call to the REST API, as tainted by the plugins.
2255 *
2256 * Make a PUT call to the Orthanc REST API, after all the plugins
2257 * are applied. In other words, if some plugin overrides or adds the
2258 * called URI to the built-in Orthanc REST API, this call will
2259 * return the result provided by this plugin. The result to the
2260 * query is stored into a newly allocated memory buffer.
2261 *
2262 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2263 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2264 * @param uri The URI in the built-in Orthanc API.
2265 * @param body The body of the PUT request.
2266 * @param bodySize The size of the body.
2267 * @return 0 if success, or the error code if failure.
2268 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2269 * @see OrthancPluginRestApiPut
2270 * @ingroup Orthanc
2271 **/
2272 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins(
2273 OrthancPluginContext* context,
2274 OrthancPluginMemoryBuffer* target,
2275 const char* uri,
2276 const char* body,
2277 uint32_t bodySize)
2278 {
2279 _OrthancPluginRestApiPostPut params;
2280 params.target = target;
2281 params.uri = uri;
2282 params.body = body;
2283 params.bodySize = bodySize;
2284 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, &params);
2285 }
2286
2287
2288
2289 typedef struct
2290 {
2291 OrthancPluginRestOutput* output;
2292 const char* argument;
2293 } _OrthancPluginOutputPlusArgument;
2294
2295 /**
2296 * @brief Redirect a REST request.
2297 *
2298 * This function answers to a REST request by redirecting the user
2299 * to another URI using HTTP status 301.
2300 *
2301 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2302 * @param output The HTTP connection to the client application.
2303 * @param redirection Where to redirect.
2304 * @ingroup REST
2305 **/
2306 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
2307 OrthancPluginContext* context,
2308 OrthancPluginRestOutput* output,
2309 const char* redirection)
2310 {
2311 _OrthancPluginOutputPlusArgument params;
2312 params.output = output;
2313 params.argument = redirection;
2314 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
2315 }
2316
2317
2318
2319 typedef struct
2320 {
2321 char** result;
2322 const char* argument;
2323 } _OrthancPluginRetrieveDynamicString;
2324
2325 /**
2326 * @brief Look for a patient.
2327 *
2328 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
2329 * This function uses the database index to run as fast as possible (it does not loop
2330 * over all the stored patients).
2331 *
2332 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2333 * @param patientID The Patient ID of interest.
2334 * @return The NULL value if the patient is non-existent, or a string containing the
2335 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
2336 * @ingroup Orthanc
2337 **/
2338 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
2339 OrthancPluginContext* context,
2340 const char* patientID)
2341 {
2342 char* result;
2343
2344 _OrthancPluginRetrieveDynamicString params;
2345 params.result = &result;
2346 params.argument = patientID;
2347
2348 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, &params) != OrthancPluginErrorCode_Success)
2349 {
2350 /* Error */
2351 return NULL;
2352 }
2353 else
2354 {
2355 return result;
2356 }
2357 }
2358
2359
2360 /**
2361 * @brief Look for a study.
2362 *
2363 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
2364 * This function uses the database index to run as fast as possible (it does not loop
2365 * over all the stored studies).
2366 *
2367 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2368 * @param studyUID The Study Instance UID of interest.
2369 * @return The NULL value if the study is non-existent, or a string containing the
2370 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2371 * @ingroup Orthanc
2372 **/
2373 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
2374 OrthancPluginContext* context,
2375 const char* studyUID)
2376 {
2377 char* result;
2378
2379 _OrthancPluginRetrieveDynamicString params;
2380 params.result = &result;
2381 params.argument = studyUID;
2382
2383 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, &params) != OrthancPluginErrorCode_Success)
2384 {
2385 /* Error */
2386 return NULL;
2387 }
2388 else
2389 {
2390 return result;
2391 }
2392 }
2393
2394
2395 /**
2396 * @brief Look for a study, using the accession number.
2397 *
2398 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
2399 * This function uses the database index to run as fast as possible (it does not loop
2400 * over all the stored studies).
2401 *
2402 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2403 * @param accessionNumber The Accession Number of interest.
2404 * @return The NULL value if the study is non-existent, or a string containing the
2405 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2406 * @ingroup Orthanc
2407 **/
2408 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
2409 OrthancPluginContext* context,
2410 const char* accessionNumber)
2411 {
2412 char* result;
2413
2414 _OrthancPluginRetrieveDynamicString params;
2415 params.result = &result;
2416 params.argument = accessionNumber;
2417
2418 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, &params) != OrthancPluginErrorCode_Success)
2419 {
2420 /* Error */
2421 return NULL;
2422 }
2423 else
2424 {
2425 return result;
2426 }
2427 }
2428
2429
2430 /**
2431 * @brief Look for a series.
2432 *
2433 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
2434 * This function uses the database index to run as fast as possible (it does not loop
2435 * over all the stored series).
2436 *
2437 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2438 * @param seriesUID The Series Instance UID of interest.
2439 * @return The NULL value if the series is non-existent, or a string containing the
2440 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
2441 * @ingroup Orthanc
2442 **/
2443 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
2444 OrthancPluginContext* context,
2445 const char* seriesUID)
2446 {
2447 char* result;
2448
2449 _OrthancPluginRetrieveDynamicString params;
2450 params.result = &result;
2451 params.argument = seriesUID;
2452
2453 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, &params) != OrthancPluginErrorCode_Success)
2454 {
2455 /* Error */
2456 return NULL;
2457 }
2458 else
2459 {
2460 return result;
2461 }
2462 }
2463
2464
2465 /**
2466 * @brief Look for an instance.
2467 *
2468 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
2469 * This function uses the database index to run as fast as possible (it does not loop
2470 * over all the stored instances).
2471 *
2472 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2473 * @param sopInstanceUID The SOP Instance UID of interest.
2474 * @return The NULL value if the instance is non-existent, or a string containing the
2475 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
2476 * @ingroup Orthanc
2477 **/
2478 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
2479 OrthancPluginContext* context,
2480 const char* sopInstanceUID)
2481 {
2482 char* result;
2483
2484 _OrthancPluginRetrieveDynamicString params;
2485 params.result = &result;
2486 params.argument = sopInstanceUID;
2487
2488 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, &params) != OrthancPluginErrorCode_Success)
2489 {
2490 /* Error */
2491 return NULL;
2492 }
2493 else
2494 {
2495 return result;
2496 }
2497 }
2498
2499
2500
2501 typedef struct
2502 {
2503 OrthancPluginRestOutput* output;
2504 uint16_t status;
2505 } _OrthancPluginSendHttpStatusCode;
2506
2507 /**
2508 * @brief Send a HTTP status code.
2509 *
2510 * This function answers to a REST request by sending a HTTP status
2511 * code (such as "400 - Bad Request"). Note that:
2512 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
2513 * - Redirections (status 301) must use ::OrthancPluginRedirect().
2514 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
2515 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
2516 *
2517 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2518 * @param output The HTTP connection to the client application.
2519 * @param status The HTTP status code to be sent.
2520 * @ingroup REST
2521 * @see OrthancPluginSendHttpStatus()
2522 **/
2523 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
2524 OrthancPluginContext* context,
2525 OrthancPluginRestOutput* output,
2526 uint16_t status)
2527 {
2528 _OrthancPluginSendHttpStatusCode params;
2529 params.output = output;
2530 params.status = status;
2531 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
2532 }
2533
2534
2535 /**
2536 * @brief Signal that a REST request is not authorized.
2537 *
2538 * This function answers to a REST request by signaling that it is
2539 * not authorized.
2540 *
2541 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2542 * @param output The HTTP connection to the client application.
2543 * @param realm The realm for the authorization process.
2544 * @ingroup REST
2545 **/
2546 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
2547 OrthancPluginContext* context,
2548 OrthancPluginRestOutput* output,
2549 const char* realm)
2550 {
2551 _OrthancPluginOutputPlusArgument params;
2552 params.output = output;
2553 params.argument = realm;
2554 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
2555 }
2556
2557
2558 /**
2559 * @brief Signal that this URI does not support this HTTP method.
2560 *
2561 * This function answers to a REST request by signaling that the
2562 * queried URI does not support this method.
2563 *
2564 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2565 * @param output The HTTP connection to the client application.
2566 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
2567 * @ingroup REST
2568 **/
2569 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
2570 OrthancPluginContext* context,
2571 OrthancPluginRestOutput* output,
2572 const char* allowedMethods)
2573 {
2574 _OrthancPluginOutputPlusArgument params;
2575 params.output = output;
2576 params.argument = allowedMethods;
2577 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
2578 }
2579
2580
2581 typedef struct
2582 {
2583 OrthancPluginRestOutput* output;
2584 const char* key;
2585 const char* value;
2586 } _OrthancPluginSetHttpHeader;
2587
2588 /**
2589 * @brief Set a cookie.
2590 *
2591 * This function sets a cookie in the HTTP client.
2592 *
2593 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2594 * @param output The HTTP connection to the client application.
2595 * @param cookie The cookie to be set.
2596 * @param value The value of the cookie.
2597 * @ingroup REST
2598 **/
2599 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
2600 OrthancPluginContext* context,
2601 OrthancPluginRestOutput* output,
2602 const char* cookie,
2603 const char* value)
2604 {
2605 _OrthancPluginSetHttpHeader params;
2606 params.output = output;
2607 params.key = cookie;
2608 params.value = value;
2609 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
2610 }
2611
2612
2613 /**
2614 * @brief Set some HTTP header.
2615 *
2616 * This function sets a HTTP header in the HTTP answer.
2617 *
2618 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2619 * @param output The HTTP connection to the client application.
2620 * @param key The HTTP header to be set.
2621 * @param value The value of the HTTP header.
2622 * @ingroup REST
2623 **/
2624 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
2625 OrthancPluginContext* context,
2626 OrthancPluginRestOutput* output,
2627 const char* key,
2628 const char* value)
2629 {
2630 _OrthancPluginSetHttpHeader params;
2631 params.output = output;
2632 params.key = key;
2633 params.value = value;
2634 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, &params);
2635 }
2636
2637
2638 typedef struct
2639 {
2640 char** resultStringToFree;
2641 const char** resultString;
2642 int64_t* resultInt64;
2643 const char* key;
2644 OrthancPluginDicomInstance* instance;
2645 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */
2646 } _OrthancPluginAccessDicomInstance;
2647
2648
2649 /**
2650 * @brief Get the AET of a DICOM instance.
2651 *
2652 * This function returns the Application Entity Title (AET) of the
2653 * DICOM modality from which a DICOM instance originates.
2654 *
2655 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2656 * @param instance The instance of interest.
2657 * @return The AET if success, NULL if error.
2658 * @ingroup Callbacks
2659 **/
2660 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
2661 OrthancPluginContext* context,
2662 OrthancPluginDicomInstance* instance)
2663 {
2664 const char* result;
2665
2666 _OrthancPluginAccessDicomInstance params;
2667 memset(&params, 0, sizeof(params));
2668 params.resultString = &result;
2669 params.instance = instance;
2670
2671 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, &params) != OrthancPluginErrorCode_Success)
2672 {
2673 /* Error */
2674 return NULL;
2675 }
2676 else
2677 {
2678 return result;
2679 }
2680 }
2681
2682
2683 /**
2684 * @brief Get the size of a DICOM file.
2685 *
2686 * This function returns the number of bytes of the given DICOM instance.
2687 *
2688 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2689 * @param instance The instance of interest.
2690 * @return The size of the file, -1 in case of error.
2691 * @ingroup Callbacks
2692 **/
2693 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
2694 OrthancPluginContext* context,
2695 OrthancPluginDicomInstance* instance)
2696 {
2697 int64_t size;
2698
2699 _OrthancPluginAccessDicomInstance params;
2700 memset(&params, 0, sizeof(params));
2701 params.resultInt64 = &size;
2702 params.instance = instance;
2703
2704 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, &params) != OrthancPluginErrorCode_Success)
2705 {
2706 /* Error */
2707 return -1;
2708 }
2709 else
2710 {
2711 return size;
2712 }
2713 }
2714
2715
2716 /**
2717 * @brief Get the data of a DICOM file.
2718 *
2719 * This function returns a pointer to the content of the given DICOM instance.
2720 *
2721 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2722 * @param instance The instance of interest.
2723 * @return The pointer to the DICOM data, NULL in case of error.
2724 * @ingroup Callbacks
2725 **/
2726 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData(
2727 OrthancPluginContext* context,
2728 OrthancPluginDicomInstance* instance)
2729 {
2730 const char* result;
2731
2732 _OrthancPluginAccessDicomInstance params;
2733 memset(&params, 0, sizeof(params));
2734 params.resultString = &result;
2735 params.instance = instance;
2736
2737 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, &params) != OrthancPluginErrorCode_Success)
2738 {
2739 /* Error */
2740 return NULL;
2741 }
2742 else
2743 {
2744 return result;
2745 }
2746 }
2747
2748
2749 /**
2750 * @brief Get the DICOM tag hierarchy as a JSON file.
2751 *
2752 * This function returns a pointer to a newly created string
2753 * containing a JSON file. This JSON file encodes the tag hierarchy
2754 * of the given DICOM instance.
2755 *
2756 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2757 * @param instance The instance of interest.
2758 * @return The NULL value in case of error, or a string containing the JSON file.
2759 * This string must be freed by OrthancPluginFreeString().
2760 * @ingroup Callbacks
2761 **/
2762 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
2763 OrthancPluginContext* context,
2764 OrthancPluginDicomInstance* instance)
2765 {
2766 char* result;
2767
2768 _OrthancPluginAccessDicomInstance params;
2769 memset(&params, 0, sizeof(params));
2770 params.resultStringToFree = &result;
2771 params.instance = instance;
2772
2773 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, &params) != OrthancPluginErrorCode_Success)
2774 {
2775 /* Error */
2776 return NULL;
2777 }
2778 else
2779 {
2780 return result;
2781 }
2782 }
2783
2784
2785 /**
2786 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
2787 *
2788 * This function returns a pointer to a newly created string
2789 * containing a JSON file. This JSON file encodes the tag hierarchy
2790 * of the given DICOM instance. In contrast with
2791 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in
2792 * its simplified version.
2793 *
2794 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2795 * @param instance The instance of interest.
2796 * @return The NULL value in case of error, or a string containing the JSON file.
2797 * This string must be freed by OrthancPluginFreeString().
2798 * @ingroup Callbacks
2799 **/
2800 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
2801 OrthancPluginContext* context,
2802 OrthancPluginDicomInstance* instance)
2803 {
2804 char* result;
2805
2806 _OrthancPluginAccessDicomInstance params;
2807 memset(&params, 0, sizeof(params));
2808 params.resultStringToFree = &result;
2809 params.instance = instance;
2810
2811 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, &params) != OrthancPluginErrorCode_Success)
2812 {
2813 /* Error */
2814 return NULL;
2815 }
2816 else
2817 {
2818 return result;
2819 }
2820 }
2821
2822
2823 /**
2824 * @brief Check whether a DICOM instance is associated with some metadata.
2825 *
2826 * This function checks whether the DICOM instance of interest is
2827 * associated with some metadata. As of Orthanc 0.8.1, in the
2828 * callbacks registered by
2829 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
2830 * possibly available metadata are "ReceptionDate", "RemoteAET" and
2831 * "IndexInSeries".
2832 *
2833 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2834 * @param instance The instance of interest.
2835 * @param metadata The metadata of interest.
2836 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
2837 * @ingroup Callbacks
2838 **/
2839 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata(
2840 OrthancPluginContext* context,
2841 OrthancPluginDicomInstance* instance,
2842 const char* metadata)
2843 {
2844 int64_t result;
2845
2846 _OrthancPluginAccessDicomInstance params;
2847 memset(&params, 0, sizeof(params));
2848 params.resultInt64 = &result;
2849 params.instance = instance;
2850 params.key = metadata;
2851
2852 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
2853 {
2854 /* Error */
2855 return -1;
2856 }
2857 else
2858 {
2859 return (result != 0);
2860 }
2861 }
2862
2863
2864 /**
2865 * @brief Get the value of some metadata associated with a given DICOM instance.
2866 *
2867 * This functions returns the value of some metadata that is associated with the DICOM instance of interest.
2868 * Before calling this function, the existence of the metadata must have been checked with
2869 * ::OrthancPluginHasInstanceMetadata().
2870 *
2871 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2872 * @param instance The instance of interest.
2873 * @param metadata The metadata of interest.
2874 * @return The metadata value if success, NULL if error.
2875 * @ingroup Callbacks
2876 **/
2877 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
2878 OrthancPluginContext* context,
2879 OrthancPluginDicomInstance* instance,
2880 const char* metadata)
2881 {
2882 const char* result;
2883
2884 _OrthancPluginAccessDicomInstance params;
2885 memset(&params, 0, sizeof(params));
2886 params.resultString = &result;
2887 params.instance = instance;
2888 params.key = metadata;
2889
2890 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
2891 {
2892 /* Error */
2893 return NULL;
2894 }
2895 else
2896 {
2897 return result;
2898 }
2899 }
2900
2901
2902
2903 typedef struct
2904 {
2905 OrthancPluginStorageCreate create;
2906 OrthancPluginStorageRead read;
2907 OrthancPluginStorageRemove remove;
2908 OrthancPluginFree free;
2909 } _OrthancPluginRegisterStorageArea;
2910
2911 /**
2912 * @brief Register a custom storage area.
2913 *
2914 * This function registers a custom storage area, to replace the
2915 * built-in way Orthanc stores its files on the filesystem. This
2916 * function must be called during the initialization of the plugin,
2917 * i.e. inside the OrthancPluginInitialize() public function.
2918 *
2919 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2920 * @param create The callback function to store a file on the custom storage area.
2921 * @param read The callback function to read a file from the custom storage area.
2922 * @param remove The callback function to remove a file from the custom storage area.
2923 * @ingroup Callbacks
2924 **/
2925 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
2926 OrthancPluginContext* context,
2927 OrthancPluginStorageCreate create,
2928 OrthancPluginStorageRead read,
2929 OrthancPluginStorageRemove remove)
2930 {
2931 _OrthancPluginRegisterStorageArea params;
2932 params.create = create;
2933 params.read = read;
2934 params.remove = remove;
2935
2936 #ifdef __cplusplus
2937 params.free = ::free;
2938 #else
2939 params.free = free;
2940 #endif
2941
2942 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, &params);
2943 }
2944
2945
2946
2947 /**
2948 * @brief Return the path to the Orthanc executable.
2949 *
2950 * This function returns the path to the Orthanc executable.
2951 *
2952 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2953 * @return NULL in the case of an error, or a newly allocated string
2954 * containing the path. This string must be freed by
2955 * OrthancPluginFreeString().
2956 **/
2957 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
2958 {
2959 char* result;
2960
2961 _OrthancPluginRetrieveDynamicString params;
2962 params.result = &result;
2963 params.argument = NULL;
2964
2965 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, &params) != OrthancPluginErrorCode_Success)
2966 {
2967 /* Error */
2968 return NULL;
2969 }
2970 else
2971 {
2972 return result;
2973 }
2974 }
2975
2976
2977 /**
2978 * @brief Return the directory containing the Orthanc.
2979 *
2980 * This function returns the path to the directory containing the Orthanc executable.
2981 *
2982 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2983 * @return NULL in the case of an error, or a newly allocated string
2984 * containing the path. This string must be freed by
2985 * OrthancPluginFreeString().
2986 **/
2987 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
2988 {
2989 char* result;
2990
2991 _OrthancPluginRetrieveDynamicString params;
2992 params.result = &result;
2993 params.argument = NULL;
2994
2995 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, &params) != OrthancPluginErrorCode_Success)
2996 {
2997 /* Error */
2998 return NULL;
2999 }
3000 else
3001 {
3002 return result;
3003 }
3004 }
3005
3006
3007 /**
3008 * @brief Return the path to the configuration file(s).
3009 *
3010 * This function returns the path to the configuration file(s) that
3011 * was specified when starting Orthanc. Since version 0.9.1, this
3012 * path can refer to a folder that stores a set of configuration
3013 * files. This function is deprecated in favor of
3014 * OrthancPluginGetConfiguration().
3015 *
3016 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3017 * @return NULL in the case of an error, or a newly allocated string
3018 * containing the path. This string must be freed by
3019 * OrthancPluginFreeString().
3020 * @see OrthancPluginGetConfiguration()
3021 **/
3022 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
3023 {
3024 char* result;
3025
3026 _OrthancPluginRetrieveDynamicString params;
3027 params.result = &result;
3028 params.argument = NULL;
3029
3030 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, &params) != OrthancPluginErrorCode_Success)
3031 {
3032 /* Error */
3033 return NULL;
3034 }
3035 else
3036 {
3037 return result;
3038 }
3039 }
3040
3041
3042
3043 typedef struct
3044 {
3045 OrthancPluginOnChangeCallback callback;
3046 } _OrthancPluginOnChangeCallback;
3047
3048 /**
3049 * @brief Register a callback to monitor changes.
3050 *
3051 * This function registers a callback function that is called
3052 * whenever a change happens to some DICOM resource.
3053 *
3054 * @warning If your change callback has to call the REST API of
3055 * Orthanc, you should make these calls in a separate thread (with
3056 * the events passing through a message queue). Otherwise, this
3057 * could result in deadlocks in the presence of other plugins or Lua
3058 * scripts.
3059 *
3060 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3061 * @param callback The callback function.
3062 * @ingroup Callbacks
3063 **/
3064 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback(
3065 OrthancPluginContext* context,
3066 OrthancPluginOnChangeCallback callback)
3067 {
3068 _OrthancPluginOnChangeCallback params;
3069 params.callback = callback;
3070
3071 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, &params);
3072 }
3073
3074
3075
3076 typedef struct
3077 {
3078 const char* plugin;
3079 _OrthancPluginProperty property;
3080 const char* value;
3081 } _OrthancPluginSetPluginProperty;
3082
3083
3084 /**
3085 * @brief Set the URI where the plugin provides its Web interface.
3086 *
3087 * For plugins that come with a Web interface, this function
3088 * declares the entry path where to find this interface. This
3089 * information is notably used in the "Plugins" page of Orthanc
3090 * Explorer.
3091 *
3092 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3093 * @param uri The root URI for this plugin.
3094 **/
3095 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri(
3096 OrthancPluginContext* context,
3097 const char* uri)
3098 {
3099 _OrthancPluginSetPluginProperty params;
3100 params.plugin = OrthancPluginGetName();
3101 params.property = _OrthancPluginProperty_RootUri;
3102 params.value = uri;
3103
3104 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3105 }
3106
3107
3108 /**
3109 * @brief Set a description for this plugin.
3110 *
3111 * Set a description for this plugin. It is displayed in the
3112 * "Plugins" page of Orthanc Explorer.
3113 *
3114 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3115 * @param description The description.
3116 **/
3117 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription(
3118 OrthancPluginContext* context,
3119 const char* description)
3120 {
3121 _OrthancPluginSetPluginProperty params;
3122 params.plugin = OrthancPluginGetName();
3123 params.property = _OrthancPluginProperty_Description;
3124 params.value = description;
3125
3126 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3127 }
3128
3129
3130 /**
3131 * @brief Extend the JavaScript code of Orthanc Explorer.
3132 *
3133 * Add JavaScript code to customize the default behavior of Orthanc
3134 * Explorer. This can for instance be used to add new buttons.
3135 *
3136 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3137 * @param javascript The custom JavaScript code.
3138 **/
3139 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer(
3140 OrthancPluginContext* context,
3141 const char* javascript)
3142 {
3143 _OrthancPluginSetPluginProperty params;
3144 params.plugin = OrthancPluginGetName();
3145 params.property = _OrthancPluginProperty_OrthancExplorer;
3146 params.value = javascript;
3147
3148 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3149 }
3150
3151
3152 typedef struct
3153 {
3154 char** result;
3155 int32_t property;
3156 const char* value;
3157 } _OrthancPluginGlobalProperty;
3158
3159
3160 /**
3161 * @brief Get the value of a global property.
3162 *
3163 * Get the value of a global property that is stored in the Orthanc database. Global
3164 * properties whose index is below 1024 are reserved by Orthanc.
3165 *
3166 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3167 * @param property The global property of interest.
3168 * @param defaultValue The value to return, if the global property is unset.
3169 * @return The value of the global property, or NULL in the case of an error. This
3170 * string must be freed by OrthancPluginFreeString().
3171 * @ingroup Orthanc
3172 **/
3173 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty(
3174 OrthancPluginContext* context,
3175 int32_t property,
3176 const char* defaultValue)
3177 {
3178 char* result;
3179
3180 _OrthancPluginGlobalProperty params;
3181 params.result = &result;
3182 params.property = property;
3183 params.value = defaultValue;
3184
3185 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, &params) != OrthancPluginErrorCode_Success)
3186 {
3187 /* Error */
3188 return NULL;
3189 }
3190 else
3191 {
3192 return result;
3193 }
3194 }
3195
3196
3197 /**
3198 * @brief Set the value of a global property.
3199 *
3200 * Set the value of a global property into the Orthanc
3201 * database. Setting a global property can be used by plugins to
3202 * save their internal parameters. Plugins are only allowed to set
3203 * properties whose index are above or equal to 1024 (properties
3204 * below 1024 are read-only and reserved by Orthanc).
3205 *
3206 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3207 * @param property The global property of interest.
3208 * @param value The value to be set in the global property.
3209 * @return 0 if success, or the error code if failure.
3210 * @ingroup Orthanc
3211 **/
3212 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty(
3213 OrthancPluginContext* context,
3214 int32_t property,
3215 const char* value)
3216 {
3217 _OrthancPluginGlobalProperty params;
3218 params.result = NULL;
3219 params.property = property;
3220 params.value = value;
3221
3222 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, &params);
3223 }
3224
3225
3226
3227 typedef struct
3228 {
3229 int32_t *resultInt32;
3230 uint32_t *resultUint32;
3231 int64_t *resultInt64;
3232 uint64_t *resultUint64;
3233 } _OrthancPluginReturnSingleValue;
3234
3235 /**
3236 * @brief Get the number of command-line arguments.
3237 *
3238 * Retrieve the number of command-line arguments that were used to launch Orthanc.
3239 *
3240 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3241 * @return The number of arguments.
3242 **/
3243 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount(
3244 OrthancPluginContext* context)
3245 {
3246 uint32_t count = 0;
3247
3248 _OrthancPluginReturnSingleValue params;
3249 memset(&params, 0, sizeof(params));
3250 params.resultUint32 = &count;
3251
3252 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, &params) != OrthancPluginErrorCode_Success)
3253 {
3254 /* Error */
3255 return 0;
3256 }
3257 else
3258 {
3259 return count;
3260 }
3261 }
3262
3263
3264
3265 /**
3266 * @brief Get the value of a command-line argument.
3267 *
3268 * Get the value of one of the command-line arguments that were used
3269 * to launch Orthanc. The number of available arguments can be
3270 * retrieved by OrthancPluginGetCommandLineArgumentsCount().
3271 *
3272 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3273 * @param argument The index of the argument.
3274 * @return The value of the argument, or NULL in the case of an error. This
3275 * string must be freed by OrthancPluginFreeString().
3276 **/
3277 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument(
3278 OrthancPluginContext* context,
3279 uint32_t argument)
3280 {
3281 char* result;
3282
3283 _OrthancPluginGlobalProperty params;
3284 params.result = &result;
3285 params.property = (int32_t) argument;
3286 params.value = NULL;
3287
3288 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, &params) != OrthancPluginErrorCode_Success)
3289 {
3290 /* Error */
3291 return NULL;
3292 }
3293 else
3294 {
3295 return result;
3296 }
3297 }
3298
3299
3300 /**
3301 * @brief Get the expected version of the database schema.
3302 *
3303 * Retrieve the expected version of the database schema.
3304 *
3305 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3306 * @return The version.
3307 * @ingroup Callbacks
3308 **/
3309 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
3310 OrthancPluginContext* context)
3311 {
3312 uint32_t count = 0;
3313
3314 _OrthancPluginReturnSingleValue params;
3315 memset(&params, 0, sizeof(params));
3316 params.resultUint32 = &count;
3317
3318 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params) != OrthancPluginErrorCode_Success)
3319 {
3320 /* Error */
3321 return 0;
3322 }
3323 else
3324 {
3325 return count;
3326 }
3327 }
3328
3329
3330
3331 /**
3332 * @brief Return the content of the configuration file(s).
3333 *
3334 * This function returns the content of the configuration that is
3335 * used by Orthanc, formatted as a JSON string.
3336 *
3337 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3338 * @return NULL in the case of an error, or a newly allocated string
3339 * containing the configuration. This string must be freed by
3340 * OrthancPluginFreeString().
3341 **/
3342 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context)
3343 {
3344 char* result;
3345
3346 _OrthancPluginRetrieveDynamicString params;
3347 params.result = &result;
3348 params.argument = NULL;
3349
3350 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, &params) != OrthancPluginErrorCode_Success)
3351 {
3352 /* Error */
3353 return NULL;
3354 }
3355 else
3356 {
3357 return result;
3358 }
3359 }
3360
3361
3362
3363 typedef struct
3364 {
3365 OrthancPluginRestOutput* output;
3366 const char* subType;
3367 const char* contentType;
3368 } _OrthancPluginStartMultipartAnswer;
3369
3370 /**
3371 * @brief Start an HTTP multipart answer.
3372 *
3373 * Initiates a HTTP multipart answer, as the result of a REST request.
3374 *
3375 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3376 * @param output The HTTP connection to the client application.
3377 * @param subType The sub-type of the multipart answer ("mixed" or "related").
3378 * @param contentType The MIME type of the items in the multipart answer.
3379 * @return 0 if success, or the error code if failure.
3380 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2()
3381 * @ingroup REST
3382 **/
3383 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer(
3384 OrthancPluginContext* context,
3385 OrthancPluginRestOutput* output,
3386 const char* subType,
3387 const char* contentType)
3388 {
3389 _OrthancPluginStartMultipartAnswer params;
3390 params.output = output;
3391 params.subType = subType;
3392 params.contentType = contentType;
3393 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, &params);
3394 }
3395
3396
3397 /**
3398 * @brief Send an item as a part of some HTTP multipart answer.
3399 *
3400 * This function sends an item as a part of some HTTP multipart
3401 * answer that was initiated by OrthancPluginStartMultipartAnswer().
3402 *
3403 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3404 * @param output The HTTP connection to the client application.
3405 * @param answer Pointer to the memory buffer containing the item.
3406 * @param answerSize Number of bytes of the item.
3407 * @return 0 if success, or the error code if failure (this notably happens
3408 * if the connection is closed by the client).
3409 * @see OrthancPluginSendMultipartItem2()
3410 * @ingroup REST
3411 **/
3412 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem(
3413 OrthancPluginContext* context,
3414 OrthancPluginRestOutput* output,
3415 const char* answer,
3416 uint32_t answerSize)
3417 {
3418 _OrthancPluginAnswerBuffer params;
3419 params.output = output;
3420 params.answer = answer;
3421 params.answerSize = answerSize;
3422 params.mimeType = NULL;
3423 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, &params);
3424 }
3425
3426
3427
3428 typedef struct
3429 {
3430 OrthancPluginMemoryBuffer* target;
3431 const void* source;
3432 uint32_t size;
3433 OrthancPluginCompressionType compression;
3434 uint8_t uncompress;
3435 } _OrthancPluginBufferCompression;
3436
3437
3438 /**
3439 * @brief Compress or decompress a buffer.
3440 *
3441 * This function compresses or decompresses a buffer, using the
3442 * version of the zlib library that is used by the Orthanc core.
3443 *
3444 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3445 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3446 * @param source The source buffer.
3447 * @param size The size in bytes of the source buffer.
3448 * @param compression The compression algorithm.
3449 * @param uncompress If set to "0", the buffer must be compressed.
3450 * If set to "1", the buffer must be uncompressed.
3451 * @return 0 if success, or the error code if failure.
3452 * @ingroup Images
3453 **/
3454 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression(
3455 OrthancPluginContext* context,
3456 OrthancPluginMemoryBuffer* target,
3457 const void* source,
3458 uint32_t size,
3459 OrthancPluginCompressionType compression,
3460 uint8_t uncompress)
3461 {
3462 _OrthancPluginBufferCompression params;
3463 params.target = target;
3464 params.source = source;
3465 params.size = size;
3466 params.compression = compression;
3467 params.uncompress = uncompress;
3468
3469 return context->InvokeService(context, _OrthancPluginService_BufferCompression, &params);
3470 }
3471
3472
3473
3474 typedef struct
3475 {
3476 OrthancPluginMemoryBuffer* target;
3477 const char* path;
3478 } _OrthancPluginReadFile;
3479
3480 /**
3481 * @brief Read a file.
3482 *
3483 * Read the content of a file on the filesystem, and returns it into
3484 * a newly allocated memory buffer.
3485 *
3486 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3487 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3488 * @param path The path of the file to be read.
3489 * @return 0 if success, or the error code if failure.
3490 **/
3491 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile(
3492 OrthancPluginContext* context,
3493 OrthancPluginMemoryBuffer* target,
3494 const char* path)
3495 {
3496 _OrthancPluginReadFile params;
3497 params.target = target;
3498 params.path = path;
3499 return context->InvokeService(context, _OrthancPluginService_ReadFile, &params);
3500 }
3501
3502
3503
3504 typedef struct
3505 {
3506 const char* path;
3507 const void* data;
3508 uint32_t size;
3509 } _OrthancPluginWriteFile;
3510
3511 /**
3512 * @brief Write a file.
3513 *
3514 * Write the content of a memory buffer to the filesystem.
3515 *
3516 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3517 * @param path The path of the file to be written.
3518 * @param data The content of the memory buffer.
3519 * @param size The size of the memory buffer.
3520 * @return 0 if success, or the error code if failure.
3521 **/
3522 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile(
3523 OrthancPluginContext* context,
3524 const char* path,
3525 const void* data,
3526 uint32_t size)
3527 {
3528 _OrthancPluginWriteFile params;
3529 params.path = path;
3530 params.data = data;
3531 params.size = size;
3532 return context->InvokeService(context, _OrthancPluginService_WriteFile, &params);
3533 }
3534
3535
3536
3537 typedef struct
3538 {
3539 const char** target;
3540 OrthancPluginErrorCode error;
3541 } _OrthancPluginGetErrorDescription;
3542
3543 /**
3544 * @brief Get the description of a given error code.
3545 *
3546 * This function returns the description of a given error code.
3547 *
3548 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3549 * @param error The error code of interest.
3550 * @return The error description. This is a statically-allocated
3551 * string, do not free it.
3552 **/
3553 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription(
3554 OrthancPluginContext* context,
3555 OrthancPluginErrorCode error)
3556 {
3557 const char* result = NULL;
3558
3559 _OrthancPluginGetErrorDescription params;
3560 params.target = &result;
3561 params.error = error;
3562
3563 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, &params) != OrthancPluginErrorCode_Success ||
3564 result == NULL)
3565 {
3566 return "Unknown error code";
3567 }
3568 else
3569 {
3570 return result;
3571 }
3572 }
3573
3574
3575
3576 typedef struct
3577 {
3578 OrthancPluginRestOutput* output;
3579 uint16_t status;
3580 const char* body;
3581 uint32_t bodySize;
3582 } _OrthancPluginSendHttpStatus;
3583
3584 /**
3585 * @brief Send a HTTP status, with a custom body.
3586 *
3587 * This function answers to a HTTP request by sending a HTTP status
3588 * code (such as "400 - Bad Request"), together with a body
3589 * describing the error. The body will only be returned if the
3590 * configuration option "HttpDescribeErrors" of Orthanc is set to "true".
3591 *
3592 * Note that:
3593 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
3594 * - Redirections (status 301) must use ::OrthancPluginRedirect().
3595 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
3596 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
3597 *
3598 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3599 * @param output The HTTP connection to the client application.
3600 * @param status The HTTP status code to be sent.
3601 * @param body The body of the answer.
3602 * @param bodySize The size of the body.
3603 * @see OrthancPluginSendHttpStatusCode()
3604 * @ingroup REST
3605 **/
3606 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus(
3607 OrthancPluginContext* context,
3608 OrthancPluginRestOutput* output,
3609 uint16_t status,
3610 const char* body,
3611 uint32_t bodySize)
3612 {
3613 _OrthancPluginSendHttpStatus params;
3614 params.output = output;
3615 params.status = status;
3616 params.body = body;
3617 params.bodySize = bodySize;
3618 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, &params);
3619 }
3620
3621
3622
3623 typedef struct
3624 {
3625 const OrthancPluginImage* image;
3626 uint32_t* resultUint32;
3627 OrthancPluginPixelFormat* resultPixelFormat;
3628 void** resultBuffer;
3629 } _OrthancPluginGetImageInfo;
3630
3631
3632 /**
3633 * @brief Return the pixel format of an image.
3634 *
3635 * This function returns the type of memory layout for the pixels of the given image.
3636 *
3637 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3638 * @param image The image of interest.
3639 * @return The pixel format.
3640 * @ingroup Images
3641 **/
3642 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat(
3643 OrthancPluginContext* context,
3644 const OrthancPluginImage* image)
3645 {
3646 OrthancPluginPixelFormat target;
3647
3648 _OrthancPluginGetImageInfo params;
3649 memset(&params, 0, sizeof(params));
3650 params.image = image;
3651 params.resultPixelFormat = &target;
3652
3653 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, &params) != OrthancPluginErrorCode_Success)
3654 {
3655 return OrthancPluginPixelFormat_Unknown;
3656 }
3657 else
3658 {
3659 return (OrthancPluginPixelFormat) target;
3660 }
3661 }
3662
3663
3664
3665 /**
3666 * @brief Return the width of an image.
3667 *
3668 * This function returns the width of the given image.
3669 *
3670 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3671 * @param image The image of interest.
3672 * @return The width.
3673 * @ingroup Images
3674 **/
3675 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth(
3676 OrthancPluginContext* context,
3677 const OrthancPluginImage* image)
3678 {
3679 uint32_t width;
3680
3681 _OrthancPluginGetImageInfo params;
3682 memset(&params, 0, sizeof(params));
3683 params.image = image;
3684 params.resultUint32 = &width;
3685
3686 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, &params) != OrthancPluginErrorCode_Success)
3687 {
3688 return 0;
3689 }
3690 else
3691 {
3692 return width;
3693 }
3694 }
3695
3696
3697
3698 /**
3699 * @brief Return the height of an image.
3700 *
3701 * This function returns the height of the given image.
3702 *
3703 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3704 * @param image The image of interest.
3705 * @return The height.
3706 * @ingroup Images
3707 **/
3708 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight(
3709 OrthancPluginContext* context,
3710 const OrthancPluginImage* image)
3711 {
3712 uint32_t height;
3713
3714 _OrthancPluginGetImageInfo params;
3715 memset(&params, 0, sizeof(params));
3716 params.image = image;
3717 params.resultUint32 = &height;
3718
3719 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, &params) != OrthancPluginErrorCode_Success)
3720 {
3721 return 0;
3722 }
3723 else
3724 {
3725 return height;
3726 }
3727 }
3728
3729
3730
3731 /**
3732 * @brief Return the pitch of an image.
3733 *
3734 * This function returns the pitch of the given image. The pitch is
3735 * defined as the number of bytes between 2 successive lines of the
3736 * image in the memory buffer.
3737 *
3738 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3739 * @param image The image of interest.
3740 * @return The pitch.
3741 * @ingroup Images
3742 **/
3743 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch(
3744 OrthancPluginContext* context,
3745 const OrthancPluginImage* image)
3746 {
3747 uint32_t pitch;
3748
3749 _OrthancPluginGetImageInfo params;
3750 memset(&params, 0, sizeof(params));
3751 params.image = image;
3752 params.resultUint32 = &pitch;
3753
3754 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, &params) != OrthancPluginErrorCode_Success)
3755 {
3756 return 0;
3757 }
3758 else
3759 {
3760 return pitch;
3761 }
3762 }
3763
3764
3765
3766 /**
3767 * @brief Return a pointer to the content of an image.
3768 *
3769 * This function returns a pointer to the memory buffer that
3770 * contains the pixels of the image.
3771 *
3772 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3773 * @param image The image of interest.
3774 * @return The pointer.
3775 * @ingroup Images
3776 **/
3777 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer(
3778 OrthancPluginContext* context,
3779 const OrthancPluginImage* image)
3780 {
3781 void* target = NULL;
3782
3783 _OrthancPluginGetImageInfo params;
3784 memset(&params, 0, sizeof(params));
3785 params.resultBuffer = &target;
3786 params.image = image;
3787
3788 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, &params) != OrthancPluginErrorCode_Success)
3789 {
3790 return NULL;
3791 }
3792 else
3793 {
3794 return target;
3795 }
3796 }
3797
3798
3799 typedef struct
3800 {
3801 OrthancPluginImage** target;
3802 const void* data;
3803 uint32_t size;
3804 OrthancPluginImageFormat format;
3805 } _OrthancPluginUncompressImage;
3806
3807
3808 /**
3809 * @brief Decode a compressed image.
3810 *
3811 * This function decodes a compressed image from a memory buffer.
3812 *
3813 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3814 * @param data Pointer to a memory buffer containing the compressed image.
3815 * @param size Size of the memory buffer containing the compressed image.
3816 * @param format The file format of the compressed image.
3817 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
3818 * @ingroup Images
3819 **/
3820 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage(
3821 OrthancPluginContext* context,
3822 const void* data,
3823 uint32_t size,
3824 OrthancPluginImageFormat format)
3825 {
3826 OrthancPluginImage* target = NULL;
3827
3828 _OrthancPluginUncompressImage params;
3829 memset(&params, 0, sizeof(params));
3830 params.target = &target;
3831 params.data = data;
3832 params.size = size;
3833 params.format = format;
3834
3835 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, &params) != OrthancPluginErrorCode_Success)
3836 {
3837 return NULL;
3838 }
3839 else
3840 {
3841 return target;
3842 }
3843 }
3844
3845
3846
3847
3848 typedef struct
3849 {
3850 OrthancPluginImage* image;
3851 } _OrthancPluginFreeImage;
3852
3853 /**
3854 * @brief Free an image.
3855 *
3856 * This function frees an image that was decoded with OrthancPluginUncompressImage().
3857 *
3858 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3859 * @param image The image.
3860 * @ingroup Images
3861 **/
3862 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage(
3863 OrthancPluginContext* context,
3864 OrthancPluginImage* image)
3865 {
3866 _OrthancPluginFreeImage params;
3867 params.image = image;
3868
3869 context->InvokeService(context, _OrthancPluginService_FreeImage, &params);
3870 }
3871
3872
3873
3874
3875 typedef struct
3876 {
3877 OrthancPluginMemoryBuffer* target;
3878 OrthancPluginImageFormat imageFormat;
3879 OrthancPluginPixelFormat pixelFormat;
3880 uint32_t width;
3881 uint32_t height;
3882 uint32_t pitch;
3883 const void* buffer;
3884 uint8_t quality;
3885 } _OrthancPluginCompressImage;
3886
3887
3888 /**
3889 * @brief Encode a PNG image.
3890 *
3891 * This function compresses the given memory buffer containing an
3892 * image using the PNG specification, and stores the result of the
3893 * compression into a newly allocated memory buffer.
3894 *
3895 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3896 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3897 * @param format The memory layout of the uncompressed image.
3898 * @param width The width of the image.
3899 * @param height The height of the image.
3900 * @param pitch The pitch of the image (i.e. the number of bytes
3901 * between 2 successive lines of the image in the memory buffer).
3902 * @param buffer The memory buffer containing the uncompressed image.
3903 * @return 0 if success, or the error code if failure.
3904 * @see OrthancPluginCompressAndAnswerPngImage()
3905 * @ingroup Images
3906 **/
3907 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage(
3908 OrthancPluginContext* context,
3909 OrthancPluginMemoryBuffer* target,
3910 OrthancPluginPixelFormat format,
3911 uint32_t width,
3912 uint32_t height,
3913 uint32_t pitch,
3914 const void* buffer)
3915 {
3916 _OrthancPluginCompressImage params;
3917 memset(&params, 0, sizeof(params));
3918 params.target = target;
3919 params.imageFormat = OrthancPluginImageFormat_Png;
3920 params.pixelFormat = format;
3921 params.width = width;
3922 params.height = height;
3923 params.pitch = pitch;
3924 params.buffer = buffer;
3925 params.quality = 0; /* Unused for PNG */
3926
3927 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
3928 }
3929
3930
3931 /**
3932 * @brief Encode a JPEG image.
3933 *
3934 * This function compresses the given memory buffer containing an
3935 * image using the JPEG specification, and stores the result of the
3936 * compression into a newly allocated memory buffer.
3937 *
3938 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3939 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3940 * @param format The memory layout of the uncompressed image.
3941 * @param width The width of the image.
3942 * @param height The height of the image.
3943 * @param pitch The pitch of the image (i.e. the number of bytes
3944 * between 2 successive lines of the image in the memory buffer).
3945 * @param buffer The memory buffer containing the uncompressed image.
3946 * @param quality The quality of the JPEG encoding, between 1 (worst
3947 * quality, best compression) and 100 (best quality, worst
3948 * compression).
3949 * @return 0 if success, or the error code if failure.
3950 * @ingroup Images
3951 **/
3952 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage(
3953 OrthancPluginContext* context,
3954 OrthancPluginMemoryBuffer* target,
3955 OrthancPluginPixelFormat format,
3956 uint32_t width,
3957 uint32_t height,
3958 uint32_t pitch,
3959 const void* buffer,
3960 uint8_t quality)
3961 {
3962 _OrthancPluginCompressImage params;
3963 memset(&params, 0, sizeof(params));
3964 params.target = target;
3965 params.imageFormat = OrthancPluginImageFormat_Jpeg;
3966 params.pixelFormat = format;
3967 params.width = width;
3968 params.height = height;
3969 params.pitch = pitch;
3970 params.buffer = buffer;
3971 params.quality = quality;
3972
3973 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
3974 }
3975
3976
3977
3978 /**
3979 * @brief Answer to a REST request with a JPEG image.
3980 *
3981 * This function answers to a REST request with a JPEG image. The
3982 * parameters of this function describe a memory buffer that
3983 * contains an uncompressed image. The image will be automatically compressed
3984 * as a JPEG image by the core system of Orthanc.
3985 *
3986 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3987 * @param output The HTTP connection to the client application.
3988 * @param format The memory layout of the uncompressed image.
3989 * @param width The width of the image.
3990 * @param height The height of the image.
3991 * @param pitch The pitch of the image (i.e. the number of bytes
3992 * between 2 successive lines of the image in the memory buffer).
3993 * @param buffer The memory buffer containing the uncompressed image.
3994 * @param quality The quality of the JPEG encoding, between 1 (worst
3995 * quality, best compression) and 100 (best quality, worst
3996 * compression).
3997 * @ingroup REST
3998 **/
3999 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage(
4000 OrthancPluginContext* context,
4001 OrthancPluginRestOutput* output,
4002 OrthancPluginPixelFormat format,
4003 uint32_t width,
4004 uint32_t height,
4005 uint32_t pitch,
4006 const void* buffer,
4007 uint8_t quality)
4008 {
4009 _OrthancPluginCompressAndAnswerImage params;
4010 params.output = output;
4011 params.imageFormat = OrthancPluginImageFormat_Jpeg;
4012 params.pixelFormat = format;
4013 params.width = width;
4014 params.height = height;
4015 params.pitch = pitch;
4016 params.buffer = buffer;
4017 params.quality = quality;
4018 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
4019 }
4020
4021
4022
4023
4024 typedef struct
4025 {
4026 OrthancPluginMemoryBuffer* target;
4027 OrthancPluginHttpMethod method;
4028 const char* url;
4029 const char* username;
4030 const char* password;
4031 const char* body;
4032 uint32_t bodySize;
4033 } _OrthancPluginCallHttpClient;
4034
4035
4036 /**
4037 * @brief Issue a HTTP GET call.
4038 *
4039 * Make a HTTP GET call to the given URL. The result to the query is
4040 * stored into a newly allocated memory buffer. Favor
4041 * OrthancPluginRestApiGet() if calling the built-in REST API of the
4042 * Orthanc instance that hosts this plugin.
4043 *
4044 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4045 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4046 * @param url The URL of interest.
4047 * @param username The username (can be <tt>NULL</tt> if no password protection).
4048 * @param password The password (can be <tt>NULL</tt> if no password protection).
4049 * @return 0 if success, or the error code if failure.
4050 **/
4051 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet(
4052 OrthancPluginContext* context,
4053 OrthancPluginMemoryBuffer* target,
4054 const char* url,
4055 const char* username,
4056 const char* password)
4057 {
4058 _OrthancPluginCallHttpClient params;
4059 memset(&params, 0, sizeof(params));
4060
4061 params.target = target;
4062 params.method = OrthancPluginHttpMethod_Get;
4063 params.url = url;
4064 params.username = username;
4065 params.password = password;
4066
4067 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4068 }
4069
4070
4071 /**
4072 * @brief Issue a HTTP POST call.
4073 *
4074 * Make a HTTP POST call to the given URL. The result to the query
4075 * is stored into a newly allocated memory buffer. Favor
4076 * OrthancPluginRestApiPost() if calling the built-in REST API of
4077 * the Orthanc instance that hosts this plugin.
4078 *
4079 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4080 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4081 * @param url The URL of interest.
4082 * @param body The content of the body of the request.
4083 * @param bodySize The size of the body of the request.
4084 * @param username The username (can be <tt>NULL</tt> if no password protection).
4085 * @param password The password (can be <tt>NULL</tt> if no password protection).
4086 * @return 0 if success, or the error code if failure.
4087 **/
4088 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost(
4089 OrthancPluginContext* context,
4090 OrthancPluginMemoryBuffer* target,
4091 const char* url,
4092 const char* body,
4093 uint32_t bodySize,
4094 const char* username,
4095 const char* password)
4096 {
4097 _OrthancPluginCallHttpClient params;
4098 memset(&params, 0, sizeof(params));
4099
4100 params.target = target;
4101 params.method = OrthancPluginHttpMethod_Post;
4102 params.url = url;
4103 params.body = body;
4104 params.bodySize = bodySize;
4105 params.username = username;
4106 params.password = password;
4107
4108 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4109 }
4110
4111
4112 /**
4113 * @brief Issue a HTTP PUT call.
4114 *
4115 * Make a HTTP PUT call to the given URL. The result to the query is
4116 * stored into a newly allocated memory buffer. Favor
4117 * OrthancPluginRestApiPut() if calling the built-in REST API of the
4118 * Orthanc instance that hosts this plugin.
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 url The URL of interest.
4123 * @param body The content of the body of the request.
4124 * @param bodySize The size of the body of the request.
4125 * @param username The username (can be <tt>NULL</tt> if no password protection).
4126 * @param password The password (can be <tt>NULL</tt> if no password protection).
4127 * @return 0 if success, or the error code if failure.
4128 **/
4129 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut(
4130 OrthancPluginContext* context,
4131 OrthancPluginMemoryBuffer* target,
4132 const char* url,
4133 const char* body,
4134 uint32_t bodySize,
4135 const char* username,
4136 const char* password)
4137 {
4138 _OrthancPluginCallHttpClient params;
4139 memset(&params, 0, sizeof(params));
4140
4141 params.target = target;
4142 params.method = OrthancPluginHttpMethod_Put;
4143 params.url = url;
4144 params.body = body;
4145 params.bodySize = bodySize;
4146 params.username = username;
4147 params.password = password;
4148
4149 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4150 }
4151
4152
4153 /**
4154 * @brief Issue a HTTP DELETE call.
4155 *
4156 * Make a HTTP DELETE call to the given URL. Favor
4157 * OrthancPluginRestApiDelete() if calling the built-in REST API of
4158 * the Orthanc instance that hosts this plugin.
4159 *
4160 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4161 * @param url The URL of interest.
4162 * @param username The username (can be <tt>NULL</tt> if no password protection).
4163 * @param password The password (can be <tt>NULL</tt> if no password protection).
4164 * @return 0 if success, or the error code if failure.
4165 **/
4166 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete(
4167 OrthancPluginContext* context,
4168 const char* url,
4169 const char* username,
4170 const char* password)
4171 {
4172 _OrthancPluginCallHttpClient params;
4173 memset(&params, 0, sizeof(params));
4174
4175 params.method = OrthancPluginHttpMethod_Delete;
4176 params.url = url;
4177 params.username = username;
4178 params.password = password;
4179
4180 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4181 }
4182
4183
4184
4185 typedef struct
4186 {
4187 OrthancPluginImage** target;
4188 const OrthancPluginImage* source;
4189 OrthancPluginPixelFormat targetFormat;
4190 } _OrthancPluginConvertPixelFormat;
4191
4192
4193 /**
4194 * @brief Change the pixel format of an image.
4195 *
4196 * This function creates a new image, changing the memory layout of the pixels.
4197 *
4198 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4199 * @param source The source image.
4200 * @param targetFormat The target pixel format.
4201 * @return The resulting image. It must be freed with OrthancPluginFreeImage().
4202 * @ingroup Images
4203 **/
4204 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat(
4205 OrthancPluginContext* context,
4206 const OrthancPluginImage* source,
4207 OrthancPluginPixelFormat targetFormat)
4208 {
4209 OrthancPluginImage* target = NULL;
4210
4211 _OrthancPluginConvertPixelFormat params;
4212 params.target = &target;
4213 params.source = source;
4214 params.targetFormat = targetFormat;
4215
4216 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, &params) != OrthancPluginErrorCode_Success)
4217 {
4218 return NULL;
4219 }
4220 else
4221 {
4222 return target;
4223 }
4224 }
4225
4226
4227
4228 /**
4229 * @brief Return the number of available fonts.
4230 *
4231 * This function returns the number of fonts that are built in the
4232 * Orthanc core. These fonts can be used to draw texts on images
4233 * through OrthancPluginDrawText().
4234 *
4235 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4236 * @return The number of fonts.
4237 * @ingroup Images
4238 **/
4239 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount(
4240 OrthancPluginContext* context)
4241 {
4242 uint32_t count = 0;
4243
4244 _OrthancPluginReturnSingleValue params;
4245 memset(&params, 0, sizeof(params));
4246 params.resultUint32 = &count;
4247
4248 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, &params) != OrthancPluginErrorCode_Success)
4249 {
4250 /* Error */
4251 return 0;
4252 }
4253 else
4254 {
4255 return count;
4256 }
4257 }
4258
4259
4260
4261
4262 typedef struct
4263 {
4264 uint32_t fontIndex; /* in */
4265 const char** name; /* out */
4266 uint32_t* size; /* out */
4267 } _OrthancPluginGetFontInfo;
4268
4269 /**
4270 * @brief Return the name of a font.
4271 *
4272 * This function returns the name of a font that is built in the Orthanc core.
4273 *
4274 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4275 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4276 * @return The font name. This is a statically-allocated string, do not free it.
4277 * @ingroup Images
4278 **/
4279 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName(
4280 OrthancPluginContext* context,
4281 uint32_t fontIndex)
4282 {
4283 const char* result = NULL;
4284
4285 _OrthancPluginGetFontInfo params;
4286 memset(&params, 0, sizeof(params));
4287 params.name = &result;
4288 params.fontIndex = fontIndex;
4289
4290 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4291 {
4292 return NULL;
4293 }
4294 else
4295 {
4296 return result;
4297 }
4298 }
4299
4300
4301 /**
4302 * @brief Return the size of a font.
4303 *
4304 * This function returns the size of a font that is built in the Orthanc core.
4305 *
4306 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4307 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4308 * @return The font size.
4309 * @ingroup Images
4310 **/
4311 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize(
4312 OrthancPluginContext* context,
4313 uint32_t fontIndex)
4314 {
4315 uint32_t result;
4316
4317 _OrthancPluginGetFontInfo params;
4318 memset(&params, 0, sizeof(params));
4319 params.size = &result;
4320 params.fontIndex = fontIndex;
4321
4322 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4323 {
4324 return 0;
4325 }
4326 else
4327 {
4328 return result;
4329 }
4330 }
4331
4332
4333
4334 typedef struct
4335 {
4336 OrthancPluginImage* image;
4337 uint32_t fontIndex;
4338 const char* utf8Text;
4339 int32_t x;
4340 int32_t y;
4341 uint8_t r;
4342 uint8_t g;
4343 uint8_t b;
4344 } _OrthancPluginDrawText;
4345
4346
4347 /**
4348 * @brief Draw text on an image.
4349 *
4350 * This function draws some text on some image.
4351 *
4352 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4353 * @param image The image upon which to draw the text.
4354 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4355 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string.
4356 * @param x The X position of the text over the image.
4357 * @param y The Y position of the text over the image.
4358 * @param r The value of the red color channel of the text.
4359 * @param g The value of the green color channel of the text.
4360 * @param b The value of the blue color channel of the text.
4361 * @return 0 if success, other value if error.
4362 * @ingroup Images
4363 **/
4364 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText(
4365 OrthancPluginContext* context,
4366 OrthancPluginImage* image,
4367 uint32_t fontIndex,
4368 const char* utf8Text,
4369 int32_t x,
4370 int32_t y,
4371 uint8_t r,
4372 uint8_t g,
4373 uint8_t b)
4374 {
4375 _OrthancPluginDrawText params;
4376 memset(&params, 0, sizeof(params));
4377 params.image = image;
4378 params.fontIndex = fontIndex;
4379 params.utf8Text = utf8Text;
4380 params.x = x;
4381 params.y = y;
4382 params.r = r;
4383 params.g = g;
4384 params.b = b;
4385
4386 return context->InvokeService(context, _OrthancPluginService_DrawText, &params);
4387 }
4388
4389
4390
4391 typedef struct
4392 {
4393 OrthancPluginStorageArea* storageArea;
4394 const char* uuid;
4395 const void* content;
4396 uint64_t size;
4397 OrthancPluginContentType type;
4398 } _OrthancPluginStorageAreaCreate;
4399
4400
4401 /**
4402 * @brief Create a file inside the storage area.
4403 *
4404 * This function creates a new file inside the storage area that is
4405 * currently used by Orthanc.
4406 *
4407 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4408 * @param storageArea The storage area.
4409 * @param uuid The identifier of the file to be created.
4410 * @param content The content to store in the newly created file.
4411 * @param size The size of the content.
4412 * @param type The type of the file content.
4413 * @return 0 if success, other value if error.
4414 * @ingroup Callbacks
4415 **/
4416 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate(
4417 OrthancPluginContext* context,
4418 OrthancPluginStorageArea* storageArea,
4419 const char* uuid,
4420 const void* content,
4421 uint64_t size,
4422 OrthancPluginContentType type)
4423 {
4424 _OrthancPluginStorageAreaCreate params;
4425 params.storageArea = storageArea;
4426 params.uuid = uuid;
4427 params.content = content;
4428 params.size = size;
4429 params.type = type;
4430
4431 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, &params);
4432 }
4433
4434
4435 typedef struct
4436 {
4437 OrthancPluginMemoryBuffer* target;
4438 OrthancPluginStorageArea* storageArea;
4439 const char* uuid;
4440 OrthancPluginContentType type;
4441 } _OrthancPluginStorageAreaRead;
4442
4443
4444 /**
4445 * @brief Read a file from the storage area.
4446 *
4447 * This function reads the content of a given file from the storage
4448 * area that is currently used by Orthanc.
4449 *
4450 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4451 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4452 * @param storageArea The storage area.
4453 * @param uuid The identifier of the file to be read.
4454 * @param type The type of the file content.
4455 * @return 0 if success, other value if error.
4456 * @ingroup Callbacks
4457 **/
4458 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead(
4459 OrthancPluginContext* context,
4460 OrthancPluginMemoryBuffer* target,
4461 OrthancPluginStorageArea* storageArea,
4462 const char* uuid,
4463 OrthancPluginContentType type)
4464 {
4465 _OrthancPluginStorageAreaRead params;
4466 params.target = target;
4467 params.storageArea = storageArea;
4468 params.uuid = uuid;
4469 params.type = type;
4470
4471 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, &params);
4472 }
4473
4474
4475 typedef struct
4476 {
4477 OrthancPluginStorageArea* storageArea;
4478 const char* uuid;
4479 OrthancPluginContentType type;
4480 } _OrthancPluginStorageAreaRemove;
4481
4482 /**
4483 * @brief Remove a file from the storage area.
4484 *
4485 * This function removes a given file from the storage area that is
4486 * currently used by Orthanc.
4487 *
4488 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4489 * @param storageArea The storage area.
4490 * @param uuid The identifier of the file to be removed.
4491 * @param type The type of the file content.
4492 * @return 0 if success, other value if error.
4493 * @ingroup Callbacks
4494 **/
4495 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove(
4496 OrthancPluginContext* context,
4497 OrthancPluginStorageArea* storageArea,
4498 const char* uuid,
4499 OrthancPluginContentType type)
4500 {
4501 _OrthancPluginStorageAreaRemove params;
4502 params.storageArea = storageArea;
4503 params.uuid = uuid;
4504 params.type = type;
4505
4506 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, &params);
4507 }
4508
4509
4510
4511 typedef struct
4512 {
4513 OrthancPluginErrorCode* target;
4514 int32_t code;
4515 uint16_t httpStatus;
4516 const char* message;
4517 } _OrthancPluginRegisterErrorCode;
4518
4519 /**
4520 * @brief Declare a custom error code for this plugin.
4521 *
4522 * This function declares a custom error code that can be generated
4523 * by this plugin. This declaration is used to enrich the body of
4524 * the HTTP answer in the case of an error, and to set the proper
4525 * HTTP status code.
4526 *
4527 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4528 * @param code The error code that is internal to this plugin.
4529 * @param httpStatus The HTTP status corresponding to this error.
4530 * @param message The description of the error.
4531 * @return The error code that has been assigned inside the Orthanc core.
4532 * @ingroup Toolbox
4533 **/
4534 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode(
4535 OrthancPluginContext* context,
4536 int32_t code,
4537 uint16_t httpStatus,
4538 const char* message)
4539 {
4540 OrthancPluginErrorCode target;
4541
4542 _OrthancPluginRegisterErrorCode params;
4543 params.target = &target;
4544 params.code = code;
4545 params.httpStatus = httpStatus;
4546 params.message = message;
4547
4548 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, &params) == OrthancPluginErrorCode_Success)
4549 {
4550 return target;
4551 }
4552 else
4553 {
4554 /* There was an error while assigned the error. Use a generic code. */
4555 return OrthancPluginErrorCode_Plugin;
4556 }
4557 }
4558
4559
4560
4561 typedef struct
4562 {
4563 uint16_t group;
4564 uint16_t element;
4565 OrthancPluginValueRepresentation vr;
4566 const char* name;
4567 uint32_t minMultiplicity;
4568 uint32_t maxMultiplicity;
4569 } _OrthancPluginRegisterDictionaryTag;
4570
4571 /**
4572 * @brief Register a new tag into the DICOM dictionary.
4573 *
4574 * This function declares a new public tag in the dictionary of
4575 * DICOM tags that are known to Orthanc. This function should be
4576 * used in the OrthancPluginInitialize() callback.
4577 *
4578 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4579 * @param group The group of the tag.
4580 * @param element The element of the tag.
4581 * @param vr The value representation of the tag.
4582 * @param name The nickname of the tag.
4583 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4584 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4585 * an arbitrary multiplicity ("<tt>n</tt>").
4586 * @return 0 if success, other value if error.
4587 * @see OrthancPluginRegisterPrivateDictionaryTag()
4588 * @ingroup Toolbox
4589 **/
4590 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag(
4591 OrthancPluginContext* context,
4592 uint16_t group,
4593 uint16_t element,
4594 OrthancPluginValueRepresentation vr,
4595 const char* name,
4596 uint32_t minMultiplicity,
4597 uint32_t maxMultiplicity)
4598 {
4599 _OrthancPluginRegisterDictionaryTag params;
4600 params.group = group;
4601 params.element = element;
4602 params.vr = vr;
4603 params.name = name;
4604 params.minMultiplicity = minMultiplicity;
4605 params.maxMultiplicity = maxMultiplicity;
4606
4607 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, &params);
4608 }
4609
4610
4611
4612 typedef struct
4613 {
4614 uint16_t group;
4615 uint16_t element;
4616 OrthancPluginValueRepresentation vr;
4617 const char* name;
4618 uint32_t minMultiplicity;
4619 uint32_t maxMultiplicity;
4620 const char* privateCreator;
4621 } _OrthancPluginRegisterPrivateDictionaryTag;
4622
4623 /**
4624 * @brief Register a new private tag into the DICOM dictionary.
4625 *
4626 * This function declares a new private tag in the dictionary of
4627 * DICOM tags that are known to Orthanc. This function should be
4628 * used in the OrthancPluginInitialize() callback.
4629 *
4630 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4631 * @param group The group of the tag.
4632 * @param element The element of the tag.
4633 * @param vr The value representation of the tag.
4634 * @param name The nickname of the tag.
4635 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4636 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4637 * an arbitrary multiplicity ("<tt>n</tt>").
4638 * @param privateCreator The private creator of this private tag.
4639 * @return 0 if success, other value if error.
4640 * @see OrthancPluginRegisterDictionaryTag()
4641 * @ingroup Toolbox
4642 **/
4643 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag(
4644 OrthancPluginContext* context,
4645 uint16_t group,
4646 uint16_t element,
4647 OrthancPluginValueRepresentation vr,
4648 const char* name,
4649 uint32_t minMultiplicity,
4650 uint32_t maxMultiplicity,
4651 const char* privateCreator)
4652 {
4653 _OrthancPluginRegisterPrivateDictionaryTag params;
4654 params.group = group;
4655 params.element = element;
4656 params.vr = vr;
4657 params.name = name;
4658 params.minMultiplicity = minMultiplicity;
4659 params.maxMultiplicity = maxMultiplicity;
4660 params.privateCreator = privateCreator;
4661
4662 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, &params);
4663 }
4664
4665
4666
4667 typedef struct
4668 {
4669 OrthancPluginStorageArea* storageArea;
4670 OrthancPluginResourceType level;
4671 } _OrthancPluginReconstructMainDicomTags;
4672
4673 /**
4674 * @brief Reconstruct the main DICOM tags.
4675 *
4676 * This function requests the Orthanc core to reconstruct the main
4677 * DICOM tags of all the resources of the given type. This function
4678 * can only be used as a part of the upgrade of a custom database
4679 * back-end. A database transaction will be automatically setup.
4680 *
4681 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4682 * @param storageArea The storage area.
4683 * @param level The type of the resources of interest.
4684 * @return 0 if success, other value if error.
4685 * @ingroup Callbacks
4686 **/
4687 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags(
4688 OrthancPluginContext* context,
4689 OrthancPluginStorageArea* storageArea,
4690 OrthancPluginResourceType level)
4691 {
4692 _OrthancPluginReconstructMainDicomTags params;
4693 params.level = level;
4694 params.storageArea = storageArea;
4695
4696 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, &params);
4697 }
4698
4699
4700 typedef struct
4701 {
4702 char** result;
4703 const char* instanceId;
4704 const void* buffer;
4705 uint32_t size;
4706 OrthancPluginDicomToJsonFormat format;
4707 OrthancPluginDicomToJsonFlags flags;
4708 uint32_t maxStringLength;
4709 } _OrthancPluginDicomToJson;
4710
4711
4712 /**
4713 * @brief Format a DICOM memory buffer as a JSON string.
4714 *
4715 * This function takes as input a memory buffer containing a DICOM
4716 * file, and outputs a JSON string representing the tags of this
4717 * DICOM file.
4718 *
4719 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4720 * @param buffer The memory buffer containing the DICOM file.
4721 * @param size The size of the memory buffer.
4722 * @param format The output format.
4723 * @param flags Flags governing the output.
4724 * @param maxStringLength The maximum length of a field. Too long fields will
4725 * be output as "null". The 0 value means no maximum length.
4726 * @return The NULL value if the case of an error, or the JSON
4727 * string. This string must be freed by OrthancPluginFreeString().
4728 * @ingroup Toolbox
4729 * @see OrthancPluginDicomInstanceToJson
4730 **/
4731 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson(
4732 OrthancPluginContext* context,
4733 const void* buffer,
4734 uint32_t size,
4735 OrthancPluginDicomToJsonFormat format,
4736 OrthancPluginDicomToJsonFlags flags,
4737 uint32_t maxStringLength)
4738 {
4739 char* result;
4740
4741 _OrthancPluginDicomToJson params;
4742 memset(&params, 0, sizeof(params));
4743 params.result = &result;
4744 params.buffer = buffer;
4745 params.size = size;
4746 params.format = format;
4747 params.flags = flags;
4748 params.maxStringLength = maxStringLength;
4749
4750 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, &params) != OrthancPluginErrorCode_Success)
4751 {
4752 /* Error */
4753 return NULL;
4754 }
4755 else
4756 {
4757 return result;
4758 }
4759 }
4760
4761
4762 /**
4763 * @brief Format a DICOM instance as a JSON string.
4764 *
4765 * This function formats a DICOM instance that is stored in Orthanc,
4766 * and outputs a JSON string representing the tags of this DICOM
4767 * instance.
4768 *
4769 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4770 * @param instanceId The Orthanc identifier of the instance.
4771 * @param format The output format.
4772 * @param flags Flags governing the output.
4773 * @param maxStringLength The maximum length of a field. Too long fields will
4774 * be output as "null". The 0 value means no maximum length.
4775 * @return The NULL value if the case of an error, or the JSON
4776 * string. This string must be freed by OrthancPluginFreeString().
4777 * @ingroup Toolbox
4778 * @see OrthancPluginDicomInstanceToJson
4779 **/
4780 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson(
4781 OrthancPluginContext* context,
4782 const char* instanceId,
4783 OrthancPluginDicomToJsonFormat format,
4784 OrthancPluginDicomToJsonFlags flags,
4785 uint32_t maxStringLength)
4786 {
4787 char* result;
4788
4789 _OrthancPluginDicomToJson params;
4790 memset(&params, 0, sizeof(params));
4791 params.result = &result;
4792 params.instanceId = instanceId;
4793 params.format = format;
4794 params.flags = flags;
4795 params.maxStringLength = maxStringLength;
4796
4797 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, &params) != OrthancPluginErrorCode_Success)
4798 {
4799 /* Error */
4800 return NULL;
4801 }
4802 else
4803 {
4804 return result;
4805 }
4806 }
4807
4808
4809 typedef struct
4810 {
4811 OrthancPluginMemoryBuffer* target;
4812 const char* uri;
4813 uint32_t headersCount;
4814 const char* const* headersKeys;
4815 const char* const* headersValues;
4816 int32_t afterPlugins;
4817 } _OrthancPluginRestApiGet2;
4818
4819 /**
4820 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers.
4821 *
4822 * Make a GET call to the Orthanc REST API with extended
4823 * parameters. The result to the query is stored into a newly
4824 * allocated memory buffer.
4825 *
4826 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4827 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4828 * @param uri The URI in the built-in Orthanc API.
4829 * @param headersCount The number of HTTP headers.
4830 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
4831 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
4832 * @param afterPlugins If 0, the built-in API of Orthanc is used.
4833 * If 1, the API is tainted by the plugins.
4834 * @return 0 if success, or the error code if failure.
4835 * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins
4836 * @ingroup Orthanc
4837 **/
4838 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2(
4839 OrthancPluginContext* context,
4840 OrthancPluginMemoryBuffer* target,
4841 const char* uri,
4842 uint32_t headersCount,
4843 const char* const* headersKeys,
4844 const char* const* headersValues,
4845 int32_t afterPlugins)
4846 {
4847 _OrthancPluginRestApiGet2 params;
4848 params.target = target;
4849 params.uri = uri;
4850 params.headersCount = headersCount;
4851 params.headersKeys = headersKeys;
4852 params.headersValues = headersValues;
4853 params.afterPlugins = afterPlugins;
4854
4855 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, &params);
4856 }
4857
4858
4859
4860 typedef struct
4861 {
4862 OrthancPluginWorklistCallback callback;
4863 } _OrthancPluginWorklistCallback;
4864
4865 /**
4866 * @brief Register a callback to handle modality worklists requests.
4867 *
4868 * This function registers a callback to handle C-Find SCP requests
4869 * on modality worklists.
4870 *
4871 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4872 * @param callback The callback.
4873 * @return 0 if success, other value if error.
4874 * @ingroup DicomCallbacks
4875 **/
4876 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback(
4877 OrthancPluginContext* context,
4878 OrthancPluginWorklistCallback callback)
4879 {
4880 _OrthancPluginWorklistCallback params;
4881 params.callback = callback;
4882
4883 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, &params);
4884 }
4885
4886
4887
4888 typedef struct
4889 {
4890 OrthancPluginWorklistAnswers* answers;
4891 const OrthancPluginWorklistQuery* query;
4892 const void* dicom;
4893 uint32_t size;
4894 } _OrthancPluginWorklistAnswersOperation;
4895
4896 /**
4897 * @brief Add one answer to some modality worklist request.
4898 *
4899 * This function adds one worklist (encoded as a DICOM file) to the
4900 * set of answers corresponding to some C-Find SCP request against
4901 * modality worklists.
4902 *
4903 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4904 * @param answers The set of answers.
4905 * @param query The worklist query, as received by the callback.
4906 * @param dicom The worklist to answer, encoded as a DICOM file.
4907 * @param size The size of the DICOM file.
4908 * @return 0 if success, other value if error.
4909 * @ingroup DicomCallbacks
4910 * @see OrthancPluginCreateDicom()
4911 **/
4912 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer(
4913 OrthancPluginContext* context,
4914 OrthancPluginWorklistAnswers* answers,
4915 const OrthancPluginWorklistQuery* query,
4916 const void* dicom,
4917 uint32_t size)
4918 {
4919 _OrthancPluginWorklistAnswersOperation params;
4920 params.answers = answers;
4921 params.query = query;
4922 params.dicom = dicom;
4923 params.size = size;
4924
4925 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, &params);
4926 }
4927
4928
4929 /**
4930 * @brief Mark the set of worklist answers as incomplete.
4931 *
4932 * This function marks as incomplete the set of answers
4933 * corresponding to some C-Find SCP request against modality
4934 * worklists. This must be used if canceling the handling of a
4935 * request when too many answers are to be returned.
4936 *
4937 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4938 * @param answers The set of answers.
4939 * @return 0 if success, other value if error.
4940 * @ingroup DicomCallbacks
4941 **/
4942 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete(
4943 OrthancPluginContext* context,
4944 OrthancPluginWorklistAnswers* answers)
4945 {
4946 _OrthancPluginWorklistAnswersOperation params;
4947 params.answers = answers;
4948 params.query = NULL;
4949 params.dicom = NULL;
4950 params.size = 0;
4951
4952 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, &params);
4953 }
4954
4955
4956 typedef struct
4957 {
4958 const OrthancPluginWorklistQuery* query;
4959 const void* dicom;
4960 uint32_t size;
4961 int32_t* isMatch;
4962 OrthancPluginMemoryBuffer* target;
4963 } _OrthancPluginWorklistQueryOperation;
4964
4965 /**
4966 * @brief Test whether a worklist matches the query.
4967 *
4968 * This function checks whether one worklist (encoded as a DICOM
4969 * file) matches the C-Find SCP query against modality
4970 * worklists. This function must be called before adding the
4971 * worklist as an answer through OrthancPluginWorklistAddAnswer().
4972 *
4973 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4974 * @param query The worklist query, as received by the callback.
4975 * @param dicom The worklist to answer, encoded as a DICOM file.
4976 * @param size The size of the DICOM file.
4977 * @return 1 if the worklist matches the query, 0 otherwise.
4978 * @ingroup DicomCallbacks
4979 **/
4980 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch(
4981 OrthancPluginContext* context,
4982 const OrthancPluginWorklistQuery* query,
4983 const void* dicom,
4984 uint32_t size)
4985 {
4986 int32_t isMatch = 0;
4987
4988 _OrthancPluginWorklistQueryOperation params;
4989 params.query = query;
4990 params.dicom = dicom;
4991 params.size = size;
4992 params.isMatch = &isMatch;
4993 params.target = NULL;
4994
4995 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, &params) == OrthancPluginErrorCode_Success)
4996 {
4997 return isMatch;
4998 }
4999 else
5000 {
5001 /* Error: Assume non-match */
5002 return 0;
5003 }
5004 }
5005
5006
5007 /**
5008 * @brief Retrieve the worklist query as a DICOM file.
5009 *
5010 * This function retrieves the DICOM file that underlies a C-Find
5011 * SCP query against modality worklists.
5012 *
5013 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5014 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer().
5015 * @param query The worklist query, as received by the callback.
5016 * @return 0 if success, other value if error.
5017 * @ingroup DicomCallbacks
5018 **/
5019 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery(
5020 OrthancPluginContext* context,
5021 OrthancPluginMemoryBuffer* target,
5022 const OrthancPluginWorklistQuery* query)
5023 {
5024 _OrthancPluginWorklistQueryOperation params;
5025 params.query = query;
5026 params.dicom = NULL;
5027 params.size = 0;
5028 params.isMatch = NULL;
5029 params.target = target;
5030
5031 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, &params);
5032 }
5033
5034
5035 /**
5036 * @brief Get the origin of a DICOM file.
5037 *
5038 * This function returns the origin of a DICOM instance that has been received by Orthanc.
5039 *
5040 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5041 * @param instance The instance of interest.
5042 * @return The origin of the instance.
5043 * @ingroup Callbacks
5044 **/
5045 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin(
5046 OrthancPluginContext* context,
5047 OrthancPluginDicomInstance* instance)
5048 {
5049 OrthancPluginInstanceOrigin origin;
5050
5051 _OrthancPluginAccessDicomInstance params;
5052 memset(&params, 0, sizeof(params));
5053 params.resultOrigin = &origin;
5054 params.instance = instance;
5055
5056 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, &params) != OrthancPluginErrorCode_Success)
5057 {
5058 /* Error */
5059 return OrthancPluginInstanceOrigin_Unknown;
5060 }
5061 else
5062 {
5063 return origin;
5064 }
5065 }
5066
5067
5068 typedef struct
5069 {
5070 OrthancPluginMemoryBuffer* target;
5071 const char* json;
5072 const OrthancPluginImage* pixelData;
5073 OrthancPluginCreateDicomFlags flags;
5074 } _OrthancPluginCreateDicom;
5075
5076 /**
5077 * @brief Create a DICOM instance from a JSON string and an image.
5078 *
5079 * This function takes as input a string containing a JSON file
5080 * describing the content of a DICOM instance. As an output, it
5081 * writes the corresponding DICOM instance to a newly allocated
5082 * memory buffer. Additionally, an image to be encoded within the
5083 * DICOM instance can also be provided.
5084 *
5085 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5086 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
5087 * @param json The input JSON file.
5088 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.
5089 * @param flags Flags governing the output.
5090 * @return 0 if success, other value if error.
5091 * @ingroup Toolbox
5092 * @see OrthancPluginDicomBufferToJson
5093 **/
5094 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom(
5095 OrthancPluginContext* context,
5096 OrthancPluginMemoryBuffer* target,
5097 const char* json,
5098 const OrthancPluginImage* pixelData,
5099 OrthancPluginCreateDicomFlags flags)
5100 {
5101 _OrthancPluginCreateDicom params;
5102 params.target = target;
5103 params.json = json;
5104 params.pixelData = pixelData;
5105 params.flags = flags;
5106
5107 return context->InvokeService(context, _OrthancPluginService_CreateDicom, &params);
5108 }
5109
5110
5111 typedef struct
5112 {
5113 OrthancPluginDecodeImageCallback callback;
5114 } _OrthancPluginDecodeImageCallback;
5115
5116 /**
5117 * @brief Register a callback to handle the decoding of DICOM images.
5118 *
5119 * This function registers a custom callback to the decoding of
5120 * DICOM images, replacing the built-in decoder of Orthanc.
5121 *
5122 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5123 * @param callback The callback.
5124 * @return 0 if success, other value if error.
5125 * @ingroup Callbacks
5126 **/
5127 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback(
5128 OrthancPluginContext* context,
5129 OrthancPluginDecodeImageCallback callback)
5130 {
5131 _OrthancPluginDecodeImageCallback params;
5132 params.callback = callback;
5133
5134 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, &params);
5135 }
5136
5137
5138
5139 typedef struct
5140 {
5141 OrthancPluginImage** target;
5142 OrthancPluginPixelFormat format;
5143 uint32_t width;
5144 uint32_t height;
5145 uint32_t pitch;
5146 void* buffer;
5147 const void* constBuffer;
5148 uint32_t bufferSize;
5149 uint32_t frameIndex;
5150 } _OrthancPluginCreateImage;
5151
5152
5153 /**
5154 * @brief Create an image.
5155 *
5156 * This function creates an image of given size and format.
5157 *
5158 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5159 * @param format The format of the pixels.
5160 * @param width The width of the image.
5161 * @param height The height of the image.
5162 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5163 * @ingroup Images
5164 **/
5165 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage(
5166 OrthancPluginContext* context,
5167 OrthancPluginPixelFormat format,
5168 uint32_t width,
5169 uint32_t height)
5170 {
5171 OrthancPluginImage* target = NULL;
5172
5173 _OrthancPluginCreateImage params;
5174 memset(&params, 0, sizeof(params));
5175 params.target = &target;
5176 params.format = format;
5177 params.width = width;
5178 params.height = height;
5179
5180 if (context->InvokeService(context, _OrthancPluginService_CreateImage, &params) != OrthancPluginErrorCode_Success)
5181 {
5182 return NULL;
5183 }
5184 else
5185 {
5186 return target;
5187 }
5188 }
5189
5190
5191 /**
5192 * @brief Create an image pointing to a memory buffer.
5193 *
5194 * This function creates an image whose content points to a memory
5195 * buffer managed by the plugin. Note that the buffer is directly
5196 * accessed, no memory is allocated and no data is copied.
5197 *
5198 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5199 * @param format The format of the pixels.
5200 * @param width The width of the image.
5201 * @param height The height of the image.
5202 * @param pitch The pitch of the image (i.e. the number of bytes
5203 * between 2 successive lines of the image in the memory buffer).
5204 * @param buffer The memory buffer.
5205 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5206 * @ingroup Images
5207 **/
5208 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor(
5209 OrthancPluginContext* context,
5210 OrthancPluginPixelFormat format,
5211 uint32_t width,
5212 uint32_t height,
5213 uint32_t pitch,
5214 void* buffer)
5215 {
5216 OrthancPluginImage* target = NULL;
5217
5218 _OrthancPluginCreateImage params;
5219 memset(&params, 0, sizeof(params));
5220 params.target = &target;
5221 params.format = format;
5222 params.width = width;
5223 params.height = height;
5224 params.pitch = pitch;
5225 params.buffer = buffer;
5226
5227 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, &params) != OrthancPluginErrorCode_Success)
5228 {
5229 return NULL;
5230 }
5231 else
5232 {
5233 return target;
5234 }
5235 }
5236
5237
5238
5239 /**
5240 * @brief Decode one frame from a DICOM instance.
5241 *
5242 * This function decodes one frame of a DICOM image that is stored
5243 * in a memory buffer. This function will give the same result as
5244 * OrthancPluginUncompressImage() for single-frame DICOM images.
5245 *
5246 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5247 * @param buffer Pointer to a memory buffer containing the DICOM image.
5248 * @param bufferSize Size of the memory buffer containing the DICOM image.
5249 * @param frameIndex The index of the frame of interest in a multi-frame image.
5250 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
5251 * @ingroup Images
5252 **/
5253 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage(
5254 OrthancPluginContext* context,
5255 const void* buffer,
5256 uint32_t bufferSize,
5257 uint32_t frameIndex)
5258 {
5259 OrthancPluginImage* target = NULL;
5260
5261 _OrthancPluginCreateImage params;
5262 memset(&params, 0, sizeof(params));
5263 params.target = &target;
5264 params.constBuffer = buffer;
5265 params.bufferSize = bufferSize;
5266 params.frameIndex = frameIndex;
5267
5268 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, &params) != OrthancPluginErrorCode_Success)
5269 {
5270 return NULL;
5271 }
5272 else
5273 {
5274 return target;
5275 }
5276 }
5277
5278
5279
5280 typedef struct
5281 {
5282 char** result;
5283 const void* buffer;
5284 uint32_t size;
5285 } _OrthancPluginComputeHash;
5286
5287 /**
5288 * @brief Compute an MD5 hash.
5289 *
5290 * This functions computes the MD5 cryptographic hash of the given memory buffer.
5291 *
5292 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5293 * @param buffer The source memory buffer.
5294 * @param size The size in bytes of the source buffer.
5295 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5296 * This string must be freed by OrthancPluginFreeString().
5297 * @ingroup Toolbox
5298 **/
5299 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5(
5300 OrthancPluginContext* context,
5301 const void* buffer,
5302 uint32_t size)
5303 {
5304 char* result;
5305
5306 _OrthancPluginComputeHash params;
5307 params.result = &result;
5308 params.buffer = buffer;
5309 params.size = size;
5310
5311 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, &params) != OrthancPluginErrorCode_Success)
5312 {
5313 /* Error */
5314 return NULL;
5315 }
5316 else
5317 {
5318 return result;
5319 }
5320 }
5321
5322
5323 /**
5324 * @brief Compute a SHA-1 hash.
5325 *
5326 * This functions computes the SHA-1 cryptographic hash of the given memory buffer.
5327 *
5328 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5329 * @param buffer The source memory buffer.
5330 * @param size The size in bytes of the source buffer.
5331 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5332 * This string must be freed by OrthancPluginFreeString().
5333 * @ingroup Toolbox
5334 **/
5335 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1(
5336 OrthancPluginContext* context,
5337 const void* buffer,
5338 uint32_t size)
5339 {
5340 char* result;
5341
5342 _OrthancPluginComputeHash params;
5343 params.result = &result;
5344 params.buffer = buffer;
5345 params.size = size;
5346
5347 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, &params) != OrthancPluginErrorCode_Success)
5348 {
5349 /* Error */
5350 return NULL;
5351 }
5352 else
5353 {
5354 return result;
5355 }
5356 }
5357
5358
5359
5360 typedef struct
5361 {
5362 OrthancPluginDictionaryEntry* target;
5363 const char* name;
5364 } _OrthancPluginLookupDictionary;
5365
5366 /**
5367 * @brief Get information about the given DICOM tag.
5368 *
5369 * This functions makes a lookup in the dictionary of DICOM tags
5370 * that are known to Orthanc, and returns information about this
5371 * tag. The tag can be specified using its human-readable name
5372 * (e.g. "PatientName") or a set of two hexadecimal numbers
5373 * (e.g. "0010-0020").
5374 *
5375 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5376 * @param target Where to store the information about the tag.
5377 * @param name The name of the DICOM tag.
5378 * @return 0 if success, other value if error.
5379 * @ingroup Toolbox
5380 **/
5381 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary(
5382 OrthancPluginContext* context,
5383 OrthancPluginDictionaryEntry* target,
5384 const char* name)
5385 {
5386 _OrthancPluginLookupDictionary params;
5387 params.target = target;
5388 params.name = name;
5389 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, &params);
5390 }
5391
5392
5393
5394 typedef struct
5395 {
5396 OrthancPluginRestOutput* output;
5397 const char* answer;
5398 uint32_t answerSize;
5399 uint32_t headersCount;
5400 const char* const* headersKeys;
5401 const char* const* headersValues;
5402 } _OrthancPluginSendMultipartItem2;
5403
5404 /**
5405 * @brief Send an item as a part of some HTTP multipart answer, with custom headers.
5406 *
5407 * This function sends an item as a part of some HTTP multipart
5408 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to
5409 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated
5410 * with the item.
5411 *
5412 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5413 * @param output The HTTP connection to the client application.
5414 * @param answer Pointer to the memory buffer containing the item.
5415 * @param answerSize Number of bytes of the item.
5416 * @param headersCount The number of HTTP headers.
5417 * @param headersKeys Array containing the keys of the HTTP headers.
5418 * @param headersValues Array containing the values of the HTTP headers.
5419 * @return 0 if success, or the error code if failure (this notably happens
5420 * if the connection is closed by the client).
5421 * @see OrthancPluginSendMultipartItem()
5422 * @ingroup REST
5423 **/
5424 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2(
5425 OrthancPluginContext* context,
5426 OrthancPluginRestOutput* output,
5427 const char* answer,
5428 uint32_t answerSize,
5429 uint32_t headersCount,
5430 const char* const* headersKeys,
5431 const char* const* headersValues)
5432 {
5433 _OrthancPluginSendMultipartItem2 params;
5434 params.output = output;
5435 params.answer = answer;
5436 params.answerSize = answerSize;
5437 params.headersCount = headersCount;
5438 params.headersKeys = headersKeys;
5439 params.headersValues = headersValues;
5440
5441 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, &params);
5442 }
5443
5444
5445 typedef struct
5446 {
5447 OrthancPluginIncomingHttpRequestFilter callback;
5448 } _OrthancPluginIncomingHttpRequestFilter;
5449
5450 /**
5451 * @brief Register a callback to filter incoming HTTP requests.
5452 *
5453 * This function registers a custom callback to filter incoming HTTP/REST
5454 * requests received by the HTTP server of Orthanc.
5455 *
5456 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5457 * @param callback The callback.
5458 * @return 0 if success, other value if error.
5459 * @ingroup Callbacks
5460 * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2()
5461 **/
5462 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter(
5463 OrthancPluginContext* context,
5464 OrthancPluginIncomingHttpRequestFilter callback)
5465 {
5466 _OrthancPluginIncomingHttpRequestFilter params;
5467 params.callback = callback;
5468
5469 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, &params);
5470 }
5471
5472
5473
5474 typedef struct
5475 {
5476 OrthancPluginMemoryBuffer* answerBody;
5477 OrthancPluginMemoryBuffer* answerHeaders;
5478 uint16_t* httpStatus;
5479 OrthancPluginHttpMethod method;
5480 const char* url;
5481 uint32_t headersCount;
5482 const char* const* headersKeys;
5483 const char* const* headersValues;
5484 const char* body;
5485 uint32_t bodySize;
5486 const char* username;
5487 const char* password;
5488 uint32_t timeout;
5489 const char* certificateFile;
5490 const char* certificateKeyFile;
5491 const char* certificateKeyPassword;
5492 uint8_t pkcs11;
5493 } _OrthancPluginCallHttpClient2;
5494
5495
5496
5497 /**
5498 * @brief Issue a HTTP call with full flexibility.
5499 *
5500 * Make a HTTP call to the given URL. The result to the query is
5501 * stored into a newly allocated memory buffer. The HTTP request
5502 * will be done accordingly to the global configuration of Orthanc
5503 * (in particular, the options "HttpProxy", "HttpTimeout",
5504 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be
5505 * taken into account).
5506 *
5507 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5508 * @param answerBody The target memory buffer (out argument).
5509 * It must be freed with OrthancPluginFreeMemoryBuffer().
5510 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
5511 * The answer headers are formatted as a JSON object (associative array).
5512 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
5513 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
5514 * @param httpStatus The HTTP status after the execution of the request (out argument).
5515 * @param method HTTP method to be used.
5516 * @param url The URL of interest.
5517 * @param headersCount The number of HTTP headers.
5518 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
5519 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
5520 * @param username The username (can be <tt>NULL</tt> if no password protection).
5521 * @param password The password (can be <tt>NULL</tt> if no password protection).
5522 * @param body The HTTP body for a POST or PUT request.
5523 * @param bodySize The size of the body.
5524 * @param timeout Timeout in seconds (0 for default timeout).
5525 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
5526 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5527 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
5528 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5529 * @param certificateKeyPassword Password to unlock the key of the client certificate
5530 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5531 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
5532 * @return 0 if success, or the error code if failure.
5533 * @see OrthancPluginCallPeerApi()
5534 **/
5535 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient(
5536 OrthancPluginContext* context,
5537 OrthancPluginMemoryBuffer* answerBody,
5538 OrthancPluginMemoryBuffer* answerHeaders,
5539 uint16_t* httpStatus,
5540 OrthancPluginHttpMethod method,
5541 const char* url,
5542 uint32_t headersCount,
5543 const char* const* headersKeys,
5544 const char* const* headersValues,
5545 const char* body,
5546 uint32_t bodySize,
5547 const char* username,
5548 const char* password,
5549 uint32_t timeout,
5550 const char* certificateFile,
5551 const char* certificateKeyFile,
5552 const char* certificateKeyPassword,
5553 uint8_t pkcs11)
5554 {
5555 _OrthancPluginCallHttpClient2 params;
5556 memset(&params, 0, sizeof(params));
5557
5558 params.answerBody = answerBody;
5559 params.answerHeaders = answerHeaders;
5560 params.httpStatus = httpStatus;
5561 params.method = method;
5562 params.url = url;
5563 params.headersCount = headersCount;
5564 params.headersKeys = headersKeys;
5565 params.headersValues = headersValues;
5566 params.body = body;
5567 params.bodySize = bodySize;
5568 params.username = username;
5569 params.password = password;
5570 params.timeout = timeout;
5571 params.certificateFile = certificateFile;
5572 params.certificateKeyFile = certificateKeyFile;
5573 params.certificateKeyPassword = certificateKeyPassword;
5574 params.pkcs11 = pkcs11;
5575
5576 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, &params);
5577 }
5578
5579
5580 /**
5581 * @brief Generate an UUID.
5582 *
5583 * Generate a random GUID/UUID (globally unique identifier).
5584 *
5585 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5586 * @return NULL in the case of an error, or a newly allocated string
5587 * containing the UUID. This string must be freed by OrthancPluginFreeString().
5588 * @ingroup Toolbox
5589 **/
5590 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid(
5591 OrthancPluginContext* context)
5592 {
5593 char* result;
5594
5595 _OrthancPluginRetrieveDynamicString params;
5596 params.result = &result;
5597 params.argument = NULL;
5598
5599 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, &params) != OrthancPluginErrorCode_Success)
5600 {
5601 /* Error */
5602 return NULL;
5603 }
5604 else
5605 {
5606 return result;
5607 }
5608 }
5609
5610
5611
5612
5613 typedef struct
5614 {
5615 OrthancPluginFindCallback callback;
5616 } _OrthancPluginFindCallback;
5617
5618 /**
5619 * @brief Register a callback to handle C-Find requests.
5620 *
5621 * This function registers a callback to handle C-Find SCP requests
5622 * that are not related to modality worklists.
5623 *
5624 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5625 * @param callback The callback.
5626 * @return 0 if success, other value if error.
5627 * @ingroup DicomCallbacks
5628 **/
5629 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback(
5630 OrthancPluginContext* context,
5631 OrthancPluginFindCallback callback)
5632 {
5633 _OrthancPluginFindCallback params;
5634 params.callback = callback;
5635
5636 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, &params);
5637 }
5638
5639
5640 typedef struct
5641 {
5642 OrthancPluginFindAnswers *answers;
5643 const OrthancPluginFindQuery *query;
5644 const void *dicom;
5645 uint32_t size;
5646 uint32_t index;
5647 uint32_t *resultUint32;
5648 uint16_t *resultGroup;
5649 uint16_t *resultElement;
5650 char **resultString;
5651 } _OrthancPluginFindOperation;
5652
5653 /**
5654 * @brief Add one answer to some C-Find request.
5655 *
5656 * This function adds one answer (encoded as a DICOM file) to the
5657 * set of answers corresponding to some C-Find SCP request that is
5658 * not related to modality worklists.
5659 *
5660 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5661 * @param answers The set of answers.
5662 * @param dicom The answer to be added, encoded as a DICOM file.
5663 * @param size The size of the DICOM file.
5664 * @return 0 if success, other value if error.
5665 * @ingroup DicomCallbacks
5666 * @see OrthancPluginCreateDicom()
5667 **/
5668 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer(
5669 OrthancPluginContext* context,
5670 OrthancPluginFindAnswers* answers,
5671 const void* dicom,
5672 uint32_t size)
5673 {
5674 _OrthancPluginFindOperation params;
5675 memset(&params, 0, sizeof(params));
5676 params.answers = answers;
5677 params.dicom = dicom;
5678 params.size = size;
5679
5680 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, &params);
5681 }
5682
5683
5684 /**
5685 * @brief Mark the set of C-Find answers as incomplete.
5686 *
5687 * This function marks as incomplete the set of answers
5688 * corresponding to some C-Find SCP request that is not related to
5689 * modality worklists. This must be used if canceling the handling
5690 * of a request when too many answers are to be returned.
5691 *
5692 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5693 * @param answers The set of answers.
5694 * @return 0 if success, other value if error.
5695 * @ingroup DicomCallbacks
5696 **/
5697 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete(
5698 OrthancPluginContext* context,
5699 OrthancPluginFindAnswers* answers)
5700 {
5701 _OrthancPluginFindOperation params;
5702 memset(&params, 0, sizeof(params));
5703 params.answers = answers;
5704
5705 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, &params);
5706 }
5707
5708
5709
5710 /**
5711 * @brief Get the number of tags in a C-Find query.
5712 *
5713 * This function returns the number of tags that are contained in
5714 * the given C-Find query.
5715 *
5716 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5717 * @param query The C-Find query.
5718 * @return The number of tags.
5719 * @ingroup DicomCallbacks
5720 **/
5721 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize(
5722 OrthancPluginContext* context,
5723 const OrthancPluginFindQuery* query)
5724 {
5725 uint32_t count = 0;
5726
5727 _OrthancPluginFindOperation params;
5728 memset(&params, 0, sizeof(params));
5729 params.query = query;
5730 params.resultUint32 = &count;
5731
5732 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, &params) != OrthancPluginErrorCode_Success)
5733 {
5734 /* Error */
5735 return 0;
5736 }
5737 else
5738 {
5739 return count;
5740 }
5741 }
5742
5743
5744 /**
5745 * @brief Get one tag in a C-Find query.
5746 *
5747 * This function returns the group and the element of one DICOM tag
5748 * in the given C-Find query.
5749 *
5750 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5751 * @param group The group of the tag (output).
5752 * @param element The element of the tag (output).
5753 * @param query The C-Find query.
5754 * @param index The index of the tag of interest.
5755 * @return 0 if success, other value if error.
5756 * @ingroup DicomCallbacks
5757 **/
5758 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag(
5759 OrthancPluginContext* context,
5760 uint16_t* group,
5761 uint16_t* element,
5762 const OrthancPluginFindQuery* query,
5763 uint32_t index)
5764 {
5765 _OrthancPluginFindOperation params;
5766 memset(&params, 0, sizeof(params));
5767 params.query = query;
5768 params.index = index;
5769 params.resultGroup = group;
5770 params.resultElement = element;
5771
5772 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, &params);
5773 }
5774
5775
5776 /**
5777 * @brief Get the symbolic name of one tag in a C-Find query.
5778 *
5779 * This function returns the symbolic name of one DICOM tag in the
5780 * given C-Find query.
5781 *
5782 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5783 * @param query The C-Find query.
5784 * @param index The index of the tag of interest.
5785 * @return The NULL value in case of error, or a string containing the name of the tag.
5786 * @return 0 if success, other value if error.
5787 * @ingroup DicomCallbacks
5788 **/
5789 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName(
5790 OrthancPluginContext* context,
5791 const OrthancPluginFindQuery* query,
5792 uint32_t index)
5793 {
5794 char* result;
5795
5796 _OrthancPluginFindOperation params;
5797 memset(&params, 0, sizeof(params));
5798 params.query = query;
5799 params.index = index;
5800 params.resultString = &result;
5801
5802 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, &params) != OrthancPluginErrorCode_Success)
5803 {
5804 /* Error */
5805 return NULL;
5806 }
5807 else
5808 {
5809 return result;
5810 }
5811 }
5812
5813
5814 /**
5815 * @brief Get the value associated with one tag in a C-Find query.
5816 *
5817 * This function returns the value associated with one tag in the
5818 * given C-Find query.
5819 *
5820 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5821 * @param query The C-Find query.
5822 * @param index The index of the tag of interest.
5823 * @return The NULL value in case of error, or a string containing the value of the tag.
5824 * @return 0 if success, other value if error.
5825 * @ingroup DicomCallbacks
5826 **/
5827 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue(
5828 OrthancPluginContext* context,
5829 const OrthancPluginFindQuery* query,
5830 uint32_t index)
5831 {
5832 char* result;
5833
5834 _OrthancPluginFindOperation params;
5835 memset(&params, 0, sizeof(params));
5836 params.query = query;
5837 params.index = index;
5838 params.resultString = &result;
5839
5840 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, &params) != OrthancPluginErrorCode_Success)
5841 {
5842 /* Error */
5843 return NULL;
5844 }
5845 else
5846 {
5847 return result;
5848 }
5849 }
5850
5851
5852
5853
5854 typedef struct
5855 {
5856 OrthancPluginMoveCallback callback;
5857 OrthancPluginGetMoveSize getMoveSize;
5858 OrthancPluginApplyMove applyMove;
5859 OrthancPluginFreeMove freeMove;
5860 } _OrthancPluginMoveCallback;
5861
5862 /**
5863 * @brief Register a callback to handle C-Move requests.
5864 *
5865 * This function registers a callback to handle C-Move SCP requests.
5866 *
5867 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5868 * @param callback The main callback.
5869 * @param getMoveSize Callback to read the number of C-Move suboperations.
5870 * @param applyMove Callback to apply one C-Move suboperations.
5871 * @param freeMove Callback to free the C-Move driver.
5872 * @return 0 if success, other value if error.
5873 * @ingroup DicomCallbacks
5874 **/
5875 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback(
5876 OrthancPluginContext* context,
5877 OrthancPluginMoveCallback callback,
5878 OrthancPluginGetMoveSize getMoveSize,
5879 OrthancPluginApplyMove applyMove,
5880 OrthancPluginFreeMove freeMove)
5881 {
5882 _OrthancPluginMoveCallback params;
5883 params.callback = callback;
5884 params.getMoveSize = getMoveSize;
5885 params.applyMove = applyMove;
5886 params.freeMove = freeMove;
5887
5888 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, &params);
5889 }
5890
5891
5892
5893 typedef struct
5894 {
5895 OrthancPluginFindMatcher** target;
5896 const void* query;
5897 uint32_t size;
5898 } _OrthancPluginCreateFindMatcher;
5899
5900
5901 /**
5902 * @brief Create a C-Find matcher.
5903 *
5904 * This function creates a "matcher" object that can be used to
5905 * check whether a DICOM instance matches a C-Find query. The C-Find
5906 * query must be expressed as a DICOM buffer.
5907 *
5908 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5909 * @param query The C-Find DICOM query.
5910 * @param size The size of the DICOM query.
5911 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher().
5912 * @ingroup Toolbox
5913 **/
5914 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher(
5915 OrthancPluginContext* context,
5916 const void* query,
5917 uint32_t size)
5918 {
5919 OrthancPluginFindMatcher* target = NULL;
5920
5921 _OrthancPluginCreateFindMatcher params;
5922 memset(&params, 0, sizeof(params));
5923 params.target = &target;
5924 params.query = query;
5925 params.size = size;
5926
5927 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, &params) != OrthancPluginErrorCode_Success)
5928 {
5929 return NULL;
5930 }
5931 else
5932 {
5933 return target;
5934 }
5935 }
5936
5937
5938 typedef struct
5939 {
5940 OrthancPluginFindMatcher* matcher;
5941 } _OrthancPluginFreeFindMatcher;
5942
5943 /**
5944 * @brief Free a C-Find matcher.
5945 *
5946 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher().
5947 *
5948 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5949 * @param matcher The matcher of interest.
5950 * @ingroup Toolbox
5951 **/
5952 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher(
5953 OrthancPluginContext* context,
5954 OrthancPluginFindMatcher* matcher)
5955 {
5956 _OrthancPluginFreeFindMatcher params;
5957 params.matcher = matcher;
5958
5959 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, &params);
5960 }
5961
5962
5963 typedef struct
5964 {
5965 const OrthancPluginFindMatcher* matcher;
5966 const void* dicom;
5967 uint32_t size;
5968 int32_t* isMatch;
5969 } _OrthancPluginFindMatcherIsMatch;
5970
5971 /**
5972 * @brief Test whether a DICOM instance matches a C-Find query.
5973 *
5974 * This function checks whether one DICOM instance matches C-Find
5975 * matcher that was previously allocated using
5976 * OrthancPluginCreateFindMatcher().
5977 *
5978 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5979 * @param matcher The matcher of interest.
5980 * @param dicom The DICOM instance to be matched.
5981 * @param size The size of the DICOM instance.
5982 * @return 1 if the DICOM instance matches the query, 0 otherwise.
5983 * @ingroup Toolbox
5984 **/
5985 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch(
5986 OrthancPluginContext* context,
5987 const OrthancPluginFindMatcher* matcher,
5988 const void* dicom,
5989 uint32_t size)
5990 {
5991 int32_t isMatch = 0;
5992
5993 _OrthancPluginFindMatcherIsMatch params;
5994 params.matcher = matcher;
5995 params.dicom = dicom;
5996 params.size = size;
5997 params.isMatch = &isMatch;
5998
5999 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, &params) == OrthancPluginErrorCode_Success)
6000 {
6001 return isMatch;
6002 }
6003 else
6004 {
6005 /* Error: Assume non-match */
6006 return 0;
6007 }
6008 }
6009
6010
6011 typedef struct
6012 {
6013 OrthancPluginIncomingHttpRequestFilter2 callback;
6014 } _OrthancPluginIncomingHttpRequestFilter2;
6015
6016 /**
6017 * @brief Register a callback to filter incoming HTTP requests.
6018 *
6019 * This function registers a custom callback to filter incoming HTTP/REST
6020 * requests received by the HTTP server of Orthanc.
6021 *
6022 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6023 * @param callback The callback.
6024 * @return 0 if success, other value if error.
6025 * @ingroup Callbacks
6026 **/
6027 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter2(
6028 OrthancPluginContext* context,
6029 OrthancPluginIncomingHttpRequestFilter2 callback)
6030 {
6031 _OrthancPluginIncomingHttpRequestFilter2 params;
6032 params.callback = callback;
6033
6034 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, &params);
6035 }
6036
6037
6038
6039 typedef struct
6040 {
6041 OrthancPluginPeers** peers;
6042 } _OrthancPluginGetPeers;
6043
6044 /**
6045 * @brief Return the list of available Orthanc peers.
6046 *
6047 * This function returns the parameters of the Orthanc peers that are known to
6048 * the Orthanc server hosting the plugin.
6049 *
6050 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6051 * @return NULL if error, or a newly allocated opaque data structure containing the peers.
6052 * This structure must be freed with OrthancPluginFreePeers().
6053 * @ingroup Toolbox
6054 **/
6055 ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers(
6056 OrthancPluginContext* context)
6057 {
6058 OrthancPluginPeers* peers = NULL;
6059
6060 _OrthancPluginGetPeers params;
6061 memset(&params, 0, sizeof(params));
6062 params.peers = &peers;
6063
6064 if (context->InvokeService(context, _OrthancPluginService_GetPeers, &params) != OrthancPluginErrorCode_Success)
6065 {
6066 return NULL;
6067 }
6068 else
6069 {
6070 return peers;
6071 }
6072 }
6073
6074
6075 typedef struct
6076 {
6077 OrthancPluginPeers* peers;
6078 } _OrthancPluginFreePeers;
6079
6080 /**
6081 * @brief Free the list of available Orthanc peers.
6082 *
6083 * This function frees the data structure returned by OrthancPluginGetPeers().
6084 *
6085 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6086 * @param peers The data structure describing the Orthanc peers.
6087 * @ingroup Toolbox
6088 **/
6089 ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers(
6090 OrthancPluginContext* context,
6091 OrthancPluginPeers* peers)
6092 {
6093 _OrthancPluginFreePeers params;
6094 params.peers = peers;
6095
6096 context->InvokeService(context, _OrthancPluginService_FreePeers, &params);
6097 }
6098
6099
6100 typedef struct
6101 {
6102 uint32_t* target;
6103 const OrthancPluginPeers* peers;
6104 } _OrthancPluginGetPeersCount;
6105
6106 /**
6107 * @brief Get the number of Orthanc peers.
6108 *
6109 * This function returns the number of Orthanc peers.
6110 *
6111 * This function is thread-safe: Several threads sharing the same
6112 * OrthancPluginPeers object can simultaneously call this function.
6113 *
6114 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6115 * @param peers The data structure describing the Orthanc peers.
6116 * @result The number of peers.
6117 * @ingroup Toolbox
6118 **/
6119 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount(
6120 OrthancPluginContext* context,
6121 const OrthancPluginPeers* peers)
6122 {
6123 uint32_t target = 0;
6124
6125 _OrthancPluginGetPeersCount params;
6126 memset(&params, 0, sizeof(params));
6127 params.target = &target;
6128 params.peers = peers;
6129
6130 if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, &params) != OrthancPluginErrorCode_Success)
6131 {
6132 /* Error */
6133 return 0;
6134 }
6135 else
6136 {
6137 return target;
6138 }
6139 }
6140
6141
6142 typedef struct
6143 {
6144 const char** target;
6145 const OrthancPluginPeers* peers;
6146 uint32_t peerIndex;
6147 const char* userProperty;
6148 } _OrthancPluginGetPeerProperty;
6149
6150 /**
6151 * @brief Get the symbolic name of an Orthanc peer.
6152 *
6153 * This function returns the symbolic name of the Orthanc peer,
6154 * which corresponds to the key of the "OrthancPeers" configuration
6155 * option of Orthanc.
6156 *
6157 * This function is thread-safe: Several threads sharing the same
6158 * OrthancPluginPeers object can simultaneously call this function.
6159 *
6160 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6161 * @param peers The data structure describing the Orthanc peers.
6162 * @param peerIndex The index of the peer of interest.
6163 * This value must be lower than OrthancPluginGetPeersCount().
6164 * @result The symbolic name, or NULL in the case of an error.
6165 * @ingroup Toolbox
6166 **/
6167 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName(
6168 OrthancPluginContext* context,
6169 const OrthancPluginPeers* peers,
6170 uint32_t peerIndex)
6171 {
6172 const char* target = NULL;
6173
6174 _OrthancPluginGetPeerProperty params;
6175 memset(&params, 0, sizeof(params));
6176 params.target = &target;
6177 params.peers = peers;
6178 params.peerIndex = peerIndex;
6179 params.userProperty = NULL;
6180
6181 if (context->InvokeService(context, _OrthancPluginService_GetPeerName, &params) != OrthancPluginErrorCode_Success)
6182 {
6183 /* Error */
6184 return NULL;
6185 }
6186 else
6187 {
6188 return target;
6189 }
6190 }
6191
6192
6193 /**
6194 * @brief Get the base URL of an Orthanc peer.
6195 *
6196 * This function returns the base URL to the REST API of some Orthanc peer.
6197 *
6198 * This function is thread-safe: Several threads sharing the same
6199 * OrthancPluginPeers object can simultaneously call this function.
6200 *
6201 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6202 * @param peers The data structure describing the Orthanc peers.
6203 * @param peerIndex The index of the peer of interest.
6204 * This value must be lower than OrthancPluginGetPeersCount().
6205 * @result The URL, or NULL in the case of an error.
6206 * @ingroup Toolbox
6207 **/
6208 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl(
6209 OrthancPluginContext* context,
6210 const OrthancPluginPeers* peers,
6211 uint32_t peerIndex)
6212 {
6213 const char* target = NULL;
6214
6215 _OrthancPluginGetPeerProperty params;
6216 memset(&params, 0, sizeof(params));
6217 params.target = &target;
6218 params.peers = peers;
6219 params.peerIndex = peerIndex;
6220 params.userProperty = NULL;
6221
6222 if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, &params) != OrthancPluginErrorCode_Success)
6223 {
6224 /* Error */
6225 return NULL;
6226 }
6227 else
6228 {
6229 return target;
6230 }
6231 }
6232
6233
6234
6235 /**
6236 * @brief Get some user-defined property of an Orthanc peer.
6237 *
6238 * This function returns some user-defined property of some Orthanc
6239 * peer. An user-defined property is a property that is associated
6240 * with the peer in the Orthanc configuration file, but that is not
6241 * recognized by the Orthanc core.
6242 *
6243 * This function is thread-safe: Several threads sharing the same
6244 * OrthancPluginPeers object can simultaneously call this function.
6245 *
6246 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6247 * @param peers The data structure describing the Orthanc peers.
6248 * @param peerIndex The index of the peer of interest.
6249 * This value must be lower than OrthancPluginGetPeersCount().
6250 * @param userProperty The user property of interest.
6251 * @result The value of the user property, or NULL if it is not defined.
6252 * @ingroup Toolbox
6253 **/
6254 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty(
6255 OrthancPluginContext* context,
6256 const OrthancPluginPeers* peers,
6257 uint32_t peerIndex,
6258 const char* userProperty)
6259 {
6260 const char* target = NULL;
6261
6262 _OrthancPluginGetPeerProperty params;
6263 memset(&params, 0, sizeof(params));
6264 params.target = &target;
6265 params.peers = peers;
6266 params.peerIndex = peerIndex;
6267 params.userProperty = userProperty;
6268
6269 if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, &params) != OrthancPluginErrorCode_Success)
6270 {
6271 /* No such user property */
6272 return NULL;
6273 }
6274 else
6275 {
6276 return target;
6277 }
6278 }
6279
6280
6281
6282 typedef struct
6283 {
6284 OrthancPluginMemoryBuffer* answerBody;
6285 OrthancPluginMemoryBuffer* answerHeaders;
6286 uint16_t* httpStatus;
6287 const OrthancPluginPeers* peers;
6288 uint32_t peerIndex;
6289 OrthancPluginHttpMethod method;
6290 const char* uri;
6291 uint32_t additionalHeadersCount;
6292 const char* const* additionalHeadersKeys;
6293 const char* const* additionalHeadersValues;
6294 const char* body;
6295 uint32_t bodySize;
6296 uint32_t timeout;
6297 } _OrthancPluginCallPeerApi;
6298
6299 /**
6300 * @brief Call the REST API of an Orthanc peer.
6301 *
6302 * Make a REST call to the given URI in the REST API of a remote
6303 * Orthanc peer. The result to the query is stored into a newly
6304 * allocated memory buffer. The HTTP request will be done according
6305 * to the "OrthancPeers" configuration option of Orthanc.
6306 *
6307 * This function is thread-safe: Several threads sharing the same
6308 * OrthancPluginPeers object can simultaneously call this function.
6309 *
6310 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6311 * @param answerBody The target memory buffer (out argument).
6312 * It must be freed with OrthancPluginFreeMemoryBuffer().
6313 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
6314 * The answer headers are formatted as a JSON object (associative array).
6315 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
6316 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
6317 * @param httpStatus The HTTP status after the execution of the request (out argument).
6318 * @param peers The data structure describing the Orthanc peers.
6319 * @param peerIndex The index of the peer of interest.
6320 * This value must be lower than OrthancPluginGetPeersCount().
6321 * @param method HTTP method to be used.
6322 * @param uri The URI of interest in the REST API.
6323 * @param additionalHeadersCount The number of HTTP headers to be added to the
6324 * HTTP headers provided in the global configuration of Orthanc.
6325 * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
6326 * @param additionalHeadersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
6327 * @param body The HTTP body for a POST or PUT request.
6328 * @param bodySize The size of the body.
6329 * @param timeout Timeout in seconds (0 for default timeout).
6330 * @return 0 if success, or the error code if failure.
6331 * @see OrthancPluginHttpClient()
6332 * @ingroup Toolbox
6333 **/
6334 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi(
6335 OrthancPluginContext* context,
6336 OrthancPluginMemoryBuffer* answerBody,
6337 OrthancPluginMemoryBuffer* answerHeaders,
6338 uint16_t* httpStatus,
6339 const OrthancPluginPeers* peers,
6340 uint32_t peerIndex,
6341 OrthancPluginHttpMethod method,
6342 const char* uri,
6343 uint32_t additionalHeadersCount,
6344 const char* const* additionalHeadersKeys,
6345 const char* const* additionalHeadersValues,
6346 const char* body,
6347 uint32_t bodySize,
6348 uint32_t timeout)
6349 {
6350 _OrthancPluginCallPeerApi params;
6351 memset(&params, 0, sizeof(params));
6352
6353 params.answerBody = answerBody;
6354 params.answerHeaders = answerHeaders;
6355 params.httpStatus = httpStatus;
6356 params.peers = peers;
6357 params.peerIndex = peerIndex;
6358 params.method = method;
6359 params.uri = uri;
6360 params.additionalHeadersCount = additionalHeadersCount;
6361 params.additionalHeadersKeys = additionalHeadersKeys;
6362 params.additionalHeadersValues = additionalHeadersValues;
6363 params.body = body;
6364 params.bodySize = bodySize;
6365 params.timeout = timeout;
6366
6367 return context->InvokeService(context, _OrthancPluginService_CallPeerApi, &params);
6368 }
6369
6370
6371
6372
6373
6374 typedef struct
6375 {
6376 OrthancPluginJob** target;
6377 void *job;
6378 OrthancPluginJobFinalize finalize;
6379 const char *type;
6380 OrthancPluginJobGetProgress getProgress;
6381 OrthancPluginJobGetContent getContent;
6382 OrthancPluginJobGetSerialized getSerialized;
6383 OrthancPluginJobStep step;
6384 OrthancPluginJobStop stop;
6385 OrthancPluginJobReset reset;
6386 } _OrthancPluginCreateJob;
6387
6388 /**
6389 * @brief Create a custom job.
6390 *
6391 * This function creates a custom job to be run by the jobs engine
6392 * of Orthanc.
6393 *
6394 * Orthanc starts one dedicated thread per custom job that is
6395 * running. It is guaranteed that all the callbacks will only be
6396 * called from this single dedicated thread, in mutual exclusion: As
6397 * a consequence, it is *not* mandatory to protect the various
6398 * callbacks by mutexes.
6399 *
6400 * The custom job can nonetheless launch its own processing threads
6401 * on the first call to the "step()" callback, and stop them once
6402 * the "stop()" callback is called.
6403 *
6404 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6405 * @param job The job to be executed.
6406 * @param finalize The finalization callback.
6407 * @param type The type of the job, provided to the job unserializer.
6408 * See OrthancPluginRegisterJobsUnserializer().
6409 * @param getProgress The progress callback.
6410 * @param getContent The content callback.
6411 * @param getSerialized The serialization callback.
6412 * @param step The callback to execute the individual steps of the job.
6413 * @param stop The callback that is invoked once the job leaves the "running" state.
6414 * @param reset The callback that is invoked if a stopped job is started again.
6415 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(),
6416 * as long as it is not submitted with OrthancPluginSubmitJob().
6417 * @ingroup Toolbox
6418 **/
6419 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob(
6420 OrthancPluginContext *context,
6421 void *job,
6422 OrthancPluginJobFinalize finalize,
6423 const char *type,
6424 OrthancPluginJobGetProgress getProgress,
6425 OrthancPluginJobGetContent getContent,
6426 OrthancPluginJobGetSerialized getSerialized,
6427 OrthancPluginJobStep step,
6428 OrthancPluginJobStop stop,
6429 OrthancPluginJobReset reset)
6430 {
6431 OrthancPluginJob* target = NULL;
6432
6433 _OrthancPluginCreateJob params;
6434 memset(&params, 0, sizeof(params));
6435
6436 params.target = &target;
6437 params.job = job;
6438 params.finalize = finalize;
6439 params.type = type;
6440 params.getProgress = getProgress;
6441 params.getContent = getContent;
6442 params.getSerialized = getSerialized;
6443 params.step = step;
6444 params.stop = stop;
6445 params.reset = reset;
6446
6447 if (context->InvokeService(context, _OrthancPluginService_CreateJob, &params) != OrthancPluginErrorCode_Success ||
6448 target == NULL)
6449 {
6450 /* Error */
6451 return NULL;
6452 }
6453 else
6454 {
6455 return target;
6456 }
6457 }
6458
6459
6460 typedef struct
6461 {
6462 OrthancPluginJob* job;
6463 } _OrthancPluginFreeJob;
6464
6465 /**
6466 * @brief Free a custom job.
6467 *
6468 * This function frees an image that was created with OrthancPluginCreateJob().
6469 *
6470 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6471 * @param job The job.
6472 * @ingroup Toolbox
6473 **/
6474 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob(
6475 OrthancPluginContext* context,
6476 OrthancPluginJob* job)
6477 {
6478 _OrthancPluginFreeJob params;
6479 params.job = job;
6480
6481 context->InvokeService(context, _OrthancPluginService_FreeJob, &params);
6482 }
6483
6484
6485
6486 typedef struct
6487 {
6488 char** resultId;
6489 OrthancPluginJob *job;
6490 int priority;
6491 } _OrthancPluginSubmitJob;
6492
6493 /**
6494 * @brief Submit a new job to the jobs engine of Orthanc.
6495 *
6496 * This function adds the given job to the pending jobs of
6497 * Orthanc. Orthanc will take take of freeing it by invoking the
6498 * finalization callback provided to OrthancPluginCreateJob().
6499 *
6500 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6501 * @param job The job, as received by OrthancPluginCreateJob().
6502 * @param priority The priority of the job.
6503 * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString().
6504 * @ingroup Toolbox
6505 **/
6506 ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob(
6507 OrthancPluginContext *context,
6508 OrthancPluginJob *job,
6509 int priority)
6510 {
6511 char* resultId = NULL;
6512
6513 _OrthancPluginSubmitJob params;
6514 memset(&params, 0, sizeof(params));
6515
6516 params.resultId = &resultId;
6517 params.job = job;
6518 params.priority = priority;
6519
6520 if (context->InvokeService(context, _OrthancPluginService_SubmitJob, &params) != OrthancPluginErrorCode_Success ||
6521 resultId == NULL)
6522 {
6523 /* Error */
6524 return NULL;
6525 }
6526 else
6527 {
6528 return resultId;
6529 }
6530 }
6531
6532
6533
6534 typedef struct
6535 {
6536 OrthancPluginJobsUnserializer unserializer;
6537 } _OrthancPluginJobsUnserializer;
6538
6539 /**
6540 * @brief Register an unserializer for custom jobs.
6541 *
6542 * This function registers an unserializer that decodes custom jobs
6543 * from a JSON string. This callback is invoked when the jobs engine
6544 * of Orthanc is started (on Orthanc initialization), for each job
6545 * that is stored in the Orthanc database.
6546 *
6547 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6548 * @param unserializer The job unserializer.
6549 * @ingroup Callbacks
6550 **/
6551 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer(
6552 OrthancPluginContext* context,
6553 OrthancPluginJobsUnserializer unserializer)
6554 {
6555 _OrthancPluginJobsUnserializer params;
6556 params.unserializer = unserializer;
6557
6558 context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, &params);
6559 }
6560
6561
6562
6563 typedef struct
6564 {
6565 OrthancPluginRestOutput* output;
6566 const char* details;
6567 uint8_t log;
6568 } _OrthancPluginSetHttpErrorDetails;
6569
6570 /**
6571 * @brief Provide a detailed description for an HTTP error.
6572 *
6573 * This function sets the detailed description associated with an
6574 * HTTP error. This description will be displayed in the "Details"
6575 * field of the JSON body of the HTTP answer. It is only taken into
6576 * consideration if the REST callback returns an error code that is
6577 * different from "OrthancPluginErrorCode_Success", and if the
6578 * "HttpDescribeErrors" configuration option of Orthanc is set to
6579 * "true".
6580 *
6581 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6582 * @param output The HTTP connection to the client application.
6583 * @param details The details of the error message.
6584 * @param log Whether to also write the detailed error to the Orthanc logs.
6585 * @ingroup REST
6586 **/
6587 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails(
6588 OrthancPluginContext* context,
6589 OrthancPluginRestOutput* output,
6590 const char* details,
6591 uint8_t log)
6592 {
6593 _OrthancPluginSetHttpErrorDetails params;
6594 params.output = output;
6595 params.details = details;
6596 params.log = log;
6597 context->InvokeService(context, _OrthancPluginService_SetHttpErrorDetails, &params);
6598 }
6599
6600
6601
6602 typedef struct
6603 {
6604 const char** result;
6605 const char* argument;
6606 } _OrthancPluginRetrieveStaticString;
6607
6608 /**
6609 * @brief Detect the MIME type of a file.
6610 *
6611 * This function returns the MIME type of a file by inspecting its extension.
6612 *
6613 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6614 * @param path Path to the file.
6615 * @return The MIME type. This is a statically-allocated
6616 * string, do not free it.
6617 * @ingroup Toolbox
6618 **/
6619 ORTHANC_PLUGIN_INLINE const char* OrthancPluginAutodetectMimeType(
6620 OrthancPluginContext* context,
6621 const char* path)
6622 {
6623 const char* result = NULL;
6624
6625 _OrthancPluginRetrieveStaticString params;
6626 params.result = &result;
6627 params.argument = path;
6628
6629 if (context->InvokeService(context, _OrthancPluginService_AutodetectMimeType, &params) != OrthancPluginErrorCode_Success)
6630 {
6631 /* Error */
6632 return NULL;
6633 }
6634 else
6635 {
6636 return result;
6637 }
6638 }
6639
6640
6641
6642 typedef struct
6643 {
6644 const char* name;
6645 float value;
6646 OrthancPluginMetricsType type;
6647 } _OrthancPluginSetMetricsValue;
6648
6649 /**
6650 * @brief Set the value of a metrics.
6651 *
6652 * This function sets the value of a metrics to monitor the behavior
6653 * of the plugin through tools such as Prometheus. The values of all
6654 * the metrics are stored within the Orthanc context.
6655 *
6656 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6657 * @param name The name of the metrics to be set.
6658 * @param value The value of the metrics.
6659 * @param type The type of the metrics. This parameter is only taken into consideration
6660 * the first time this metrics is set.
6661 * @ingroup Toolbox
6662 **/
6663 ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsValue(
6664 OrthancPluginContext* context,
6665 const char* name,
6666 float value,
6667 OrthancPluginMetricsType type)
6668 {
6669 _OrthancPluginSetMetricsValue params;
6670 params.name = name;
6671 params.value = value;
6672 params.type = type;
6673 context->InvokeService(context, _OrthancPluginService_SetMetricsValue, &params);
6674 }
6675
6676
6677
6678 typedef struct
6679 {
6680 OrthancPluginRefreshMetricsCallback callback;
6681 } _OrthancPluginRegisterRefreshMetricsCallback;
6682
6683 /**
6684 * @brief Register a callback to refresh the metrics.
6685 *
6686 * This function registers a callback to refresh the metrics. The
6687 * callback must make calls to OrthancPluginSetMetricsValue().
6688 *
6689 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6690 * @param callback The callback function to handle the refresh.
6691 * @ingroup Callbacks
6692 **/
6693 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRefreshMetricsCallback(
6694 OrthancPluginContext* context,
6695 OrthancPluginRefreshMetricsCallback callback)
6696 {
6697 _OrthancPluginRegisterRefreshMetricsCallback params;
6698 params.callback = callback;
6699 context->InvokeService(context, _OrthancPluginService_RegisterRefreshMetricsCallback, &params);
6700 }
6701
6702
6703
6704
6705 typedef struct
6706 {
6707 char** target;
6708 const void* dicom;
6709 uint32_t dicomSize;
6710 OrthancPluginDicomWebBinaryCallback callback;
6711 } _OrthancPluginEncodeDicomWeb;
6712
6713 /**
6714 * @brief Convert a DICOM instance to DICOMweb JSON.
6715 *
6716 * This function converts a memory buffer containing a DICOM instance,
6717 * into its DICOMweb JSON representation.
6718 *
6719 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6720 * @param dicom Pointer to the DICOM instance.
6721 * @param dicomSize Size of the DICOM instance.
6722 * @param callback Callback to set the value of the binary tags.
6723 * @see OrthancPluginCreateDicom()
6724 * @return The NULL value in case of error, or the JSON document. This string must
6725 * be freed by OrthancPluginFreeString().
6726 * @ingroup Toolbox
6727 **/
6728 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson(
6729 OrthancPluginContext* context,
6730 const void* dicom,
6731 uint32_t dicomSize,
6732 OrthancPluginDicomWebBinaryCallback callback)
6733 {
6734 char* target = NULL;
6735
6736 _OrthancPluginEncodeDicomWeb params;
6737 params.target = &target;
6738 params.dicom = dicom;
6739 params.dicomSize = dicomSize;
6740 params.callback = callback;
6741
6742 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson, &params) != OrthancPluginErrorCode_Success)
6743 {
6744 /* Error */
6745 return NULL;
6746 }
6747 else
6748 {
6749 return target;
6750 }
6751 }
6752
6753
6754 /**
6755 * @brief Convert a DICOM instance to DICOMweb XML.
6756 *
6757 * This function converts a memory buffer containing a DICOM instance,
6758 * into its DICOMweb XML representation.
6759 *
6760 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6761 * @param dicom Pointer to the DICOM instance.
6762 * @param dicomSize Size of the DICOM instance.
6763 * @param callback Callback to set the value of the binary tags.
6764 * @return The NULL value in case of error, or the JSON document. This string must
6765 * be freed by OrthancPluginFreeString().
6766 * @see OrthancPluginCreateDicom()
6767 * @ingroup Toolbox
6768 **/
6769 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml(
6770 OrthancPluginContext* context,
6771 const void* dicom,
6772 uint32_t dicomSize,
6773 OrthancPluginDicomWebBinaryCallback callback)
6774 {
6775 char* target = NULL;
6776
6777 _OrthancPluginEncodeDicomWeb params;
6778 params.target = &target;
6779 params.dicom = dicom;
6780 params.dicomSize = dicomSize;
6781 params.callback = callback;
6782
6783 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml, &params) != OrthancPluginErrorCode_Success)
6784 {
6785 /* Error */
6786 return NULL;
6787 }
6788 else
6789 {
6790 return target;
6791 }
6792 }
6793
6794
6795 #ifdef __cplusplus
6796 }
6797 #endif
6798
6799
6800 /** @} */
6801
+0
-7260
Resources/Orthanc/Sdk-1.5.7/orthanc/OrthancCPlugin.h less more
0 /**
1 * \mainpage
2 *
3 * This C/C++ SDK allows external developers to create plugins that
4 * can be loaded into Orthanc to extend its functionality. Each
5 * Orthanc plugin must expose 4 public functions with the following
6 * signatures:
7 *
8 * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>:
9 * This function is invoked by Orthanc when it loads the plugin on startup.
10 * The plugin must:
11 * - Check its compatibility with the Orthanc version using
12 * ::OrthancPluginCheckVersion().
13 * - Store the context pointer so that it can use the plugin
14 * services of Orthanc.
15 * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback().
16 * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback().
17 * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback().
18 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea().
19 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2().
20 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback().
21 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback().
22 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback().
23 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback().
24 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2().
25 * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer().
26 * - Possibly register a callback to refresh its metrics using OrthancPluginRegisterRefreshMetricsCallback().
27 * - Possibly register a callback to answer chunked HTTP transfers using ::OrthancPluginRegisterChunkedRestCallback().
28 * -# <tt>void OrthancPluginFinalize()</tt>:
29 * This function is invoked by Orthanc during its shutdown. The plugin
30 * must free all its memory.
31 * -# <tt>const char* OrthancPluginGetName()</tt>:
32 * The plugin must return a short string to identify itself.
33 * -# <tt>const char* OrthancPluginGetVersion()</tt>:
34 * The plugin must return a string containing its version number.
35 *
36 * The name and the version of a plugin is only used to prevent it
37 * from being loaded twice. Note that, in C++, it is mandatory to
38 * declare these functions within an <tt>extern "C"</tt> section.
39 *
40 * To ensure multi-threading safety, the various REST callbacks are
41 * guaranteed to be executed in mutual exclusion since Orthanc
42 * 0.8.5. If this feature is undesired (notably when developing
43 * high-performance plugins handling simultaneous requests), use
44 * ::OrthancPluginRegisterRestCallbackNoLock().
45 **/
46
47
48
49 /**
50 * @defgroup Images Images and compression
51 * @brief Functions to deal with images and compressed buffers.
52 *
53 * @defgroup REST REST
54 * @brief Functions to answer REST requests in a callback.
55 *
56 * @defgroup Callbacks Callbacks
57 * @brief Functions to register and manage callbacks by the plugins.
58 *
59 * @defgroup DicomCallbacks DicomCallbacks
60 * @brief Functions to register and manage DICOM callbacks (worklists, C-Find, C-MOVE).
61 *
62 * @defgroup Orthanc Orthanc
63 * @brief Functions to access the content of the Orthanc server.
64 **/
65
66
67
68 /**
69 * @defgroup Toolbox Toolbox
70 * @brief Generic functions to help with the creation of plugins.
71 **/
72
73
74
75 /**
76 * Orthanc - A Lightweight, RESTful DICOM Store
77 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
78 * Department, University Hospital of Liege, Belgium
79 * Copyright (C) 2017-2019 Osimis S.A., Belgium
80 *
81 * This program is free software: you can redistribute it and/or
82 * modify it under the terms of the GNU General Public License as
83 * published by the Free Software Foundation, either version 3 of the
84 * License, or (at your option) any later version.
85 *
86 * In addition, as a special exception, the copyright holders of this
87 * program give permission to link the code of its release with the
88 * OpenSSL project's "OpenSSL" library (or with modified versions of it
89 * that use the same license as the "OpenSSL" library), and distribute
90 * the linked executables. You must obey the GNU General Public License
91 * in all respects for all of the code used other than "OpenSSL". If you
92 * modify file(s) with this exception, you may extend this exception to
93 * your version of the file(s), but you are not obligated to do so. If
94 * you do not wish to do so, delete this exception statement from your
95 * version. If you delete this exception statement from all source files
96 * in the program, then also delete it here.
97 *
98 * This program is distributed in the hope that it will be useful, but
99 * WITHOUT ANY WARRANTY; without even the implied warranty of
100 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
101 * General Public License for more details.
102 *
103 * You should have received a copy of the GNU General Public License
104 * along with this program. If not, see <http://www.gnu.org/licenses/>.
105 **/
106
107
108
109 #pragma once
110
111
112 #include <stdio.h>
113 #include <string.h>
114
115 #ifdef WIN32
116 # define ORTHANC_PLUGINS_API __declspec(dllexport)
117 #elif __GNUC__ >= 4
118 # define ORTHANC_PLUGINS_API __attribute__ ((visibility ("default")))
119 #else
120 # define ORTHANC_PLUGINS_API
121 #endif
122
123 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1
124 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 5
125 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 7
126
127
128 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
129 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \
130 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \
131 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \
132 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \
133 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \
134 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision))))
135 #endif
136
137
138
139 /********************************************************************
140 ** Check that function inlining is properly supported. The use of
141 ** inlining is required, to avoid the duplication of object code
142 ** between two compilation modules that would use the Orthanc Plugin
143 ** API.
144 ********************************************************************/
145
146 /* If the auto-detection of the "inline" keyword below does not work
147 automatically and that your compiler is known to properly support
148 inlining, uncomment the following #define and adapt the definition
149 of "static inline". */
150
151 /* #define ORTHANC_PLUGIN_INLINE static inline */
152
153 #ifndef ORTHANC_PLUGIN_INLINE
154 # if __STDC_VERSION__ >= 199901L
155 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
156 # define ORTHANC_PLUGIN_INLINE static inline
157 # elif defined(__cplusplus)
158 /* This is C++ */
159 # define ORTHANC_PLUGIN_INLINE static inline
160 # elif defined(__GNUC__)
161 /* This is GCC running in C89 mode */
162 # define ORTHANC_PLUGIN_INLINE static __inline
163 # elif defined(_MSC_VER)
164 /* This is Visual Studio running in C89 mode */
165 # define ORTHANC_PLUGIN_INLINE static __inline
166 # else
167 # error Your compiler is not known to support the "inline" keyword
168 # endif
169 #endif
170
171
172
173 /********************************************************************
174 ** Inclusion of standard libraries.
175 ********************************************************************/
176
177 /**
178 * For Microsoft Visual Studio, a compatibility "stdint.h" can be
179 * downloaded at the following URL:
180 * https://bitbucket.org/sjodogne/orthanc/raw/default/Resources/ThirdParty/VisualStudio/stdint.h
181 **/
182 #include <stdint.h>
183
184 #include <stdlib.h>
185
186
187
188 /********************************************************************
189 ** Definition of the Orthanc Plugin API.
190 ********************************************************************/
191
192 /** @{ */
193
194 #ifdef __cplusplus
195 extern "C"
196 {
197 #endif
198
199 /**
200 * The various error codes that can be returned by the Orthanc core.
201 **/
202 typedef enum
203 {
204 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */,
205 OrthancPluginErrorCode_Success = 0 /*!< Success */,
206 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */,
207 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */,
208 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */,
209 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */,
210 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */,
211 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */,
212 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */,
213 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */,
214 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */,
215 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */,
216 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */,
217 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */,
218 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */,
219 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */,
220 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */,
221 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */,
222 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */,
223 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */,
224 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */,
225 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */,
226 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */,
227 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */,
228 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */,
229 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */,
230 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */,
231 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */,
232 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */,
233 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */,
234 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */,
235 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */,
236 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */,
237 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */,
238 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */,
239 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */,
240 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */,
241 OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */,
242 OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */,
243 OrthancPluginErrorCode_BadGeometry = 38 /*!< Geometry error encountered in Stone */,
244 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */,
245 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */,
246 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */,
247 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */,
248 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */,
249 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */,
250 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */,
251 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */,
252 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */,
253 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */,
254 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */,
255 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */,
256 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */,
257 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */,
258 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */,
259 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */,
260 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */,
261 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */,
262 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */,
263 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */,
264 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */,
265 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */,
266 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */,
267 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */,
268 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */,
269 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */,
270 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */,
271 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */,
272 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */,
273 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */,
274 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */,
275 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */,
276 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */,
277 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */,
278 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */,
279 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */,
280 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */,
281 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */,
282 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */,
283 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */,
284 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */,
285 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */,
286 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */,
287 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */,
288 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */,
289 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */,
290 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */,
291 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */,
292 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */,
293 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */,
294 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */,
295 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */,
296 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */,
297 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */,
298 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */,
299 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */,
300 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */,
301 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */,
302 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */,
303 OrthancPluginErrorCode_UnsupportedMediaType = 3000 /*!< Unsupported media type */,
304
305 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff
306 } OrthancPluginErrorCode;
307
308
309 /**
310 * Forward declaration of one of the mandatory functions for Orthanc
311 * plugins.
312 **/
313 ORTHANC_PLUGINS_API const char* OrthancPluginGetName();
314
315
316 /**
317 * The various HTTP methods for a REST call.
318 **/
319 typedef enum
320 {
321 OrthancPluginHttpMethod_Get = 1, /*!< GET request */
322 OrthancPluginHttpMethod_Post = 2, /*!< POST request */
323 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
324 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */
325
326 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff
327 } OrthancPluginHttpMethod;
328
329
330 /**
331 * @brief The parameters of a REST request.
332 * @ingroup Callbacks
333 **/
334 typedef struct
335 {
336 /**
337 * @brief The HTTP method.
338 **/
339 OrthancPluginHttpMethod method;
340
341 /**
342 * @brief The number of groups of the regular expression.
343 **/
344 uint32_t groupsCount;
345
346 /**
347 * @brief The matched values for the groups of the regular expression.
348 **/
349 const char* const* groups;
350
351 /**
352 * @brief For a GET request, the number of GET parameters.
353 **/
354 uint32_t getCount;
355
356 /**
357 * @brief For a GET request, the keys of the GET parameters.
358 **/
359 const char* const* getKeys;
360
361 /**
362 * @brief For a GET request, the values of the GET parameters.
363 **/
364 const char* const* getValues;
365
366 /**
367 * @brief For a PUT or POST request, the content of the body.
368 **/
369 const void* body;
370
371 /**
372 * @brief For a PUT or POST request, the number of bytes of the body.
373 **/
374 uint32_t bodySize;
375
376
377 /* --------------------------------------------------
378 New in version 0.8.1
379 -------------------------------------------------- */
380
381 /**
382 * @brief The number of HTTP headers.
383 **/
384 uint32_t headersCount;
385
386 /**
387 * @brief The keys of the HTTP headers (always converted to low-case).
388 **/
389 const char* const* headersKeys;
390
391 /**
392 * @brief The values of the HTTP headers.
393 **/
394 const char* const* headersValues;
395
396 } OrthancPluginHttpRequest;
397
398
399 typedef enum
400 {
401 /* Generic services */
402 _OrthancPluginService_LogInfo = 1,
403 _OrthancPluginService_LogWarning = 2,
404 _OrthancPluginService_LogError = 3,
405 _OrthancPluginService_GetOrthancPath = 4,
406 _OrthancPluginService_GetOrthancDirectory = 5,
407 _OrthancPluginService_GetConfigurationPath = 6,
408 _OrthancPluginService_SetPluginProperty = 7,
409 _OrthancPluginService_GetGlobalProperty = 8,
410 _OrthancPluginService_SetGlobalProperty = 9,
411 _OrthancPluginService_GetCommandLineArgumentsCount = 10,
412 _OrthancPluginService_GetCommandLineArgument = 11,
413 _OrthancPluginService_GetExpectedDatabaseVersion = 12,
414 _OrthancPluginService_GetConfiguration = 13,
415 _OrthancPluginService_BufferCompression = 14,
416 _OrthancPluginService_ReadFile = 15,
417 _OrthancPluginService_WriteFile = 16,
418 _OrthancPluginService_GetErrorDescription = 17,
419 _OrthancPluginService_CallHttpClient = 18,
420 _OrthancPluginService_RegisterErrorCode = 19,
421 _OrthancPluginService_RegisterDictionaryTag = 20,
422 _OrthancPluginService_DicomBufferToJson = 21,
423 _OrthancPluginService_DicomInstanceToJson = 22,
424 _OrthancPluginService_CreateDicom = 23,
425 _OrthancPluginService_ComputeMd5 = 24,
426 _OrthancPluginService_ComputeSha1 = 25,
427 _OrthancPluginService_LookupDictionary = 26,
428 _OrthancPluginService_CallHttpClient2 = 27,
429 _OrthancPluginService_GenerateUuid = 28,
430 _OrthancPluginService_RegisterPrivateDictionaryTag = 29,
431 _OrthancPluginService_AutodetectMimeType = 30,
432 _OrthancPluginService_SetMetricsValue = 31,
433 _OrthancPluginService_EncodeDicomWebJson = 32,
434 _OrthancPluginService_EncodeDicomWebXml = 33,
435 _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */
436 _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */
437
438 /* Registration of callbacks */
439 _OrthancPluginService_RegisterRestCallback = 1000,
440 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
441 _OrthancPluginService_RegisterStorageArea = 1002,
442 _OrthancPluginService_RegisterOnChangeCallback = 1003,
443 _OrthancPluginService_RegisterRestCallbackNoLock = 1004,
444 _OrthancPluginService_RegisterWorklistCallback = 1005,
445 _OrthancPluginService_RegisterDecodeImageCallback = 1006,
446 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007,
447 _OrthancPluginService_RegisterFindCallback = 1008,
448 _OrthancPluginService_RegisterMoveCallback = 1009,
449 _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010,
450 _OrthancPluginService_RegisterRefreshMetricsCallback = 1011,
451 _OrthancPluginService_RegisterChunkedRestCallback = 1012, /* New in Orthanc 1.5.7 */
452
453 /* Sending answers to REST calls */
454 _OrthancPluginService_AnswerBuffer = 2000,
455 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */
456 _OrthancPluginService_Redirect = 2002,
457 _OrthancPluginService_SendHttpStatusCode = 2003,
458 _OrthancPluginService_SendUnauthorized = 2004,
459 _OrthancPluginService_SendMethodNotAllowed = 2005,
460 _OrthancPluginService_SetCookie = 2006,
461 _OrthancPluginService_SetHttpHeader = 2007,
462 _OrthancPluginService_StartMultipartAnswer = 2008,
463 _OrthancPluginService_SendMultipartItem = 2009,
464 _OrthancPluginService_SendHttpStatus = 2010,
465 _OrthancPluginService_CompressAndAnswerImage = 2011,
466 _OrthancPluginService_SendMultipartItem2 = 2012,
467 _OrthancPluginService_SetHttpErrorDetails = 2013,
468
469 /* Access to the Orthanc database and API */
470 _OrthancPluginService_GetDicomForInstance = 3000,
471 _OrthancPluginService_RestApiGet = 3001,
472 _OrthancPluginService_RestApiPost = 3002,
473 _OrthancPluginService_RestApiDelete = 3003,
474 _OrthancPluginService_RestApiPut = 3004,
475 _OrthancPluginService_LookupPatient = 3005,
476 _OrthancPluginService_LookupStudy = 3006,
477 _OrthancPluginService_LookupSeries = 3007,
478 _OrthancPluginService_LookupInstance = 3008,
479 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
480 _OrthancPluginService_RestApiGetAfterPlugins = 3010,
481 _OrthancPluginService_RestApiPostAfterPlugins = 3011,
482 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012,
483 _OrthancPluginService_RestApiPutAfterPlugins = 3013,
484 _OrthancPluginService_ReconstructMainDicomTags = 3014,
485 _OrthancPluginService_RestApiGet2 = 3015,
486
487 /* Access to DICOM instances */
488 _OrthancPluginService_GetInstanceRemoteAet = 4000,
489 _OrthancPluginService_GetInstanceSize = 4001,
490 _OrthancPluginService_GetInstanceData = 4002,
491 _OrthancPluginService_GetInstanceJson = 4003,
492 _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
493 _OrthancPluginService_HasInstanceMetadata = 4005,
494 _OrthancPluginService_GetInstanceMetadata = 4006,
495 _OrthancPluginService_GetInstanceOrigin = 4007,
496
497 /* Services for plugins implementing a database back-end */
498 _OrthancPluginService_RegisterDatabaseBackend = 5000,
499 _OrthancPluginService_DatabaseAnswer = 5001,
500 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002,
501 _OrthancPluginService_StorageAreaCreate = 5003,
502 _OrthancPluginService_StorageAreaRead = 5004,
503 _OrthancPluginService_StorageAreaRemove = 5005,
504
505 /* Primitives for handling images */
506 _OrthancPluginService_GetImagePixelFormat = 6000,
507 _OrthancPluginService_GetImageWidth = 6001,
508 _OrthancPluginService_GetImageHeight = 6002,
509 _OrthancPluginService_GetImagePitch = 6003,
510 _OrthancPluginService_GetImageBuffer = 6004,
511 _OrthancPluginService_UncompressImage = 6005,
512 _OrthancPluginService_FreeImage = 6006,
513 _OrthancPluginService_CompressImage = 6007,
514 _OrthancPluginService_ConvertPixelFormat = 6008,
515 _OrthancPluginService_GetFontsCount = 6009,
516 _OrthancPluginService_GetFontInfo = 6010,
517 _OrthancPluginService_DrawText = 6011,
518 _OrthancPluginService_CreateImage = 6012,
519 _OrthancPluginService_CreateImageAccessor = 6013,
520 _OrthancPluginService_DecodeDicomImage = 6014,
521
522 /* Primitives for handling C-Find, C-Move and worklists */
523 _OrthancPluginService_WorklistAddAnswer = 7000,
524 _OrthancPluginService_WorklistMarkIncomplete = 7001,
525 _OrthancPluginService_WorklistIsMatch = 7002,
526 _OrthancPluginService_WorklistGetDicomQuery = 7003,
527 _OrthancPluginService_FindAddAnswer = 7004,
528 _OrthancPluginService_FindMarkIncomplete = 7005,
529 _OrthancPluginService_GetFindQuerySize = 7006,
530 _OrthancPluginService_GetFindQueryTag = 7007,
531 _OrthancPluginService_GetFindQueryTagName = 7008,
532 _OrthancPluginService_GetFindQueryValue = 7009,
533 _OrthancPluginService_CreateFindMatcher = 7010,
534 _OrthancPluginService_FreeFindMatcher = 7011,
535 _OrthancPluginService_FindMatcherIsMatch = 7012,
536
537 /* Primitives for accessing Orthanc Peers (new in 1.4.2) */
538 _OrthancPluginService_GetPeers = 8000,
539 _OrthancPluginService_FreePeers = 8001,
540 _OrthancPluginService_GetPeersCount = 8003,
541 _OrthancPluginService_GetPeerName = 8004,
542 _OrthancPluginService_GetPeerUrl = 8005,
543 _OrthancPluginService_CallPeerApi = 8006,
544 _OrthancPluginService_GetPeerUserProperty = 8007,
545
546 /* Primitives for handling jobs (new in 1.4.2) */
547 _OrthancPluginService_CreateJob = 9000,
548 _OrthancPluginService_FreeJob = 9001,
549 _OrthancPluginService_SubmitJob = 9002,
550 _OrthancPluginService_RegisterJobsUnserializer = 9003,
551
552 _OrthancPluginService_INTERNAL = 0x7fffffff
553 } _OrthancPluginService;
554
555
556 typedef enum
557 {
558 _OrthancPluginProperty_Description = 1,
559 _OrthancPluginProperty_RootUri = 2,
560 _OrthancPluginProperty_OrthancExplorer = 3,
561
562 _OrthancPluginProperty_INTERNAL = 0x7fffffff
563 } _OrthancPluginProperty;
564
565
566
567 /**
568 * The memory layout of the pixels of an image.
569 * @ingroup Images
570 **/
571 typedef enum
572 {
573 /**
574 * @brief Graylevel 8bpp image.
575 *
576 * The image is graylevel. Each pixel is unsigned and stored in
577 * one byte.
578 **/
579 OrthancPluginPixelFormat_Grayscale8 = 1,
580
581 /**
582 * @brief Graylevel, unsigned 16bpp image.
583 *
584 * The image is graylevel. Each pixel is unsigned and stored in
585 * two bytes.
586 **/
587 OrthancPluginPixelFormat_Grayscale16 = 2,
588
589 /**
590 * @brief Graylevel, signed 16bpp image.
591 *
592 * The image is graylevel. Each pixel is signed and stored in two
593 * bytes.
594 **/
595 OrthancPluginPixelFormat_SignedGrayscale16 = 3,
596
597 /**
598 * @brief Color image in RGB24 format.
599 *
600 * This format describes a color image. The pixels are stored in 3
601 * consecutive bytes. The memory layout is RGB.
602 **/
603 OrthancPluginPixelFormat_RGB24 = 4,
604
605 /**
606 * @brief Color image in RGBA32 format.
607 *
608 * This format describes a color image. The pixels are stored in 4
609 * consecutive bytes. The memory layout is RGBA.
610 **/
611 OrthancPluginPixelFormat_RGBA32 = 5,
612
613 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */
614
615 /**
616 * @brief Color image in RGB48 format.
617 *
618 * This format describes a color image. The pixels are stored in 6
619 * consecutive bytes. The memory layout is RRGGBB.
620 **/
621 OrthancPluginPixelFormat_RGB48 = 7,
622
623 /**
624 * @brief Graylevel, unsigned 32bpp image.
625 *
626 * The image is graylevel. Each pixel is unsigned and stored in
627 * four bytes.
628 **/
629 OrthancPluginPixelFormat_Grayscale32 = 8,
630
631 /**
632 * @brief Graylevel, floating-point 32bpp image.
633 *
634 * The image is graylevel. Each pixel is floating-point and stored
635 * in four bytes.
636 **/
637 OrthancPluginPixelFormat_Float32 = 9,
638
639 /**
640 * @brief Color image in BGRA32 format.
641 *
642 * This format describes a color image. The pixels are stored in 4
643 * consecutive bytes. The memory layout is BGRA.
644 **/
645 OrthancPluginPixelFormat_BGRA32 = 10,
646
647 /**
648 * @brief Graylevel, unsigned 64bpp image.
649 *
650 * The image is graylevel. Each pixel is unsigned and stored in
651 * eight bytes.
652 **/
653 OrthancPluginPixelFormat_Grayscale64 = 11,
654
655 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff
656 } OrthancPluginPixelFormat;
657
658
659
660 /**
661 * The content types that are supported by Orthanc plugins.
662 **/
663 typedef enum
664 {
665 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
666 OrthancPluginContentType_Dicom = 1, /*!< DICOM */
667 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */
668
669 _OrthancPluginContentType_INTERNAL = 0x7fffffff
670 } OrthancPluginContentType;
671
672
673
674 /**
675 * The supported types of DICOM resources.
676 **/
677 typedef enum
678 {
679 OrthancPluginResourceType_Patient = 0, /*!< Patient */
680 OrthancPluginResourceType_Study = 1, /*!< Study */
681 OrthancPluginResourceType_Series = 2, /*!< Series */
682 OrthancPluginResourceType_Instance = 3, /*!< Instance */
683 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */
684
685 _OrthancPluginResourceType_INTERNAL = 0x7fffffff
686 } OrthancPluginResourceType;
687
688
689
690 /**
691 * The supported types of changes that can happen to DICOM resources.
692 * @ingroup Callbacks
693 **/
694 typedef enum
695 {
696 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */
697 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */
698 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */
699 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */
700 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */
701 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */
702 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */
703 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */
704 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */
705 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */
706 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */
707 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */
708 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */
709 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */
710 OrthancPluginChangeType_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */
711 OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */
712
713 _OrthancPluginChangeType_INTERNAL = 0x7fffffff
714 } OrthancPluginChangeType;
715
716
717 /**
718 * The compression algorithms that are supported by the Orthanc core.
719 * @ingroup Images
720 **/
721 typedef enum
722 {
723 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */
724 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */
725 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */
726 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */
727
728 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff
729 } OrthancPluginCompressionType;
730
731
732 /**
733 * The image formats that are supported by the Orthanc core.
734 * @ingroup Images
735 **/
736 typedef enum
737 {
738 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */
739 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */
740 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */
741
742 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff
743 } OrthancPluginImageFormat;
744
745
746 /**
747 * The value representations present in the DICOM standard (version 2013).
748 * @ingroup Toolbox
749 **/
750 typedef enum
751 {
752 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */
753 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */
754 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */
755 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */
756 OrthancPluginValueRepresentation_DA = 5, /*!< Date */
757 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */
758 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */
759 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */
760 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */
761 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */
762 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */
763 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */
764 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */
765 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */
766 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */
767 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */
768 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */
769 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */
770 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */
771 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */
772 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */
773 OrthancPluginValueRepresentation_TM = 22, /*!< Time */
774 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */
775 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */
776 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */
777 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */
778 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */
779
780 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff
781 } OrthancPluginValueRepresentation;
782
783
784 /**
785 * The possible output formats for a DICOM-to-JSON conversion.
786 * @ingroup Toolbox
787 * @see OrthancPluginDicomToJson()
788 **/
789 typedef enum
790 {
791 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */
792 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */
793 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */
794
795 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff
796 } OrthancPluginDicomToJsonFormat;
797
798
799 /**
800 * Flags to customize a DICOM-to-JSON conversion. By default, binary
801 * tags are formatted using Data URI scheme.
802 * @ingroup Toolbox
803 **/
804 typedef enum
805 {
806 OrthancPluginDicomToJsonFlags_None = 0,
807 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */
808 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */
809 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */
810 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */
811 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */
812 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */
813
814 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff
815 } OrthancPluginDicomToJsonFlags;
816
817
818 /**
819 * Flags to the creation of a DICOM file.
820 * @ingroup Toolbox
821 * @see OrthancPluginCreateDicom()
822 **/
823 typedef enum
824 {
825 OrthancPluginCreateDicomFlags_None = 0,
826 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */
827 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */
828
829 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff
830 } OrthancPluginCreateDicomFlags;
831
832
833 /**
834 * The constraints on the DICOM identifiers that must be supported
835 * by the database plugins.
836 * @deprecated Plugins using OrthancPluginConstraintType will be faster
837 **/
838 typedef enum
839 {
840 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */
841 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */
842 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */
843 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */
844
845 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff
846 } OrthancPluginIdentifierConstraint;
847
848
849 /**
850 * The constraints on the tags (main DICOM tags and identifier tags)
851 * that must be supported by the database plugins.
852 **/
853 typedef enum
854 {
855 OrthancPluginConstraintType_Equal = 1, /*!< Equal */
856 OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */
857 OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */
858 OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */
859 OrthancPluginConstraintType_List = 5, /*!< List of values */
860
861 _OrthancPluginConstraintType_INTERNAL = 0x7fffffff
862 } OrthancPluginConstraintType;
863
864
865 /**
866 * The origin of a DICOM instance that has been received by Orthanc.
867 **/
868 typedef enum
869 {
870 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */
871 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */
872 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */
873 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */
874 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */
875
876 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff
877 } OrthancPluginInstanceOrigin;
878
879
880 /**
881 * The possible status for one single step of a job.
882 **/
883 typedef enum
884 {
885 OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */
886 OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */
887 OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */
888 } OrthancPluginJobStepStatus;
889
890
891 /**
892 * Explains why the job should stop and release the resources it has
893 * allocated. This is especially important to disambiguate between
894 * the "paused" condition and the "final" conditions (success,
895 * failure, or canceled).
896 **/
897 typedef enum
898 {
899 OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */
900 OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */
901 OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */
902 OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */
903 } OrthancPluginJobStopReason;
904
905
906 /**
907 * The available types of metrics.
908 **/
909 typedef enum
910 {
911 OrthancPluginMetricsType_Default, /*!< Default metrics */
912
913 /**
914 * This metrics represents a time duration. Orthanc will keep the
915 * maximum value of the metrics over a sliding window of ten
916 * seconds, which is useful if the metrics is sampled frequently.
917 **/
918 OrthancPluginMetricsType_Timer
919 } OrthancPluginMetricsType;
920
921
922 /**
923 * The available modes to export a binary DICOM tag into a DICOMweb
924 * JSON or XML document.
925 **/
926 typedef enum
927 {
928 OrthancPluginDicomWebBinaryMode_Ignore, /*!< Don't include binary tags */
929 OrthancPluginDicomWebBinaryMode_InlineBinary, /*!< Inline encoding using Base64 */
930 OrthancPluginDicomWebBinaryMode_BulkDataUri /*!< Use a bulk data URI field */
931 } OrthancPluginDicomWebBinaryMode;
932
933
934
935 /**
936 * @brief A memory buffer allocated by the core system of Orthanc.
937 *
938 * A memory buffer allocated by the core system of Orthanc. When the
939 * content of the buffer is not useful anymore, it must be free by a
940 * call to ::OrthancPluginFreeMemoryBuffer().
941 **/
942 typedef struct
943 {
944 /**
945 * @brief The content of the buffer.
946 **/
947 void* data;
948
949 /**
950 * @brief The number of bytes in the buffer.
951 **/
952 uint32_t size;
953 } OrthancPluginMemoryBuffer;
954
955
956
957
958 /**
959 * @brief Opaque structure that represents the HTTP connection to the client application.
960 * @ingroup Callback
961 **/
962 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
963
964
965
966 /**
967 * @brief Opaque structure that represents a DICOM instance received by Orthanc.
968 **/
969 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
970
971
972
973 /**
974 * @brief Opaque structure that represents an image that is uncompressed in memory.
975 * @ingroup Images
976 **/
977 typedef struct _OrthancPluginImage_t OrthancPluginImage;
978
979
980
981 /**
982 * @brief Opaque structure that represents the storage area that is actually used by Orthanc.
983 * @ingroup Images
984 **/
985 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea;
986
987
988
989 /**
990 * @brief Opaque structure to an object that represents a C-Find query for worklists.
991 * @ingroup DicomCallbacks
992 **/
993 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery;
994
995
996
997 /**
998 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
999 * @ingroup DicomCallbacks
1000 **/
1001 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers;
1002
1003
1004
1005 /**
1006 * @brief Opaque structure to an object that represents a C-Find query.
1007 * @ingroup DicomCallbacks
1008 **/
1009 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery;
1010
1011
1012
1013 /**
1014 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
1015 * @ingroup DicomCallbacks
1016 **/
1017 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers;
1018
1019
1020
1021 /**
1022 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query.
1023 * @ingroup Toolbox
1024 **/
1025 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindMatcher;
1026
1027
1028
1029 /**
1030 * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server.
1031 * @ingroup Toolbox
1032 **/
1033 typedef struct _OrthancPluginPeers_t OrthancPluginPeers;
1034
1035
1036
1037 /**
1038 * @brief Opaque structure to a job to be executed by Orthanc.
1039 * @ingroup Toolbox
1040 **/
1041 typedef struct _OrthancPluginJob_t OrthancPluginJob;
1042
1043
1044
1045 /**
1046 * @brief Opaque structure that represents a node in a JSON or XML
1047 * document used in DICOMweb.
1048 * @ingroup Toolbox
1049 **/
1050 typedef struct _OrthancPluginDicomWebNode_t OrthancPluginDicomWebNode;
1051
1052
1053
1054 /**
1055 * @brief Signature of a callback function that answers to a REST request.
1056 * @ingroup Callbacks
1057 **/
1058 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) (
1059 OrthancPluginRestOutput* output,
1060 const char* url,
1061 const OrthancPluginHttpRequest* request);
1062
1063
1064
1065 /**
1066 * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance.
1067 * @ingroup Callbacks
1068 **/
1069 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) (
1070 OrthancPluginDicomInstance* instance,
1071 const char* instanceId);
1072
1073
1074
1075 /**
1076 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
1077 * @ingroup Callbacks
1078 **/
1079 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) (
1080 OrthancPluginChangeType changeType,
1081 OrthancPluginResourceType resourceType,
1082 const char* resourceId);
1083
1084
1085
1086 /**
1087 * @brief Signature of a callback function to decode a DICOM instance as an image.
1088 * @ingroup Callbacks
1089 **/
1090 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) (
1091 OrthancPluginImage** target,
1092 const void* dicom,
1093 const uint32_t size,
1094 uint32_t frameIndex);
1095
1096
1097
1098 /**
1099 * @brief Signature of a function to free dynamic memory.
1100 * @ingroup Callbacks
1101 **/
1102 typedef void (*OrthancPluginFree) (void* buffer);
1103
1104
1105
1106 /**
1107 * @brief Signature of a function to set the content of a node
1108 * encoding a binary DICOM tag, into a JSON or XML document
1109 * generated for DICOMweb.
1110 * @ingroup Callbacks
1111 **/
1112 typedef void (*OrthancPluginDicomWebSetBinaryNode) (
1113 OrthancPluginDicomWebNode* node,
1114 OrthancPluginDicomWebBinaryMode mode,
1115 const char* bulkDataUri);
1116
1117
1118
1119 /**
1120 * @brief Callback for writing to the storage area.
1121 *
1122 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
1123 *
1124 * @param uuid The UUID of the file.
1125 * @param content The content of the file.
1126 * @param size The size of the file.
1127 * @param type The content type corresponding to this file.
1128 * @return 0 if success, other value if error.
1129 * @ingroup Callbacks
1130 **/
1131 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) (
1132 const char* uuid,
1133 const void* content,
1134 int64_t size,
1135 OrthancPluginContentType type);
1136
1137
1138
1139 /**
1140 * @brief Callback for reading from the storage area.
1141 *
1142 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
1143 *
1144 * @param content The content of the file (output).
1145 * @param size The size of the file (output).
1146 * @param uuid The UUID of the file of interest.
1147 * @param type The content type corresponding to this file.
1148 * @return 0 if success, other value if error.
1149 * @ingroup Callbacks
1150 **/
1151 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) (
1152 void** content,
1153 int64_t* size,
1154 const char* uuid,
1155 OrthancPluginContentType type);
1156
1157
1158
1159 /**
1160 * @brief Callback for removing a file from the storage area.
1161 *
1162 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
1163 *
1164 * @param uuid The UUID of the file to be removed.
1165 * @param type The content type corresponding to this file.
1166 * @return 0 if success, other value if error.
1167 * @ingroup Callbacks
1168 **/
1169 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) (
1170 const char* uuid,
1171 OrthancPluginContentType type);
1172
1173
1174
1175 /**
1176 * @brief Callback to handle the C-Find SCP requests for worklists.
1177 *
1178 * Signature of a callback function that is triggered when Orthanc
1179 * receives a C-Find SCP request against modality worklists.
1180 *
1181 * @param answers The target structure where answers must be stored.
1182 * @param query The worklist query.
1183 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1184 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1185 * @return 0 if success, other value if error.
1186 * @ingroup DicomCallbacks
1187 **/
1188 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) (
1189 OrthancPluginWorklistAnswers* answers,
1190 const OrthancPluginWorklistQuery* query,
1191 const char* issuerAet,
1192 const char* calledAet);
1193
1194
1195
1196 /**
1197 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1198 *
1199 * Signature of a callback function that is triggered whenever
1200 * Orthanc receives an HTTP/REST request, and that answers whether
1201 * this request should be allowed. If the callback returns "0"
1202 * ("false"), the server answers with HTTP status code 403
1203 * (Forbidden).
1204 *
1205 * @param method The HTTP method used by the request.
1206 * @param uri The URI of interest.
1207 * @param ip The IP address of the HTTP client.
1208 * @param headersCount The number of HTTP headers.
1209 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1210 * @param headersValues The values of the HTTP headers.
1211 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1212 * @ingroup Callback
1213 * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2()
1214 **/
1215 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) (
1216 OrthancPluginHttpMethod method,
1217 const char* uri,
1218 const char* ip,
1219 uint32_t headersCount,
1220 const char* const* headersKeys,
1221 const char* const* headersValues);
1222
1223
1224
1225 /**
1226 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1227 *
1228 * Signature of a callback function that is triggered whenever
1229 * Orthanc receives an HTTP/REST request, and that answers whether
1230 * this request should be allowed. If the callback returns "0"
1231 * ("false"), the server answers with HTTP status code 403
1232 * (Forbidden).
1233 *
1234 * @param method The HTTP method used by the request.
1235 * @param uri The URI of interest.
1236 * @param ip The IP address of the HTTP client.
1237 * @param headersCount The number of HTTP headers.
1238 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1239 * @param headersValues The values of the HTTP headers.
1240 * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method).
1241 * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method).
1242 * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method).
1243 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1244 * @ingroup Callback
1245 **/
1246 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) (
1247 OrthancPluginHttpMethod method,
1248 const char* uri,
1249 const char* ip,
1250 uint32_t headersCount,
1251 const char* const* headersKeys,
1252 const char* const* headersValues,
1253 uint32_t getArgumentsCount,
1254 const char* const* getArgumentsKeys,
1255 const char* const* getArgumentsValues);
1256
1257
1258
1259 /**
1260 * @brief Callback to handle incoming C-Find SCP requests.
1261 *
1262 * Signature of a callback function that is triggered whenever
1263 * Orthanc receives a C-Find SCP request not concerning modality
1264 * worklists.
1265 *
1266 * @param answers The target structure where answers must be stored.
1267 * @param query The worklist query.
1268 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1269 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1270 * @return 0 if success, other value if error.
1271 * @ingroup DicomCallbacks
1272 **/
1273 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) (
1274 OrthancPluginFindAnswers* answers,
1275 const OrthancPluginFindQuery* query,
1276 const char* issuerAet,
1277 const char* calledAet);
1278
1279
1280
1281 /**
1282 * @brief Callback to handle incoming C-Move SCP requests.
1283 *
1284 * Signature of a callback function that is triggered whenever
1285 * Orthanc receives a C-Move SCP request. The callback receives the
1286 * type of the resource of interest (study, series, instance...)
1287 * together with the DICOM tags containing its identifiers. In turn,
1288 * the plugin must create a driver object that will be responsible
1289 * for driving the successive move suboperations.
1290 *
1291 * @param resourceType The type of the resource of interest. Note
1292 * that this might be set to ResourceType_None if the
1293 * QueryRetrieveLevel (0008,0052) tag was not provided by the
1294 * issuer (i.e. the originator modality).
1295 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL.
1296 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL.
1297 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL.
1298 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL.
1299 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL.
1300 * @param originatorAet The Application Entity Title (AET) of the
1301 * modality from which the request originates.
1302 * @param sourceAet The Application Entity Title (AET) of the
1303 * modality that should send its DICOM files to another modality.
1304 * @param targetAet The Application Entity Title (AET) of the
1305 * modality that should receive the DICOM files.
1306 * @param originatorId The Message ID issued by the originator modality,
1307 * as found in tag (0000,0110) of the DICOM query emitted by the issuer.
1308 *
1309 * @return The NULL value if the plugin cannot deal with this query,
1310 * or a pointer to the driver object that is responsible for
1311 * handling the successive move suboperations.
1312 *
1313 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation.
1314 * @ingroup DicomCallbacks
1315 **/
1316 typedef void* (*OrthancPluginMoveCallback) (
1317 OrthancPluginResourceType resourceType,
1318 const char* patientId,
1319 const char* accessionNumber,
1320 const char* studyInstanceUid,
1321 const char* seriesInstanceUid,
1322 const char* sopInstanceUid,
1323 const char* originatorAet,
1324 const char* sourceAet,
1325 const char* targetAet,
1326 uint16_t originatorId);
1327
1328
1329 /**
1330 * @brief Callback to read the size of a C-Move driver.
1331 *
1332 * Signature of a callback function that returns the number of
1333 * C-Move suboperations that are to be achieved by the given C-Move
1334 * driver. This driver is the return value of a previous call to the
1335 * OrthancPluginMoveCallback() callback.
1336 *
1337 * @param moveDriver The C-Move driver of interest.
1338 * @return The number of suboperations.
1339 * @ingroup DicomCallbacks
1340 **/
1341 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver);
1342
1343
1344 /**
1345 * @brief Callback to apply one C-Move suboperation.
1346 *
1347 * Signature of a callback function that applies the next C-Move
1348 * suboperation that os to be achieved by the given C-Move
1349 * driver. This driver is the return value of a previous call to the
1350 * OrthancPluginMoveCallback() callback.
1351 *
1352 * @param moveDriver The C-Move driver of interest.
1353 * @return 0 if success, or the error code if failure.
1354 * @ingroup DicomCallbacks
1355 **/
1356 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver);
1357
1358
1359 /**
1360 * @brief Callback to free one C-Move driver.
1361 *
1362 * Signature of a callback function that releases the resources
1363 * allocated by the given C-Move driver. This driver is the return
1364 * value of a previous call to the OrthancPluginMoveCallback()
1365 * callback.
1366 *
1367 * @param moveDriver The C-Move driver of interest.
1368 * @ingroup DicomCallbacks
1369 **/
1370 typedef void (*OrthancPluginFreeMove) (void* moveDriver);
1371
1372
1373 /**
1374 * @brief Callback to finalize one custom job.
1375 *
1376 * Signature of a callback function that releases all the resources
1377 * allocated by the given job. This job is the argument provided to
1378 * OrthancPluginCreateJob().
1379 *
1380 * @param job The job of interest.
1381 * @ingroup Toolbox
1382 **/
1383 typedef void (*OrthancPluginJobFinalize) (void* job);
1384
1385
1386 /**
1387 * @brief Callback to check the progress of one custom job.
1388 *
1389 * Signature of a callback function that returns the progress of the
1390 * job.
1391 *
1392 * @param job The job of interest.
1393 * @return The progress, as a floating-point number ranging from 0 to 1.
1394 * @ingroup Toolbox
1395 **/
1396 typedef float (*OrthancPluginJobGetProgress) (void* job);
1397
1398
1399 /**
1400 * @brief Callback to retrieve the content of one custom job.
1401 *
1402 * Signature of a callback function that returns human-readable
1403 * statistics about the job. This statistics must be formatted as a
1404 * JSON object. This information is notably displayed in the "Jobs"
1405 * tab of "Orthanc Explorer".
1406 *
1407 * @param job The job of interest.
1408 * @return The statistics, as a JSON object encoded as a string.
1409 * @ingroup Toolbox
1410 **/
1411 typedef const char* (*OrthancPluginJobGetContent) (void* job);
1412
1413
1414 /**
1415 * @brief Callback to serialize one custom job.
1416 *
1417 * Signature of a callback function that returns a serialized
1418 * version of the job, formatted as a JSON object. This
1419 * serialization is stored in the Orthanc database, and is used to
1420 * reload the job on the restart of Orthanc. The "unserialization"
1421 * callback (with OrthancPluginJobsUnserializer signature) will
1422 * receive this serialized object.
1423 *
1424 * @param job The job of interest.
1425 * @return The serialized job, as a JSON object encoded as a string.
1426 * @see OrthancPluginRegisterJobsUnserializer()
1427 * @ingroup Toolbox
1428 **/
1429 typedef const char* (*OrthancPluginJobGetSerialized) (void* job);
1430
1431
1432 /**
1433 * @brief Callback to execute one step of a custom job.
1434 *
1435 * Signature of a callback function that executes one step in the
1436 * job. The jobs engine of Orthanc will make successive calls to
1437 * this method, as long as it returns
1438 * OrthancPluginJobStepStatus_Continue.
1439 *
1440 * @param job The job of interest.
1441 * @return The status of execution.
1442 * @ingroup Toolbox
1443 **/
1444 typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job);
1445
1446
1447 /**
1448 * @brief Callback executed once one custom job leaves the "running" state.
1449 *
1450 * Signature of a callback function that is invoked once a job
1451 * leaves the "running" state. This can happen if the previous call
1452 * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc
1453 * server is being stopped, or if the user manually tags the job as
1454 * paused/canceled. This callback allows the plugin to free
1455 * resources allocated for running this custom job (e.g. to stop
1456 * threads, or to remove temporary files).
1457 *
1458 * Note that handling pauses might involves a specific treatment
1459 * (such a stopping threads, but keeping temporary files on the
1460 * disk). This "paused" situation can be checked by looking at the
1461 * "reason" parameter.
1462 *
1463 * @param job The job of interest.
1464 * @param reason The reason for leaving the "running" state.
1465 * @return 0 if success, or the error code if failure.
1466 * @ingroup Toolbox
1467 **/
1468 typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job,
1469 OrthancPluginJobStopReason reason);
1470
1471
1472 /**
1473 * @brief Callback executed once one stopped custom job is started again.
1474 *
1475 * Signature of a callback function that is invoked once a job
1476 * leaves the "failure/canceled" state, to be started again. This
1477 * function will typically reset the progress to zero. Note that
1478 * before being actually executed, the job would first be tagged as
1479 * "pending" in the Orthanc jobs engine.
1480 *
1481 * @param job The job of interest.
1482 * @return 0 if success, or the error code if failure.
1483 * @ingroup Toolbox
1484 **/
1485 typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job);
1486
1487
1488 /**
1489 * @brief Callback executed to unserialize a custom job.
1490 *
1491 * Signature of a callback function that unserializes a job that was
1492 * saved in the Orthanc database.
1493 *
1494 * @param jobType The type of the job, as provided to OrthancPluginCreateJob().
1495 * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized.
1496 * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL
1497 * if this unserializer cannot handle this job type.
1498 * @see OrthancPluginRegisterJobsUnserializer()
1499 * @ingroup Callbacks
1500 **/
1501 typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType,
1502 const char* serialized);
1503
1504
1505
1506 /**
1507 * @brief Callback executed to update the metrics of the plugin.
1508 *
1509 * Signature of a callback function that is called by Orthanc
1510 * whenever a monitoring tool (such as Prometheus) asks the current
1511 * values of the metrics. This callback gives the plugin a chance to
1512 * update its metrics, by calling OrthancPluginSetMetricsValue().
1513 * This is typically useful for metrics that are expensive to
1514 * acquire.
1515 *
1516 * @see OrthancPluginRegisterRefreshMetrics()
1517 * @ingroup Callbacks
1518 **/
1519 typedef void (*OrthancPluginRefreshMetricsCallback) ();
1520
1521
1522
1523 /**
1524 * @brief Callback executed to encode a binary tag in DICOMweb.
1525 *
1526 * Signature of a callback function that is called by Orthanc
1527 * whenever a DICOM tag that contains a binary value must be written
1528 * to a JSON or XML node, while a DICOMweb document is being
1529 * generated. The value representation (VR) of the DICOM tag can be
1530 * OB, OD, OF, OL, OW, or UN.
1531 *
1532 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
1533 * @param node The node being generated, as provided by Orthanc.
1534 * @param setter The setter to be used to encode the content of the node. If
1535 * the setter is not called, the binary tag is not written to the output document.
1536 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences.
1537 * This parameter gives the number of elements in the "levelTagGroup",
1538 * "levelTagElement", and "levelIndex" arrays.
1539 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy.
1540 * @param levelTagElement The element of the parent DICOM tags in the hierarchy.
1541 * @param levelIndex The index of the node in the parent sequences of the hiearchy.
1542 * @param tagGroup The group of the DICOM tag of interest.
1543 * @param tagElement The element of the DICOM tag of interest.
1544 * @param vr The value representation of the binary DICOM node.
1545 * @ingroup Callbacks
1546 **/
1547 typedef void (*OrthancPluginDicomWebBinaryCallback) (
1548 OrthancPluginDicomWebNode* node,
1549 OrthancPluginDicomWebSetBinaryNode setter,
1550 uint32_t levelDepth,
1551 const uint16_t* levelTagGroup,
1552 const uint16_t* levelTagElement,
1553 const uint32_t* levelIndex,
1554 uint16_t tagGroup,
1555 uint16_t tagElement,
1556 OrthancPluginValueRepresentation vr);
1557
1558
1559
1560 /**
1561 * @brief Data structure that contains information about the Orthanc core.
1562 **/
1563 typedef struct _OrthancPluginContext_t
1564 {
1565 void* pluginsManager;
1566 const char* orthancVersion;
1567 OrthancPluginFree Free;
1568 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context,
1569 _OrthancPluginService service,
1570 const void* params);
1571 } OrthancPluginContext;
1572
1573
1574
1575 /**
1576 * @brief An entry in the dictionary of DICOM tags.
1577 **/
1578 typedef struct
1579 {
1580 uint16_t group; /*!< The group of the tag */
1581 uint16_t element; /*!< The element of the tag */
1582 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */
1583 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */
1584 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */
1585 } OrthancPluginDictionaryEntry;
1586
1587
1588
1589 /**
1590 * @brief Free a string.
1591 *
1592 * Free a string that was allocated by the core system of Orthanc.
1593 *
1594 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1595 * @param str The string to be freed.
1596 **/
1597 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
1598 OrthancPluginContext* context,
1599 char* str)
1600 {
1601 if (str != NULL)
1602 {
1603 context->Free(str);
1604 }
1605 }
1606
1607
1608 /**
1609 * @brief Check that the version of the hosting Orthanc is above a given version.
1610 *
1611 * This function checks whether the version of the Orthanc server
1612 * running this plugin, is above the given version. Contrarily to
1613 * OrthancPluginCheckVersion(), it is up to the developer of the
1614 * plugin to make sure that all the Orthanc SDK services called by
1615 * the plugin are actually implemented in the given version of
1616 * Orthanc.
1617 *
1618 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1619 * @param expectedMajor Expected major version.
1620 * @param expectedMinor Expected minor version.
1621 * @param expectedRevision Expected revision.
1622 * @return 1 if and only if the versions are compatible. If the
1623 * result is 0, the initialization of the plugin should fail.
1624 * @see OrthancPluginCheckVersion
1625 * @ingroup Callbacks
1626 **/
1627 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersionAdvanced(
1628 OrthancPluginContext* context,
1629 int expectedMajor,
1630 int expectedMinor,
1631 int expectedRevision)
1632 {
1633 int major, minor, revision;
1634
1635 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
1636 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
1637 sizeof(int32_t) != sizeof(_OrthancPluginService) ||
1638 sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
1639 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
1640 sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
1641 sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
1642 sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
1643 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
1644 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) ||
1645 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
1646 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
1647 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
1648 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) ||
1649 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
1650 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
1651 sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) ||
1652 sizeof(int32_t) != sizeof(OrthancPluginConstraintType) ||
1653 sizeof(int32_t) != sizeof(OrthancPluginMetricsType) ||
1654 sizeof(int32_t) != sizeof(OrthancPluginDicomWebBinaryMode))
1655 {
1656 /* Mismatch in the size of the enumerations */
1657 return 0;
1658 }
1659
1660 /* Assume compatibility with the mainline */
1661 if (!strcmp(context->orthancVersion, "mainline"))
1662 {
1663 return 1;
1664 }
1665
1666 /* Parse the version of the Orthanc core */
1667 if (
1668 #ifdef _MSC_VER
1669 sscanf_s
1670 #else
1671 sscanf
1672 #endif
1673 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3)
1674 {
1675 return 0;
1676 }
1677
1678 /* Check the major number of the version */
1679
1680 if (major > expectedMajor)
1681 {
1682 return 1;
1683 }
1684
1685 if (major < expectedMajor)
1686 {
1687 return 0;
1688 }
1689
1690 /* Check the minor number of the version */
1691
1692 if (minor > expectedMinor)
1693 {
1694 return 1;
1695 }
1696
1697 if (minor < expectedMinor)
1698 {
1699 return 0;
1700 }
1701
1702 /* Check the revision number of the version */
1703
1704 if (revision >= expectedRevision)
1705 {
1706 return 1;
1707 }
1708 else
1709 {
1710 return 0;
1711 }
1712 }
1713
1714
1715 /**
1716 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
1717 *
1718 * This function checks whether the version of the Orthanc server
1719 * running this plugin, is above the version of the current Orthanc
1720 * SDK header. This guarantees that the plugin is compatible with
1721 * the hosting Orthanc (i.e. it will not call unavailable services).
1722 * The result of this function should always be checked in the
1723 * OrthancPluginInitialize() entry point of the plugin.
1724 *
1725 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1726 * @return 1 if and only if the versions are compatible. If the
1727 * result is 0, the initialization of the plugin should fail.
1728 * @see OrthancPluginCheckVersionAdvanced
1729 * @ingroup Callbacks
1730 **/
1731 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion(
1732 OrthancPluginContext* context)
1733 {
1734 return OrthancPluginCheckVersionAdvanced(
1735 context,
1736 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
1737 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
1738 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1739 }
1740
1741
1742 /**
1743 * @brief Free a memory buffer.
1744 *
1745 * Free a memory buffer that was allocated by the core system of Orthanc.
1746 *
1747 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1748 * @param buffer The memory buffer to release.
1749 **/
1750 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
1751 OrthancPluginContext* context,
1752 OrthancPluginMemoryBuffer* buffer)
1753 {
1754 context->Free(buffer->data);
1755 }
1756
1757
1758 /**
1759 * @brief Log an error.
1760 *
1761 * Log an error message using the Orthanc logging system.
1762 *
1763 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1764 * @param message The message to be logged.
1765 **/
1766 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
1767 OrthancPluginContext* context,
1768 const char* message)
1769 {
1770 context->InvokeService(context, _OrthancPluginService_LogError, message);
1771 }
1772
1773
1774 /**
1775 * @brief Log a warning.
1776 *
1777 * Log a warning message using the Orthanc logging system.
1778 *
1779 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1780 * @param message The message to be logged.
1781 **/
1782 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
1783 OrthancPluginContext* context,
1784 const char* message)
1785 {
1786 context->InvokeService(context, _OrthancPluginService_LogWarning, message);
1787 }
1788
1789
1790 /**
1791 * @brief Log an information.
1792 *
1793 * Log an information message using the Orthanc logging system.
1794 *
1795 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1796 * @param message The message to be logged.
1797 **/
1798 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
1799 OrthancPluginContext* context,
1800 const char* message)
1801 {
1802 context->InvokeService(context, _OrthancPluginService_LogInfo, message);
1803 }
1804
1805
1806
1807 typedef struct
1808 {
1809 const char* pathRegularExpression;
1810 OrthancPluginRestCallback callback;
1811 } _OrthancPluginRestCallback;
1812
1813 /**
1814 * @brief Register a REST callback.
1815 *
1816 * This function registers a REST callback against a regular
1817 * expression for a URI. This function must be called during the
1818 * initialization of the plugin, i.e. inside the
1819 * OrthancPluginInitialize() public function.
1820 *
1821 * Each REST callback is guaranteed to run in mutual exclusion.
1822 *
1823 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1824 * @param pathRegularExpression Regular expression for the URI. May contain groups.
1825 * @param callback The callback function to handle the REST call.
1826 * @see OrthancPluginRegisterRestCallbackNoLock()
1827 *
1828 * @note
1829 * The regular expression is case sensitive and must follow the
1830 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
1831 *
1832 * @ingroup Callbacks
1833 **/
1834 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
1835 OrthancPluginContext* context,
1836 const char* pathRegularExpression,
1837 OrthancPluginRestCallback callback)
1838 {
1839 _OrthancPluginRestCallback params;
1840 params.pathRegularExpression = pathRegularExpression;
1841 params.callback = callback;
1842 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, &params);
1843 }
1844
1845
1846
1847 /**
1848 * @brief Register a REST callback, without locking.
1849 *
1850 * This function registers a REST callback against a regular
1851 * expression for a URI. This function must be called during the
1852 * initialization of the plugin, i.e. inside the
1853 * OrthancPluginInitialize() public function.
1854 *
1855 * Contrarily to OrthancPluginRegisterRestCallback(), the callback
1856 * will NOT be invoked in mutual exclusion. This can be useful for
1857 * high-performance plugins that must handle concurrent requests
1858 * (Orthanc uses a pool of threads, one thread being assigned to
1859 * each incoming HTTP request). Of course, if using this function,
1860 * it is up to the plugin to implement the required locking
1861 * mechanisms.
1862 *
1863 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1864 * @param pathRegularExpression Regular expression for the URI. May contain groups.
1865 * @param callback The callback function to handle the REST call.
1866 * @see OrthancPluginRegisterRestCallback()
1867 *
1868 * @note
1869 * The regular expression is case sensitive and must follow the
1870 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
1871 *
1872 * @ingroup Callbacks
1873 **/
1874 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock(
1875 OrthancPluginContext* context,
1876 const char* pathRegularExpression,
1877 OrthancPluginRestCallback callback)
1878 {
1879 _OrthancPluginRestCallback params;
1880 params.pathRegularExpression = pathRegularExpression;
1881 params.callback = callback;
1882 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, &params);
1883 }
1884
1885
1886
1887 typedef struct
1888 {
1889 OrthancPluginOnStoredInstanceCallback callback;
1890 } _OrthancPluginOnStoredInstanceCallback;
1891
1892 /**
1893 * @brief Register a callback for received instances.
1894 *
1895 * This function registers a callback function that is called
1896 * whenever a new DICOM instance is stored into the Orthanc core.
1897 *
1898 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1899 * @param callback The callback function.
1900 * @ingroup Callbacks
1901 **/
1902 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
1903 OrthancPluginContext* context,
1904 OrthancPluginOnStoredInstanceCallback callback)
1905 {
1906 _OrthancPluginOnStoredInstanceCallback params;
1907 params.callback = callback;
1908
1909 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, &params);
1910 }
1911
1912
1913
1914 typedef struct
1915 {
1916 OrthancPluginRestOutput* output;
1917 const char* answer;
1918 uint32_t answerSize;
1919 const char* mimeType;
1920 } _OrthancPluginAnswerBuffer;
1921
1922 /**
1923 * @brief Answer to a REST request.
1924 *
1925 * This function answers to a REST request with the content of a memory buffer.
1926 *
1927 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1928 * @param output The HTTP connection to the client application.
1929 * @param answer Pointer to the memory buffer containing the answer.
1930 * @param answerSize Number of bytes of the answer.
1931 * @param mimeType The MIME type of the answer.
1932 * @ingroup REST
1933 **/
1934 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
1935 OrthancPluginContext* context,
1936 OrthancPluginRestOutput* output,
1937 const char* answer,
1938 uint32_t answerSize,
1939 const char* mimeType)
1940 {
1941 _OrthancPluginAnswerBuffer params;
1942 params.output = output;
1943 params.answer = answer;
1944 params.answerSize = answerSize;
1945 params.mimeType = mimeType;
1946 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, &params);
1947 }
1948
1949
1950 typedef struct
1951 {
1952 OrthancPluginRestOutput* output;
1953 OrthancPluginPixelFormat format;
1954 uint32_t width;
1955 uint32_t height;
1956 uint32_t pitch;
1957 const void* buffer;
1958 } _OrthancPluginCompressAndAnswerPngImage;
1959
1960 typedef struct
1961 {
1962 OrthancPluginRestOutput* output;
1963 OrthancPluginImageFormat imageFormat;
1964 OrthancPluginPixelFormat pixelFormat;
1965 uint32_t width;
1966 uint32_t height;
1967 uint32_t pitch;
1968 const void* buffer;
1969 uint8_t quality;
1970 } _OrthancPluginCompressAndAnswerImage;
1971
1972
1973 /**
1974 * @brief Answer to a REST request with a PNG image.
1975 *
1976 * This function answers to a REST request with a PNG image. The
1977 * parameters of this function describe a memory buffer that
1978 * contains an uncompressed image. The image will be automatically compressed
1979 * as a PNG image by the core system of Orthanc.
1980 *
1981 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1982 * @param output The HTTP connection to the client application.
1983 * @param format The memory layout of the uncompressed image.
1984 * @param width The width of the image.
1985 * @param height The height of the image.
1986 * @param pitch The pitch of the image (i.e. the number of bytes
1987 * between 2 successive lines of the image in the memory buffer).
1988 * @param buffer The memory buffer containing the uncompressed image.
1989 * @ingroup REST
1990 **/
1991 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
1992 OrthancPluginContext* context,
1993 OrthancPluginRestOutput* output,
1994 OrthancPluginPixelFormat format,
1995 uint32_t width,
1996 uint32_t height,
1997 uint32_t pitch,
1998 const void* buffer)
1999 {
2000 _OrthancPluginCompressAndAnswerImage params;
2001 params.output = output;
2002 params.imageFormat = OrthancPluginImageFormat_Png;
2003 params.pixelFormat = format;
2004 params.width = width;
2005 params.height = height;
2006 params.pitch = pitch;
2007 params.buffer = buffer;
2008 params.quality = 0; /* No quality for PNG */
2009 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
2010 }
2011
2012
2013
2014 typedef struct
2015 {
2016 OrthancPluginMemoryBuffer* target;
2017 const char* instanceId;
2018 } _OrthancPluginGetDicomForInstance;
2019
2020 /**
2021 * @brief Retrieve a DICOM instance using its Orthanc identifier.
2022 *
2023 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM
2024 * file is stored into a newly allocated memory buffer.
2025 *
2026 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2027 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2028 * @param instanceId The Orthanc identifier of the DICOM instance of interest.
2029 * @return 0 if success, or the error code if failure.
2030 * @ingroup Orthanc
2031 **/
2032 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance(
2033 OrthancPluginContext* context,
2034 OrthancPluginMemoryBuffer* target,
2035 const char* instanceId)
2036 {
2037 _OrthancPluginGetDicomForInstance params;
2038 params.target = target;
2039 params.instanceId = instanceId;
2040 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, &params);
2041 }
2042
2043
2044
2045 typedef struct
2046 {
2047 OrthancPluginMemoryBuffer* target;
2048 const char* uri;
2049 } _OrthancPluginRestApiGet;
2050
2051 /**
2052 * @brief Make a GET call to the built-in Orthanc REST API.
2053 *
2054 * Make a GET call to the built-in Orthanc REST API. The result to
2055 * the query is stored into a newly allocated memory buffer.
2056 *
2057 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2058 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2059 * @param uri The URI in the built-in Orthanc API.
2060 * @return 0 if success, or the error code if failure.
2061 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2062 * @see OrthancPluginRestApiGetAfterPlugins
2063 * @ingroup Orthanc
2064 **/
2065 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet(
2066 OrthancPluginContext* context,
2067 OrthancPluginMemoryBuffer* target,
2068 const char* uri)
2069 {
2070 _OrthancPluginRestApiGet params;
2071 params.target = target;
2072 params.uri = uri;
2073 return context->InvokeService(context, _OrthancPluginService_RestApiGet, &params);
2074 }
2075
2076
2077
2078 /**
2079 * @brief Make a GET call to the REST API, as tainted by the plugins.
2080 *
2081 * Make a GET call to the Orthanc REST API, after all the plugins
2082 * are applied. In other words, if some plugin overrides or adds the
2083 * called URI to the built-in Orthanc REST API, this call will
2084 * return the result provided by this plugin. The result to the
2085 * query is stored into a newly allocated memory buffer.
2086 *
2087 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2088 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2089 * @param uri The URI in the built-in Orthanc API.
2090 * @return 0 if success, or the error code if failure.
2091 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2092 * @see OrthancPluginRestApiGet
2093 * @ingroup Orthanc
2094 **/
2095 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins(
2096 OrthancPluginContext* context,
2097 OrthancPluginMemoryBuffer* target,
2098 const char* uri)
2099 {
2100 _OrthancPluginRestApiGet params;
2101 params.target = target;
2102 params.uri = uri;
2103 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, &params);
2104 }
2105
2106
2107
2108 typedef struct
2109 {
2110 OrthancPluginMemoryBuffer* target;
2111 const char* uri;
2112 const void* body;
2113 uint32_t bodySize;
2114 } _OrthancPluginRestApiPostPut;
2115
2116 /**
2117 * @brief Make a POST call to the built-in Orthanc REST API.
2118 *
2119 * Make a POST call to the built-in Orthanc REST API. The result to
2120 * the query is stored into a newly allocated memory buffer.
2121 *
2122 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2123 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2124 * @param uri The URI in the built-in Orthanc API.
2125 * @param body The body of the POST request.
2126 * @param bodySize The size of the body.
2127 * @return 0 if success, or the error code if failure.
2128 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2129 * @see OrthancPluginRestApiPostAfterPlugins
2130 * @ingroup Orthanc
2131 **/
2132 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost(
2133 OrthancPluginContext* context,
2134 OrthancPluginMemoryBuffer* target,
2135 const char* uri,
2136 const void* body,
2137 uint32_t bodySize)
2138 {
2139 _OrthancPluginRestApiPostPut params;
2140 params.target = target;
2141 params.uri = uri;
2142 params.body = body;
2143 params.bodySize = bodySize;
2144 return context->InvokeService(context, _OrthancPluginService_RestApiPost, &params);
2145 }
2146
2147
2148 /**
2149 * @brief Make a POST call to the REST API, as tainted by the plugins.
2150 *
2151 * Make a POST call to the Orthanc REST API, after all the plugins
2152 * are applied. In other words, if some plugin overrides or adds the
2153 * called URI to the built-in Orthanc REST API, this call will
2154 * return the result provided by this plugin. The result to the
2155 * query is stored into a newly allocated memory buffer.
2156 *
2157 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2158 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2159 * @param uri The URI in the built-in Orthanc API.
2160 * @param body The body of the POST request.
2161 * @param bodySize The size of the body.
2162 * @return 0 if success, or the error code if failure.
2163 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2164 * @see OrthancPluginRestApiPost
2165 * @ingroup Orthanc
2166 **/
2167 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins(
2168 OrthancPluginContext* context,
2169 OrthancPluginMemoryBuffer* target,
2170 const char* uri,
2171 const void* body,
2172 uint32_t bodySize)
2173 {
2174 _OrthancPluginRestApiPostPut params;
2175 params.target = target;
2176 params.uri = uri;
2177 params.body = body;
2178 params.bodySize = bodySize;
2179 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, &params);
2180 }
2181
2182
2183
2184 /**
2185 * @brief Make a DELETE call to the built-in Orthanc REST API.
2186 *
2187 * Make a DELETE call to the built-in Orthanc REST API.
2188 *
2189 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2190 * @param uri The URI to delete in the built-in Orthanc API.
2191 * @return 0 if success, or the error code if failure.
2192 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2193 * @see OrthancPluginRestApiDeleteAfterPlugins
2194 * @ingroup Orthanc
2195 **/
2196 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete(
2197 OrthancPluginContext* context,
2198 const char* uri)
2199 {
2200 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
2201 }
2202
2203
2204 /**
2205 * @brief Make a DELETE call to the REST API, as tainted by the plugins.
2206 *
2207 * Make a DELETE call to the Orthanc REST API, after all the plugins
2208 * are applied. In other words, if some plugin overrides or adds the
2209 * called URI to the built-in Orthanc REST API, this call will
2210 * return the result provided by this plugin.
2211 *
2212 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2213 * @param uri The URI to delete in the built-in Orthanc API.
2214 * @return 0 if success, or the error code if failure.
2215 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2216 * @see OrthancPluginRestApiDelete
2217 * @ingroup Orthanc
2218 **/
2219 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins(
2220 OrthancPluginContext* context,
2221 const char* uri)
2222 {
2223 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri);
2224 }
2225
2226
2227
2228 /**
2229 * @brief Make a PUT call to the built-in Orthanc REST API.
2230 *
2231 * Make a PUT call to the built-in Orthanc REST API. The result to
2232 * the query is stored into a newly allocated memory buffer.
2233 *
2234 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2235 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2236 * @param uri The URI in the built-in Orthanc API.
2237 * @param body The body of the PUT request.
2238 * @param bodySize The size of the body.
2239 * @return 0 if success, or the error code if failure.
2240 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2241 * @see OrthancPluginRestApiPutAfterPlugins
2242 * @ingroup Orthanc
2243 **/
2244 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut(
2245 OrthancPluginContext* context,
2246 OrthancPluginMemoryBuffer* target,
2247 const char* uri,
2248 const void* body,
2249 uint32_t bodySize)
2250 {
2251 _OrthancPluginRestApiPostPut params;
2252 params.target = target;
2253 params.uri = uri;
2254 params.body = body;
2255 params.bodySize = bodySize;
2256 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
2257 }
2258
2259
2260
2261 /**
2262 * @brief Make a PUT call to the REST API, as tainted by the plugins.
2263 *
2264 * Make a PUT call to the Orthanc REST API, after all the plugins
2265 * are applied. In other words, if some plugin overrides or adds the
2266 * called URI to the built-in Orthanc REST API, this call will
2267 * return the result provided by this plugin. The result to the
2268 * query is stored into a newly allocated memory buffer.
2269 *
2270 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2271 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2272 * @param uri The URI in the built-in Orthanc API.
2273 * @param body The body of the PUT request.
2274 * @param bodySize The size of the body.
2275 * @return 0 if success, or the error code if failure.
2276 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2277 * @see OrthancPluginRestApiPut
2278 * @ingroup Orthanc
2279 **/
2280 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins(
2281 OrthancPluginContext* context,
2282 OrthancPluginMemoryBuffer* target,
2283 const char* uri,
2284 const void* body,
2285 uint32_t bodySize)
2286 {
2287 _OrthancPluginRestApiPostPut params;
2288 params.target = target;
2289 params.uri = uri;
2290 params.body = body;
2291 params.bodySize = bodySize;
2292 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, &params);
2293 }
2294
2295
2296
2297 typedef struct
2298 {
2299 OrthancPluginRestOutput* output;
2300 const char* argument;
2301 } _OrthancPluginOutputPlusArgument;
2302
2303 /**
2304 * @brief Redirect a REST request.
2305 *
2306 * This function answers to a REST request by redirecting the user
2307 * to another URI using HTTP status 301.
2308 *
2309 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2310 * @param output The HTTP connection to the client application.
2311 * @param redirection Where to redirect.
2312 * @ingroup REST
2313 **/
2314 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
2315 OrthancPluginContext* context,
2316 OrthancPluginRestOutput* output,
2317 const char* redirection)
2318 {
2319 _OrthancPluginOutputPlusArgument params;
2320 params.output = output;
2321 params.argument = redirection;
2322 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
2323 }
2324
2325
2326
2327 typedef struct
2328 {
2329 char** result;
2330 const char* argument;
2331 } _OrthancPluginRetrieveDynamicString;
2332
2333 /**
2334 * @brief Look for a patient.
2335 *
2336 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
2337 * This function uses the database index to run as fast as possible (it does not loop
2338 * over all the stored patients).
2339 *
2340 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2341 * @param patientID The Patient ID of interest.
2342 * @return The NULL value if the patient is non-existent, or a string containing the
2343 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
2344 * @ingroup Orthanc
2345 **/
2346 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
2347 OrthancPluginContext* context,
2348 const char* patientID)
2349 {
2350 char* result;
2351
2352 _OrthancPluginRetrieveDynamicString params;
2353 params.result = &result;
2354 params.argument = patientID;
2355
2356 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, &params) != OrthancPluginErrorCode_Success)
2357 {
2358 /* Error */
2359 return NULL;
2360 }
2361 else
2362 {
2363 return result;
2364 }
2365 }
2366
2367
2368 /**
2369 * @brief Look for a study.
2370 *
2371 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
2372 * This function uses the database index to run as fast as possible (it does not loop
2373 * over all the stored studies).
2374 *
2375 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2376 * @param studyUID The Study Instance UID of interest.
2377 * @return The NULL value if the study is non-existent, or a string containing the
2378 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2379 * @ingroup Orthanc
2380 **/
2381 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
2382 OrthancPluginContext* context,
2383 const char* studyUID)
2384 {
2385 char* result;
2386
2387 _OrthancPluginRetrieveDynamicString params;
2388 params.result = &result;
2389 params.argument = studyUID;
2390
2391 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, &params) != OrthancPluginErrorCode_Success)
2392 {
2393 /* Error */
2394 return NULL;
2395 }
2396 else
2397 {
2398 return result;
2399 }
2400 }
2401
2402
2403 /**
2404 * @brief Look for a study, using the accession number.
2405 *
2406 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
2407 * This function uses the database index to run as fast as possible (it does not loop
2408 * over all the stored studies).
2409 *
2410 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2411 * @param accessionNumber The Accession Number of interest.
2412 * @return The NULL value if the study is non-existent, or a string containing the
2413 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2414 * @ingroup Orthanc
2415 **/
2416 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
2417 OrthancPluginContext* context,
2418 const char* accessionNumber)
2419 {
2420 char* result;
2421
2422 _OrthancPluginRetrieveDynamicString params;
2423 params.result = &result;
2424 params.argument = accessionNumber;
2425
2426 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, &params) != OrthancPluginErrorCode_Success)
2427 {
2428 /* Error */
2429 return NULL;
2430 }
2431 else
2432 {
2433 return result;
2434 }
2435 }
2436
2437
2438 /**
2439 * @brief Look for a series.
2440 *
2441 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
2442 * This function uses the database index to run as fast as possible (it does not loop
2443 * over all the stored series).
2444 *
2445 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2446 * @param seriesUID The Series Instance UID of interest.
2447 * @return The NULL value if the series is non-existent, or a string containing the
2448 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
2449 * @ingroup Orthanc
2450 **/
2451 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
2452 OrthancPluginContext* context,
2453 const char* seriesUID)
2454 {
2455 char* result;
2456
2457 _OrthancPluginRetrieveDynamicString params;
2458 params.result = &result;
2459 params.argument = seriesUID;
2460
2461 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, &params) != OrthancPluginErrorCode_Success)
2462 {
2463 /* Error */
2464 return NULL;
2465 }
2466 else
2467 {
2468 return result;
2469 }
2470 }
2471
2472
2473 /**
2474 * @brief Look for an instance.
2475 *
2476 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
2477 * This function uses the database index to run as fast as possible (it does not loop
2478 * over all the stored instances).
2479 *
2480 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2481 * @param sopInstanceUID The SOP Instance UID of interest.
2482 * @return The NULL value if the instance is non-existent, or a string containing the
2483 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
2484 * @ingroup Orthanc
2485 **/
2486 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
2487 OrthancPluginContext* context,
2488 const char* sopInstanceUID)
2489 {
2490 char* result;
2491
2492 _OrthancPluginRetrieveDynamicString params;
2493 params.result = &result;
2494 params.argument = sopInstanceUID;
2495
2496 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, &params) != OrthancPluginErrorCode_Success)
2497 {
2498 /* Error */
2499 return NULL;
2500 }
2501 else
2502 {
2503 return result;
2504 }
2505 }
2506
2507
2508
2509 typedef struct
2510 {
2511 OrthancPluginRestOutput* output;
2512 uint16_t status;
2513 } _OrthancPluginSendHttpStatusCode;
2514
2515 /**
2516 * @brief Send a HTTP status code.
2517 *
2518 * This function answers to a REST request by sending a HTTP status
2519 * code (such as "400 - Bad Request"). Note that:
2520 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
2521 * - Redirections (status 301) must use ::OrthancPluginRedirect().
2522 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
2523 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
2524 *
2525 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2526 * @param output The HTTP connection to the client application.
2527 * @param status The HTTP status code to be sent.
2528 * @ingroup REST
2529 * @see OrthancPluginSendHttpStatus()
2530 **/
2531 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
2532 OrthancPluginContext* context,
2533 OrthancPluginRestOutput* output,
2534 uint16_t status)
2535 {
2536 _OrthancPluginSendHttpStatusCode params;
2537 params.output = output;
2538 params.status = status;
2539 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
2540 }
2541
2542
2543 /**
2544 * @brief Signal that a REST request is not authorized.
2545 *
2546 * This function answers to a REST request by signaling that it is
2547 * not authorized.
2548 *
2549 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2550 * @param output The HTTP connection to the client application.
2551 * @param realm The realm for the authorization process.
2552 * @ingroup REST
2553 **/
2554 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
2555 OrthancPluginContext* context,
2556 OrthancPluginRestOutput* output,
2557 const char* realm)
2558 {
2559 _OrthancPluginOutputPlusArgument params;
2560 params.output = output;
2561 params.argument = realm;
2562 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
2563 }
2564
2565
2566 /**
2567 * @brief Signal that this URI does not support this HTTP method.
2568 *
2569 * This function answers to a REST request by signaling that the
2570 * queried URI does not support this method.
2571 *
2572 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2573 * @param output The HTTP connection to the client application.
2574 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
2575 * @ingroup REST
2576 **/
2577 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
2578 OrthancPluginContext* context,
2579 OrthancPluginRestOutput* output,
2580 const char* allowedMethods)
2581 {
2582 _OrthancPluginOutputPlusArgument params;
2583 params.output = output;
2584 params.argument = allowedMethods;
2585 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
2586 }
2587
2588
2589 typedef struct
2590 {
2591 OrthancPluginRestOutput* output;
2592 const char* key;
2593 const char* value;
2594 } _OrthancPluginSetHttpHeader;
2595
2596 /**
2597 * @brief Set a cookie.
2598 *
2599 * This function sets a cookie in the HTTP client.
2600 *
2601 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2602 * @param output The HTTP connection to the client application.
2603 * @param cookie The cookie to be set.
2604 * @param value The value of the cookie.
2605 * @ingroup REST
2606 **/
2607 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
2608 OrthancPluginContext* context,
2609 OrthancPluginRestOutput* output,
2610 const char* cookie,
2611 const char* value)
2612 {
2613 _OrthancPluginSetHttpHeader params;
2614 params.output = output;
2615 params.key = cookie;
2616 params.value = value;
2617 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
2618 }
2619
2620
2621 /**
2622 * @brief Set some HTTP header.
2623 *
2624 * This function sets a HTTP header in the HTTP answer.
2625 *
2626 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2627 * @param output The HTTP connection to the client application.
2628 * @param key The HTTP header to be set.
2629 * @param value The value of the HTTP header.
2630 * @ingroup REST
2631 **/
2632 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
2633 OrthancPluginContext* context,
2634 OrthancPluginRestOutput* output,
2635 const char* key,
2636 const char* value)
2637 {
2638 _OrthancPluginSetHttpHeader params;
2639 params.output = output;
2640 params.key = key;
2641 params.value = value;
2642 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, &params);
2643 }
2644
2645
2646 typedef struct
2647 {
2648 char** resultStringToFree;
2649 const char** resultString;
2650 int64_t* resultInt64;
2651 const char* key;
2652 OrthancPluginDicomInstance* instance;
2653 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */
2654 } _OrthancPluginAccessDicomInstance;
2655
2656
2657 /**
2658 * @brief Get the AET of a DICOM instance.
2659 *
2660 * This function returns the Application Entity Title (AET) of the
2661 * DICOM modality from which a DICOM instance originates.
2662 *
2663 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2664 * @param instance The instance of interest.
2665 * @return The AET if success, NULL if error.
2666 * @ingroup Callbacks
2667 **/
2668 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
2669 OrthancPluginContext* context,
2670 OrthancPluginDicomInstance* instance)
2671 {
2672 const char* result;
2673
2674 _OrthancPluginAccessDicomInstance params;
2675 memset(&params, 0, sizeof(params));
2676 params.resultString = &result;
2677 params.instance = instance;
2678
2679 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, &params) != OrthancPluginErrorCode_Success)
2680 {
2681 /* Error */
2682 return NULL;
2683 }
2684 else
2685 {
2686 return result;
2687 }
2688 }
2689
2690
2691 /**
2692 * @brief Get the size of a DICOM file.
2693 *
2694 * This function returns the number of bytes of the given DICOM instance.
2695 *
2696 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2697 * @param instance The instance of interest.
2698 * @return The size of the file, -1 in case of error.
2699 * @ingroup Callbacks
2700 **/
2701 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
2702 OrthancPluginContext* context,
2703 OrthancPluginDicomInstance* instance)
2704 {
2705 int64_t size;
2706
2707 _OrthancPluginAccessDicomInstance params;
2708 memset(&params, 0, sizeof(params));
2709 params.resultInt64 = &size;
2710 params.instance = instance;
2711
2712 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, &params) != OrthancPluginErrorCode_Success)
2713 {
2714 /* Error */
2715 return -1;
2716 }
2717 else
2718 {
2719 return size;
2720 }
2721 }
2722
2723
2724 /**
2725 * @brief Get the data of a DICOM file.
2726 *
2727 * This function returns a pointer to the content of the given DICOM instance.
2728 *
2729 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2730 * @param instance The instance of interest.
2731 * @return The pointer to the DICOM data, NULL in case of error.
2732 * @ingroup Callbacks
2733 **/
2734 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData(
2735 OrthancPluginContext* context,
2736 OrthancPluginDicomInstance* instance)
2737 {
2738 const char* result;
2739
2740 _OrthancPluginAccessDicomInstance params;
2741 memset(&params, 0, sizeof(params));
2742 params.resultString = &result;
2743 params.instance = instance;
2744
2745 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, &params) != OrthancPluginErrorCode_Success)
2746 {
2747 /* Error */
2748 return NULL;
2749 }
2750 else
2751 {
2752 return result;
2753 }
2754 }
2755
2756
2757 /**
2758 * @brief Get the DICOM tag hierarchy as a JSON file.
2759 *
2760 * This function returns a pointer to a newly created string
2761 * containing a JSON file. This JSON file encodes the tag hierarchy
2762 * of the given DICOM instance.
2763 *
2764 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2765 * @param instance The instance of interest.
2766 * @return The NULL value in case of error, or a string containing the JSON file.
2767 * This string must be freed by OrthancPluginFreeString().
2768 * @ingroup Callbacks
2769 **/
2770 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
2771 OrthancPluginContext* context,
2772 OrthancPluginDicomInstance* instance)
2773 {
2774 char* result;
2775
2776 _OrthancPluginAccessDicomInstance params;
2777 memset(&params, 0, sizeof(params));
2778 params.resultStringToFree = &result;
2779 params.instance = instance;
2780
2781 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, &params) != OrthancPluginErrorCode_Success)
2782 {
2783 /* Error */
2784 return NULL;
2785 }
2786 else
2787 {
2788 return result;
2789 }
2790 }
2791
2792
2793 /**
2794 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
2795 *
2796 * This function returns a pointer to a newly created string
2797 * containing a JSON file. This JSON file encodes the tag hierarchy
2798 * of the given DICOM instance. In contrast with
2799 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in
2800 * its simplified version.
2801 *
2802 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2803 * @param instance The instance of interest.
2804 * @return The NULL value in case of error, or a string containing the JSON file.
2805 * This string must be freed by OrthancPluginFreeString().
2806 * @ingroup Callbacks
2807 **/
2808 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
2809 OrthancPluginContext* context,
2810 OrthancPluginDicomInstance* instance)
2811 {
2812 char* result;
2813
2814 _OrthancPluginAccessDicomInstance params;
2815 memset(&params, 0, sizeof(params));
2816 params.resultStringToFree = &result;
2817 params.instance = instance;
2818
2819 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, &params) != OrthancPluginErrorCode_Success)
2820 {
2821 /* Error */
2822 return NULL;
2823 }
2824 else
2825 {
2826 return result;
2827 }
2828 }
2829
2830
2831 /**
2832 * @brief Check whether a DICOM instance is associated with some metadata.
2833 *
2834 * This function checks whether the DICOM instance of interest is
2835 * associated with some metadata. As of Orthanc 0.8.1, in the
2836 * callbacks registered by
2837 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
2838 * possibly available metadata are "ReceptionDate", "RemoteAET" and
2839 * "IndexInSeries".
2840 *
2841 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2842 * @param instance The instance of interest.
2843 * @param metadata The metadata of interest.
2844 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
2845 * @ingroup Callbacks
2846 **/
2847 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata(
2848 OrthancPluginContext* context,
2849 OrthancPluginDicomInstance* instance,
2850 const char* metadata)
2851 {
2852 int64_t result;
2853
2854 _OrthancPluginAccessDicomInstance params;
2855 memset(&params, 0, sizeof(params));
2856 params.resultInt64 = &result;
2857 params.instance = instance;
2858 params.key = metadata;
2859
2860 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
2861 {
2862 /* Error */
2863 return -1;
2864 }
2865 else
2866 {
2867 return (result != 0);
2868 }
2869 }
2870
2871
2872 /**
2873 * @brief Get the value of some metadata associated with a given DICOM instance.
2874 *
2875 * This functions returns the value of some metadata that is associated with the DICOM instance of interest.
2876 * Before calling this function, the existence of the metadata must have been checked with
2877 * ::OrthancPluginHasInstanceMetadata().
2878 *
2879 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2880 * @param instance The instance of interest.
2881 * @param metadata The metadata of interest.
2882 * @return The metadata value if success, NULL if error.
2883 * @ingroup Callbacks
2884 **/
2885 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
2886 OrthancPluginContext* context,
2887 OrthancPluginDicomInstance* instance,
2888 const char* metadata)
2889 {
2890 const char* result;
2891
2892 _OrthancPluginAccessDicomInstance params;
2893 memset(&params, 0, sizeof(params));
2894 params.resultString = &result;
2895 params.instance = instance;
2896 params.key = metadata;
2897
2898 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
2899 {
2900 /* Error */
2901 return NULL;
2902 }
2903 else
2904 {
2905 return result;
2906 }
2907 }
2908
2909
2910
2911 typedef struct
2912 {
2913 OrthancPluginStorageCreate create;
2914 OrthancPluginStorageRead read;
2915 OrthancPluginStorageRemove remove;
2916 OrthancPluginFree free;
2917 } _OrthancPluginRegisterStorageArea;
2918
2919 /**
2920 * @brief Register a custom storage area.
2921 *
2922 * This function registers a custom storage area, to replace the
2923 * built-in way Orthanc stores its files on the filesystem. This
2924 * function must be called during the initialization of the plugin,
2925 * i.e. inside the OrthancPluginInitialize() public function.
2926 *
2927 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2928 * @param create The callback function to store a file on the custom storage area.
2929 * @param read The callback function to read a file from the custom storage area.
2930 * @param remove The callback function to remove a file from the custom storage area.
2931 * @ingroup Callbacks
2932 **/
2933 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
2934 OrthancPluginContext* context,
2935 OrthancPluginStorageCreate create,
2936 OrthancPluginStorageRead read,
2937 OrthancPluginStorageRemove remove)
2938 {
2939 _OrthancPluginRegisterStorageArea params;
2940 params.create = create;
2941 params.read = read;
2942 params.remove = remove;
2943
2944 #ifdef __cplusplus
2945 params.free = ::free;
2946 #else
2947 params.free = free;
2948 #endif
2949
2950 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, &params);
2951 }
2952
2953
2954
2955 /**
2956 * @brief Return the path to the Orthanc executable.
2957 *
2958 * This function returns the path to the Orthanc executable.
2959 *
2960 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2961 * @return NULL in the case of an error, or a newly allocated string
2962 * containing the path. This string must be freed by
2963 * OrthancPluginFreeString().
2964 **/
2965 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
2966 {
2967 char* result;
2968
2969 _OrthancPluginRetrieveDynamicString params;
2970 params.result = &result;
2971 params.argument = NULL;
2972
2973 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, &params) != OrthancPluginErrorCode_Success)
2974 {
2975 /* Error */
2976 return NULL;
2977 }
2978 else
2979 {
2980 return result;
2981 }
2982 }
2983
2984
2985 /**
2986 * @brief Return the directory containing the Orthanc.
2987 *
2988 * This function returns the path to the directory containing the Orthanc executable.
2989 *
2990 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2991 * @return NULL in the case of an error, or a newly allocated string
2992 * containing the path. This string must be freed by
2993 * OrthancPluginFreeString().
2994 **/
2995 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
2996 {
2997 char* result;
2998
2999 _OrthancPluginRetrieveDynamicString params;
3000 params.result = &result;
3001 params.argument = NULL;
3002
3003 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, &params) != OrthancPluginErrorCode_Success)
3004 {
3005 /* Error */
3006 return NULL;
3007 }
3008 else
3009 {
3010 return result;
3011 }
3012 }
3013
3014
3015 /**
3016 * @brief Return the path to the configuration file(s).
3017 *
3018 * This function returns the path to the configuration file(s) that
3019 * was specified when starting Orthanc. Since version 0.9.1, this
3020 * path can refer to a folder that stores a set of configuration
3021 * files. This function is deprecated in favor of
3022 * OrthancPluginGetConfiguration().
3023 *
3024 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3025 * @return NULL in the case of an error, or a newly allocated string
3026 * containing the path. This string must be freed by
3027 * OrthancPluginFreeString().
3028 * @see OrthancPluginGetConfiguration()
3029 **/
3030 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
3031 {
3032 char* result;
3033
3034 _OrthancPluginRetrieveDynamicString params;
3035 params.result = &result;
3036 params.argument = NULL;
3037
3038 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, &params) != OrthancPluginErrorCode_Success)
3039 {
3040 /* Error */
3041 return NULL;
3042 }
3043 else
3044 {
3045 return result;
3046 }
3047 }
3048
3049
3050
3051 typedef struct
3052 {
3053 OrthancPluginOnChangeCallback callback;
3054 } _OrthancPluginOnChangeCallback;
3055
3056 /**
3057 * @brief Register a callback to monitor changes.
3058 *
3059 * This function registers a callback function that is called
3060 * whenever a change happens to some DICOM resource.
3061 *
3062 * @warning If your change callback has to call the REST API of
3063 * Orthanc, you should make these calls in a separate thread (with
3064 * the events passing through a message queue). Otherwise, this
3065 * could result in deadlocks in the presence of other plugins or Lua
3066 * scripts.
3067 *
3068 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3069 * @param callback The callback function.
3070 * @ingroup Callbacks
3071 **/
3072 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback(
3073 OrthancPluginContext* context,
3074 OrthancPluginOnChangeCallback callback)
3075 {
3076 _OrthancPluginOnChangeCallback params;
3077 params.callback = callback;
3078
3079 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, &params);
3080 }
3081
3082
3083
3084 typedef struct
3085 {
3086 const char* plugin;
3087 _OrthancPluginProperty property;
3088 const char* value;
3089 } _OrthancPluginSetPluginProperty;
3090
3091
3092 /**
3093 * @brief Set the URI where the plugin provides its Web interface.
3094 *
3095 * For plugins that come with a Web interface, this function
3096 * declares the entry path where to find this interface. This
3097 * information is notably used in the "Plugins" page of Orthanc
3098 * Explorer.
3099 *
3100 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3101 * @param uri The root URI for this plugin.
3102 **/
3103 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri(
3104 OrthancPluginContext* context,
3105 const char* uri)
3106 {
3107 _OrthancPluginSetPluginProperty params;
3108 params.plugin = OrthancPluginGetName();
3109 params.property = _OrthancPluginProperty_RootUri;
3110 params.value = uri;
3111
3112 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3113 }
3114
3115
3116 /**
3117 * @brief Set a description for this plugin.
3118 *
3119 * Set a description for this plugin. It is displayed in the
3120 * "Plugins" page of Orthanc Explorer.
3121 *
3122 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3123 * @param description The description.
3124 **/
3125 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription(
3126 OrthancPluginContext* context,
3127 const char* description)
3128 {
3129 _OrthancPluginSetPluginProperty params;
3130 params.plugin = OrthancPluginGetName();
3131 params.property = _OrthancPluginProperty_Description;
3132 params.value = description;
3133
3134 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3135 }
3136
3137
3138 /**
3139 * @brief Extend the JavaScript code of Orthanc Explorer.
3140 *
3141 * Add JavaScript code to customize the default behavior of Orthanc
3142 * Explorer. This can for instance be used to add new buttons.
3143 *
3144 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3145 * @param javascript The custom JavaScript code.
3146 **/
3147 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer(
3148 OrthancPluginContext* context,
3149 const char* javascript)
3150 {
3151 _OrthancPluginSetPluginProperty params;
3152 params.plugin = OrthancPluginGetName();
3153 params.property = _OrthancPluginProperty_OrthancExplorer;
3154 params.value = javascript;
3155
3156 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3157 }
3158
3159
3160 typedef struct
3161 {
3162 char** result;
3163 int32_t property;
3164 const char* value;
3165 } _OrthancPluginGlobalProperty;
3166
3167
3168 /**
3169 * @brief Get the value of a global property.
3170 *
3171 * Get the value of a global property that is stored in the Orthanc database. Global
3172 * properties whose index is below 1024 are reserved by Orthanc.
3173 *
3174 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3175 * @param property The global property of interest.
3176 * @param defaultValue The value to return, if the global property is unset.
3177 * @return The value of the global property, or NULL in the case of an error. This
3178 * string must be freed by OrthancPluginFreeString().
3179 * @ingroup Orthanc
3180 **/
3181 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty(
3182 OrthancPluginContext* context,
3183 int32_t property,
3184 const char* defaultValue)
3185 {
3186 char* result;
3187
3188 _OrthancPluginGlobalProperty params;
3189 params.result = &result;
3190 params.property = property;
3191 params.value = defaultValue;
3192
3193 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, &params) != OrthancPluginErrorCode_Success)
3194 {
3195 /* Error */
3196 return NULL;
3197 }
3198 else
3199 {
3200 return result;
3201 }
3202 }
3203
3204
3205 /**
3206 * @brief Set the value of a global property.
3207 *
3208 * Set the value of a global property into the Orthanc
3209 * database. Setting a global property can be used by plugins to
3210 * save their internal parameters. Plugins are only allowed to set
3211 * properties whose index are above or equal to 1024 (properties
3212 * below 1024 are read-only and reserved by Orthanc).
3213 *
3214 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3215 * @param property The global property of interest.
3216 * @param value The value to be set in the global property.
3217 * @return 0 if success, or the error code if failure.
3218 * @ingroup Orthanc
3219 **/
3220 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty(
3221 OrthancPluginContext* context,
3222 int32_t property,
3223 const char* value)
3224 {
3225 _OrthancPluginGlobalProperty params;
3226 params.result = NULL;
3227 params.property = property;
3228 params.value = value;
3229
3230 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, &params);
3231 }
3232
3233
3234
3235 typedef struct
3236 {
3237 int32_t *resultInt32;
3238 uint32_t *resultUint32;
3239 int64_t *resultInt64;
3240 uint64_t *resultUint64;
3241 } _OrthancPluginReturnSingleValue;
3242
3243 /**
3244 * @brief Get the number of command-line arguments.
3245 *
3246 * Retrieve the number of command-line arguments that were used to launch Orthanc.
3247 *
3248 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3249 * @return The number of arguments.
3250 **/
3251 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount(
3252 OrthancPluginContext* context)
3253 {
3254 uint32_t count = 0;
3255
3256 _OrthancPluginReturnSingleValue params;
3257 memset(&params, 0, sizeof(params));
3258 params.resultUint32 = &count;
3259
3260 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, &params) != OrthancPluginErrorCode_Success)
3261 {
3262 /* Error */
3263 return 0;
3264 }
3265 else
3266 {
3267 return count;
3268 }
3269 }
3270
3271
3272
3273 /**
3274 * @brief Get the value of a command-line argument.
3275 *
3276 * Get the value of one of the command-line arguments that were used
3277 * to launch Orthanc. The number of available arguments can be
3278 * retrieved by OrthancPluginGetCommandLineArgumentsCount().
3279 *
3280 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3281 * @param argument The index of the argument.
3282 * @return The value of the argument, or NULL in the case of an error. This
3283 * string must be freed by OrthancPluginFreeString().
3284 **/
3285 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument(
3286 OrthancPluginContext* context,
3287 uint32_t argument)
3288 {
3289 char* result;
3290
3291 _OrthancPluginGlobalProperty params;
3292 params.result = &result;
3293 params.property = (int32_t) argument;
3294 params.value = NULL;
3295
3296 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, &params) != OrthancPluginErrorCode_Success)
3297 {
3298 /* Error */
3299 return NULL;
3300 }
3301 else
3302 {
3303 return result;
3304 }
3305 }
3306
3307
3308 /**
3309 * @brief Get the expected version of the database schema.
3310 *
3311 * Retrieve the expected version of the database schema.
3312 *
3313 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3314 * @return The version.
3315 * @ingroup Callbacks
3316 **/
3317 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
3318 OrthancPluginContext* context)
3319 {
3320 uint32_t count = 0;
3321
3322 _OrthancPluginReturnSingleValue params;
3323 memset(&params, 0, sizeof(params));
3324 params.resultUint32 = &count;
3325
3326 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params) != OrthancPluginErrorCode_Success)
3327 {
3328 /* Error */
3329 return 0;
3330 }
3331 else
3332 {
3333 return count;
3334 }
3335 }
3336
3337
3338
3339 /**
3340 * @brief Return the content of the configuration file(s).
3341 *
3342 * This function returns the content of the configuration that is
3343 * used by Orthanc, formatted as a JSON string.
3344 *
3345 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3346 * @return NULL in the case of an error, or a newly allocated string
3347 * containing the configuration. This string must be freed by
3348 * OrthancPluginFreeString().
3349 **/
3350 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context)
3351 {
3352 char* result;
3353
3354 _OrthancPluginRetrieveDynamicString params;
3355 params.result = &result;
3356 params.argument = NULL;
3357
3358 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, &params) != OrthancPluginErrorCode_Success)
3359 {
3360 /* Error */
3361 return NULL;
3362 }
3363 else
3364 {
3365 return result;
3366 }
3367 }
3368
3369
3370
3371 typedef struct
3372 {
3373 OrthancPluginRestOutput* output;
3374 const char* subType;
3375 const char* contentType;
3376 } _OrthancPluginStartMultipartAnswer;
3377
3378 /**
3379 * @brief Start an HTTP multipart answer.
3380 *
3381 * Initiates a HTTP multipart answer, as the result of a REST request.
3382 *
3383 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3384 * @param output The HTTP connection to the client application.
3385 * @param subType The sub-type of the multipart answer ("mixed" or "related").
3386 * @param contentType The MIME type of the items in the multipart answer.
3387 * @return 0 if success, or the error code if failure.
3388 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2()
3389 * @ingroup REST
3390 **/
3391 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer(
3392 OrthancPluginContext* context,
3393 OrthancPluginRestOutput* output,
3394 const char* subType,
3395 const char* contentType)
3396 {
3397 _OrthancPluginStartMultipartAnswer params;
3398 params.output = output;
3399 params.subType = subType;
3400 params.contentType = contentType;
3401 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, &params);
3402 }
3403
3404
3405 /**
3406 * @brief Send an item as a part of some HTTP multipart answer.
3407 *
3408 * This function sends an item as a part of some HTTP multipart
3409 * answer that was initiated by OrthancPluginStartMultipartAnswer().
3410 *
3411 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3412 * @param output The HTTP connection to the client application.
3413 * @param answer Pointer to the memory buffer containing the item.
3414 * @param answerSize Number of bytes of the item.
3415 * @return 0 if success, or the error code if failure (this notably happens
3416 * if the connection is closed by the client).
3417 * @see OrthancPluginSendMultipartItem2()
3418 * @ingroup REST
3419 **/
3420 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem(
3421 OrthancPluginContext* context,
3422 OrthancPluginRestOutput* output,
3423 const char* answer,
3424 uint32_t answerSize)
3425 {
3426 _OrthancPluginAnswerBuffer params;
3427 params.output = output;
3428 params.answer = answer;
3429 params.answerSize = answerSize;
3430 params.mimeType = NULL;
3431 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, &params);
3432 }
3433
3434
3435
3436 typedef struct
3437 {
3438 OrthancPluginMemoryBuffer* target;
3439 const void* source;
3440 uint32_t size;
3441 OrthancPluginCompressionType compression;
3442 uint8_t uncompress;
3443 } _OrthancPluginBufferCompression;
3444
3445
3446 /**
3447 * @brief Compress or decompress a buffer.
3448 *
3449 * This function compresses or decompresses a buffer, using the
3450 * version of the zlib library that is used by the Orthanc core.
3451 *
3452 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3453 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3454 * @param source The source buffer.
3455 * @param size The size in bytes of the source buffer.
3456 * @param compression The compression algorithm.
3457 * @param uncompress If set to "0", the buffer must be compressed.
3458 * If set to "1", the buffer must be uncompressed.
3459 * @return 0 if success, or the error code if failure.
3460 * @ingroup Images
3461 **/
3462 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression(
3463 OrthancPluginContext* context,
3464 OrthancPluginMemoryBuffer* target,
3465 const void* source,
3466 uint32_t size,
3467 OrthancPluginCompressionType compression,
3468 uint8_t uncompress)
3469 {
3470 _OrthancPluginBufferCompression params;
3471 params.target = target;
3472 params.source = source;
3473 params.size = size;
3474 params.compression = compression;
3475 params.uncompress = uncompress;
3476
3477 return context->InvokeService(context, _OrthancPluginService_BufferCompression, &params);
3478 }
3479
3480
3481
3482 typedef struct
3483 {
3484 OrthancPluginMemoryBuffer* target;
3485 const char* path;
3486 } _OrthancPluginReadFile;
3487
3488 /**
3489 * @brief Read a file.
3490 *
3491 * Read the content of a file on the filesystem, and returns it into
3492 * a newly allocated memory buffer.
3493 *
3494 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3495 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3496 * @param path The path of the file to be read.
3497 * @return 0 if success, or the error code if failure.
3498 **/
3499 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile(
3500 OrthancPluginContext* context,
3501 OrthancPluginMemoryBuffer* target,
3502 const char* path)
3503 {
3504 _OrthancPluginReadFile params;
3505 params.target = target;
3506 params.path = path;
3507 return context->InvokeService(context, _OrthancPluginService_ReadFile, &params);
3508 }
3509
3510
3511
3512 typedef struct
3513 {
3514 const char* path;
3515 const void* data;
3516 uint32_t size;
3517 } _OrthancPluginWriteFile;
3518
3519 /**
3520 * @brief Write a file.
3521 *
3522 * Write the content of a memory buffer to the filesystem.
3523 *
3524 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3525 * @param path The path of the file to be written.
3526 * @param data The content of the memory buffer.
3527 * @param size The size of the memory buffer.
3528 * @return 0 if success, or the error code if failure.
3529 **/
3530 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile(
3531 OrthancPluginContext* context,
3532 const char* path,
3533 const void* data,
3534 uint32_t size)
3535 {
3536 _OrthancPluginWriteFile params;
3537 params.path = path;
3538 params.data = data;
3539 params.size = size;
3540 return context->InvokeService(context, _OrthancPluginService_WriteFile, &params);
3541 }
3542
3543
3544
3545 typedef struct
3546 {
3547 const char** target;
3548 OrthancPluginErrorCode error;
3549 } _OrthancPluginGetErrorDescription;
3550
3551 /**
3552 * @brief Get the description of a given error code.
3553 *
3554 * This function returns the description of a given error code.
3555 *
3556 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3557 * @param error The error code of interest.
3558 * @return The error description. This is a statically-allocated
3559 * string, do not free it.
3560 **/
3561 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription(
3562 OrthancPluginContext* context,
3563 OrthancPluginErrorCode error)
3564 {
3565 const char* result = NULL;
3566
3567 _OrthancPluginGetErrorDescription params;
3568 params.target = &result;
3569 params.error = error;
3570
3571 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, &params) != OrthancPluginErrorCode_Success ||
3572 result == NULL)
3573 {
3574 return "Unknown error code";
3575 }
3576 else
3577 {
3578 return result;
3579 }
3580 }
3581
3582
3583
3584 typedef struct
3585 {
3586 OrthancPluginRestOutput* output;
3587 uint16_t status;
3588 const char* body;
3589 uint32_t bodySize;
3590 } _OrthancPluginSendHttpStatus;
3591
3592 /**
3593 * @brief Send a HTTP status, with a custom body.
3594 *
3595 * This function answers to a HTTP request by sending a HTTP status
3596 * code (such as "400 - Bad Request"), together with a body
3597 * describing the error. The body will only be returned if the
3598 * configuration option "HttpDescribeErrors" of Orthanc is set to "true".
3599 *
3600 * Note that:
3601 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
3602 * - Redirections (status 301) must use ::OrthancPluginRedirect().
3603 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
3604 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
3605 *
3606 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3607 * @param output The HTTP connection to the client application.
3608 * @param status The HTTP status code to be sent.
3609 * @param body The body of the answer.
3610 * @param bodySize The size of the body.
3611 * @see OrthancPluginSendHttpStatusCode()
3612 * @ingroup REST
3613 **/
3614 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus(
3615 OrthancPluginContext* context,
3616 OrthancPluginRestOutput* output,
3617 uint16_t status,
3618 const char* body,
3619 uint32_t bodySize)
3620 {
3621 _OrthancPluginSendHttpStatus params;
3622 params.output = output;
3623 params.status = status;
3624 params.body = body;
3625 params.bodySize = bodySize;
3626 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, &params);
3627 }
3628
3629
3630
3631 typedef struct
3632 {
3633 const OrthancPluginImage* image;
3634 uint32_t* resultUint32;
3635 OrthancPluginPixelFormat* resultPixelFormat;
3636 void** resultBuffer;
3637 } _OrthancPluginGetImageInfo;
3638
3639
3640 /**
3641 * @brief Return the pixel format of an image.
3642 *
3643 * This function returns the type of memory layout for the pixels of the given image.
3644 *
3645 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3646 * @param image The image of interest.
3647 * @return The pixel format.
3648 * @ingroup Images
3649 **/
3650 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat(
3651 OrthancPluginContext* context,
3652 const OrthancPluginImage* image)
3653 {
3654 OrthancPluginPixelFormat target;
3655
3656 _OrthancPluginGetImageInfo params;
3657 memset(&params, 0, sizeof(params));
3658 params.image = image;
3659 params.resultPixelFormat = &target;
3660
3661 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, &params) != OrthancPluginErrorCode_Success)
3662 {
3663 return OrthancPluginPixelFormat_Unknown;
3664 }
3665 else
3666 {
3667 return (OrthancPluginPixelFormat) target;
3668 }
3669 }
3670
3671
3672
3673 /**
3674 * @brief Return the width of an image.
3675 *
3676 * This function returns the width of the given image.
3677 *
3678 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3679 * @param image The image of interest.
3680 * @return The width.
3681 * @ingroup Images
3682 **/
3683 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth(
3684 OrthancPluginContext* context,
3685 const OrthancPluginImage* image)
3686 {
3687 uint32_t width;
3688
3689 _OrthancPluginGetImageInfo params;
3690 memset(&params, 0, sizeof(params));
3691 params.image = image;
3692 params.resultUint32 = &width;
3693
3694 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, &params) != OrthancPluginErrorCode_Success)
3695 {
3696 return 0;
3697 }
3698 else
3699 {
3700 return width;
3701 }
3702 }
3703
3704
3705
3706 /**
3707 * @brief Return the height of an image.
3708 *
3709 * This function returns the height of the given image.
3710 *
3711 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3712 * @param image The image of interest.
3713 * @return The height.
3714 * @ingroup Images
3715 **/
3716 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight(
3717 OrthancPluginContext* context,
3718 const OrthancPluginImage* image)
3719 {
3720 uint32_t height;
3721
3722 _OrthancPluginGetImageInfo params;
3723 memset(&params, 0, sizeof(params));
3724 params.image = image;
3725 params.resultUint32 = &height;
3726
3727 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, &params) != OrthancPluginErrorCode_Success)
3728 {
3729 return 0;
3730 }
3731 else
3732 {
3733 return height;
3734 }
3735 }
3736
3737
3738
3739 /**
3740 * @brief Return the pitch of an image.
3741 *
3742 * This function returns the pitch of the given image. The pitch is
3743 * defined as the number of bytes between 2 successive lines of the
3744 * image in the memory buffer.
3745 *
3746 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3747 * @param image The image of interest.
3748 * @return The pitch.
3749 * @ingroup Images
3750 **/
3751 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch(
3752 OrthancPluginContext* context,
3753 const OrthancPluginImage* image)
3754 {
3755 uint32_t pitch;
3756
3757 _OrthancPluginGetImageInfo params;
3758 memset(&params, 0, sizeof(params));
3759 params.image = image;
3760 params.resultUint32 = &pitch;
3761
3762 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, &params) != OrthancPluginErrorCode_Success)
3763 {
3764 return 0;
3765 }
3766 else
3767 {
3768 return pitch;
3769 }
3770 }
3771
3772
3773
3774 /**
3775 * @brief Return a pointer to the content of an image.
3776 *
3777 * This function returns a pointer to the memory buffer that
3778 * contains the pixels of the image.
3779 *
3780 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3781 * @param image The image of interest.
3782 * @return The pointer.
3783 * @ingroup Images
3784 **/
3785 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer(
3786 OrthancPluginContext* context,
3787 const OrthancPluginImage* image)
3788 {
3789 void* target = NULL;
3790
3791 _OrthancPluginGetImageInfo params;
3792 memset(&params, 0, sizeof(params));
3793 params.resultBuffer = &target;
3794 params.image = image;
3795
3796 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, &params) != OrthancPluginErrorCode_Success)
3797 {
3798 return NULL;
3799 }
3800 else
3801 {
3802 return target;
3803 }
3804 }
3805
3806
3807 typedef struct
3808 {
3809 OrthancPluginImage** target;
3810 const void* data;
3811 uint32_t size;
3812 OrthancPluginImageFormat format;
3813 } _OrthancPluginUncompressImage;
3814
3815
3816 /**
3817 * @brief Decode a compressed image.
3818 *
3819 * This function decodes a compressed image from a memory buffer.
3820 *
3821 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3822 * @param data Pointer to a memory buffer containing the compressed image.
3823 * @param size Size of the memory buffer containing the compressed image.
3824 * @param format The file format of the compressed image.
3825 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
3826 * @ingroup Images
3827 **/
3828 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage(
3829 OrthancPluginContext* context,
3830 const void* data,
3831 uint32_t size,
3832 OrthancPluginImageFormat format)
3833 {
3834 OrthancPluginImage* target = NULL;
3835
3836 _OrthancPluginUncompressImage params;
3837 memset(&params, 0, sizeof(params));
3838 params.target = &target;
3839 params.data = data;
3840 params.size = size;
3841 params.format = format;
3842
3843 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, &params) != OrthancPluginErrorCode_Success)
3844 {
3845 return NULL;
3846 }
3847 else
3848 {
3849 return target;
3850 }
3851 }
3852
3853
3854
3855
3856 typedef struct
3857 {
3858 OrthancPluginImage* image;
3859 } _OrthancPluginFreeImage;
3860
3861 /**
3862 * @brief Free an image.
3863 *
3864 * This function frees an image that was decoded with OrthancPluginUncompressImage().
3865 *
3866 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3867 * @param image The image.
3868 * @ingroup Images
3869 **/
3870 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage(
3871 OrthancPluginContext* context,
3872 OrthancPluginImage* image)
3873 {
3874 _OrthancPluginFreeImage params;
3875 params.image = image;
3876
3877 context->InvokeService(context, _OrthancPluginService_FreeImage, &params);
3878 }
3879
3880
3881
3882
3883 typedef struct
3884 {
3885 OrthancPluginMemoryBuffer* target;
3886 OrthancPluginImageFormat imageFormat;
3887 OrthancPluginPixelFormat pixelFormat;
3888 uint32_t width;
3889 uint32_t height;
3890 uint32_t pitch;
3891 const void* buffer;
3892 uint8_t quality;
3893 } _OrthancPluginCompressImage;
3894
3895
3896 /**
3897 * @brief Encode a PNG image.
3898 *
3899 * This function compresses the given memory buffer containing an
3900 * image using the PNG specification, and stores the result of the
3901 * compression into a newly allocated memory buffer.
3902 *
3903 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3904 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3905 * @param format The memory layout of the uncompressed image.
3906 * @param width The width of the image.
3907 * @param height The height of the image.
3908 * @param pitch The pitch of the image (i.e. the number of bytes
3909 * between 2 successive lines of the image in the memory buffer).
3910 * @param buffer The memory buffer containing the uncompressed image.
3911 * @return 0 if success, or the error code if failure.
3912 * @see OrthancPluginCompressAndAnswerPngImage()
3913 * @ingroup Images
3914 **/
3915 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage(
3916 OrthancPluginContext* context,
3917 OrthancPluginMemoryBuffer* target,
3918 OrthancPluginPixelFormat format,
3919 uint32_t width,
3920 uint32_t height,
3921 uint32_t pitch,
3922 const void* buffer)
3923 {
3924 _OrthancPluginCompressImage params;
3925 memset(&params, 0, sizeof(params));
3926 params.target = target;
3927 params.imageFormat = OrthancPluginImageFormat_Png;
3928 params.pixelFormat = format;
3929 params.width = width;
3930 params.height = height;
3931 params.pitch = pitch;
3932 params.buffer = buffer;
3933 params.quality = 0; /* Unused for PNG */
3934
3935 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
3936 }
3937
3938
3939 /**
3940 * @brief Encode a JPEG image.
3941 *
3942 * This function compresses the given memory buffer containing an
3943 * image using the JPEG specification, and stores the result of the
3944 * compression into a newly allocated memory buffer.
3945 *
3946 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3947 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3948 * @param format The memory layout of the uncompressed image.
3949 * @param width The width of the image.
3950 * @param height The height of the image.
3951 * @param pitch The pitch of the image (i.e. the number of bytes
3952 * between 2 successive lines of the image in the memory buffer).
3953 * @param buffer The memory buffer containing the uncompressed image.
3954 * @param quality The quality of the JPEG encoding, between 1 (worst
3955 * quality, best compression) and 100 (best quality, worst
3956 * compression).
3957 * @return 0 if success, or the error code if failure.
3958 * @ingroup Images
3959 **/
3960 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage(
3961 OrthancPluginContext* context,
3962 OrthancPluginMemoryBuffer* target,
3963 OrthancPluginPixelFormat format,
3964 uint32_t width,
3965 uint32_t height,
3966 uint32_t pitch,
3967 const void* buffer,
3968 uint8_t quality)
3969 {
3970 _OrthancPluginCompressImage params;
3971 memset(&params, 0, sizeof(params));
3972 params.target = target;
3973 params.imageFormat = OrthancPluginImageFormat_Jpeg;
3974 params.pixelFormat = format;
3975 params.width = width;
3976 params.height = height;
3977 params.pitch = pitch;
3978 params.buffer = buffer;
3979 params.quality = quality;
3980
3981 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
3982 }
3983
3984
3985
3986 /**
3987 * @brief Answer to a REST request with a JPEG image.
3988 *
3989 * This function answers to a REST request with a JPEG image. The
3990 * parameters of this function describe a memory buffer that
3991 * contains an uncompressed image. The image will be automatically compressed
3992 * as a JPEG image by the core system of Orthanc.
3993 *
3994 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3995 * @param output The HTTP connection to the client application.
3996 * @param format The memory layout of the uncompressed image.
3997 * @param width The width of the image.
3998 * @param height The height of the image.
3999 * @param pitch The pitch of the image (i.e. the number of bytes
4000 * between 2 successive lines of the image in the memory buffer).
4001 * @param buffer The memory buffer containing the uncompressed image.
4002 * @param quality The quality of the JPEG encoding, between 1 (worst
4003 * quality, best compression) and 100 (best quality, worst
4004 * compression).
4005 * @ingroup REST
4006 **/
4007 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage(
4008 OrthancPluginContext* context,
4009 OrthancPluginRestOutput* output,
4010 OrthancPluginPixelFormat format,
4011 uint32_t width,
4012 uint32_t height,
4013 uint32_t pitch,
4014 const void* buffer,
4015 uint8_t quality)
4016 {
4017 _OrthancPluginCompressAndAnswerImage params;
4018 params.output = output;
4019 params.imageFormat = OrthancPluginImageFormat_Jpeg;
4020 params.pixelFormat = format;
4021 params.width = width;
4022 params.height = height;
4023 params.pitch = pitch;
4024 params.buffer = buffer;
4025 params.quality = quality;
4026 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
4027 }
4028
4029
4030
4031
4032 typedef struct
4033 {
4034 OrthancPluginMemoryBuffer* target;
4035 OrthancPluginHttpMethod method;
4036 const char* url;
4037 const char* username;
4038 const char* password;
4039 const void* body;
4040 uint32_t bodySize;
4041 } _OrthancPluginCallHttpClient;
4042
4043
4044 /**
4045 * @brief Issue a HTTP GET call.
4046 *
4047 * Make a HTTP GET call to the given URL. The result to the query is
4048 * stored into a newly allocated memory buffer. Favor
4049 * OrthancPluginRestApiGet() if calling the built-in REST API of the
4050 * Orthanc instance that hosts this plugin.
4051 *
4052 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4053 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4054 * @param url The URL of interest.
4055 * @param username The username (can be <tt>NULL</tt> if no password protection).
4056 * @param password The password (can be <tt>NULL</tt> if no password protection).
4057 * @return 0 if success, or the error code if failure.
4058 * @ingroup Toolbox
4059 **/
4060 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet(
4061 OrthancPluginContext* context,
4062 OrthancPluginMemoryBuffer* target,
4063 const char* url,
4064 const char* username,
4065 const char* password)
4066 {
4067 _OrthancPluginCallHttpClient params;
4068 memset(&params, 0, sizeof(params));
4069
4070 params.target = target;
4071 params.method = OrthancPluginHttpMethod_Get;
4072 params.url = url;
4073 params.username = username;
4074 params.password = password;
4075
4076 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4077 }
4078
4079
4080 /**
4081 * @brief Issue a HTTP POST call.
4082 *
4083 * Make a HTTP POST call to the given URL. The result to the query
4084 * is stored into a newly allocated memory buffer. Favor
4085 * OrthancPluginRestApiPost() if calling the built-in REST API of
4086 * the Orthanc instance that hosts this plugin.
4087 *
4088 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4089 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4090 * @param url The URL of interest.
4091 * @param body The content of the body of the request.
4092 * @param bodySize The size of the body of the request.
4093 * @param username The username (can be <tt>NULL</tt> if no password protection).
4094 * @param password The password (can be <tt>NULL</tt> if no password protection).
4095 * @return 0 if success, or the error code if failure.
4096 * @ingroup Toolbox
4097 **/
4098 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost(
4099 OrthancPluginContext* context,
4100 OrthancPluginMemoryBuffer* target,
4101 const char* url,
4102 const void* body,
4103 uint32_t bodySize,
4104 const char* username,
4105 const char* password)
4106 {
4107 _OrthancPluginCallHttpClient params;
4108 memset(&params, 0, sizeof(params));
4109
4110 params.target = target;
4111 params.method = OrthancPluginHttpMethod_Post;
4112 params.url = url;
4113 params.body = body;
4114 params.bodySize = bodySize;
4115 params.username = username;
4116 params.password = password;
4117
4118 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4119 }
4120
4121
4122 /**
4123 * @brief Issue a HTTP PUT call.
4124 *
4125 * Make a HTTP PUT call to the given URL. The result to the query is
4126 * stored into a newly allocated memory buffer. Favor
4127 * OrthancPluginRestApiPut() if calling the built-in REST API of the
4128 * Orthanc instance that hosts this plugin.
4129 *
4130 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4131 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4132 * @param url The URL of interest.
4133 * @param body The content of the body of the request.
4134 * @param bodySize The size of the body of the request.
4135 * @param username The username (can be <tt>NULL</tt> if no password protection).
4136 * @param password The password (can be <tt>NULL</tt> if no password protection).
4137 * @return 0 if success, or the error code if failure.
4138 * @ingroup Toolbox
4139 **/
4140 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut(
4141 OrthancPluginContext* context,
4142 OrthancPluginMemoryBuffer* target,
4143 const char* url,
4144 const void* body,
4145 uint32_t bodySize,
4146 const char* username,
4147 const char* password)
4148 {
4149 _OrthancPluginCallHttpClient params;
4150 memset(&params, 0, sizeof(params));
4151
4152 params.target = target;
4153 params.method = OrthancPluginHttpMethod_Put;
4154 params.url = url;
4155 params.body = body;
4156 params.bodySize = bodySize;
4157 params.username = username;
4158 params.password = password;
4159
4160 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4161 }
4162
4163
4164 /**
4165 * @brief Issue a HTTP DELETE call.
4166 *
4167 * Make a HTTP DELETE call to the given URL. Favor
4168 * OrthancPluginRestApiDelete() if calling the built-in REST API of
4169 * the Orthanc instance that hosts this plugin.
4170 *
4171 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4172 * @param url The URL of interest.
4173 * @param username The username (can be <tt>NULL</tt> if no password protection).
4174 * @param password The password (can be <tt>NULL</tt> if no password protection).
4175 * @return 0 if success, or the error code if failure.
4176 * @ingroup Toolbox
4177 **/
4178 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete(
4179 OrthancPluginContext* context,
4180 const char* url,
4181 const char* username,
4182 const char* password)
4183 {
4184 _OrthancPluginCallHttpClient params;
4185 memset(&params, 0, sizeof(params));
4186
4187 params.method = OrthancPluginHttpMethod_Delete;
4188 params.url = url;
4189 params.username = username;
4190 params.password = password;
4191
4192 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4193 }
4194
4195
4196
4197 typedef struct
4198 {
4199 OrthancPluginImage** target;
4200 const OrthancPluginImage* source;
4201 OrthancPluginPixelFormat targetFormat;
4202 } _OrthancPluginConvertPixelFormat;
4203
4204
4205 /**
4206 * @brief Change the pixel format of an image.
4207 *
4208 * This function creates a new image, changing the memory layout of the pixels.
4209 *
4210 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4211 * @param source The source image.
4212 * @param targetFormat The target pixel format.
4213 * @return The resulting image. It must be freed with OrthancPluginFreeImage().
4214 * @ingroup Images
4215 **/
4216 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat(
4217 OrthancPluginContext* context,
4218 const OrthancPluginImage* source,
4219 OrthancPluginPixelFormat targetFormat)
4220 {
4221 OrthancPluginImage* target = NULL;
4222
4223 _OrthancPluginConvertPixelFormat params;
4224 params.target = &target;
4225 params.source = source;
4226 params.targetFormat = targetFormat;
4227
4228 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, &params) != OrthancPluginErrorCode_Success)
4229 {
4230 return NULL;
4231 }
4232 else
4233 {
4234 return target;
4235 }
4236 }
4237
4238
4239
4240 /**
4241 * @brief Return the number of available fonts.
4242 *
4243 * This function returns the number of fonts that are built in the
4244 * Orthanc core. These fonts can be used to draw texts on images
4245 * through OrthancPluginDrawText().
4246 *
4247 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4248 * @return The number of fonts.
4249 * @ingroup Images
4250 **/
4251 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount(
4252 OrthancPluginContext* context)
4253 {
4254 uint32_t count = 0;
4255
4256 _OrthancPluginReturnSingleValue params;
4257 memset(&params, 0, sizeof(params));
4258 params.resultUint32 = &count;
4259
4260 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, &params) != OrthancPluginErrorCode_Success)
4261 {
4262 /* Error */
4263 return 0;
4264 }
4265 else
4266 {
4267 return count;
4268 }
4269 }
4270
4271
4272
4273
4274 typedef struct
4275 {
4276 uint32_t fontIndex; /* in */
4277 const char** name; /* out */
4278 uint32_t* size; /* out */
4279 } _OrthancPluginGetFontInfo;
4280
4281 /**
4282 * @brief Return the name of a font.
4283 *
4284 * This function returns the name of a font that is built in the Orthanc core.
4285 *
4286 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4287 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4288 * @return The font name. This is a statically-allocated string, do not free it.
4289 * @ingroup Images
4290 **/
4291 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName(
4292 OrthancPluginContext* context,
4293 uint32_t fontIndex)
4294 {
4295 const char* result = NULL;
4296
4297 _OrthancPluginGetFontInfo params;
4298 memset(&params, 0, sizeof(params));
4299 params.name = &result;
4300 params.fontIndex = fontIndex;
4301
4302 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4303 {
4304 return NULL;
4305 }
4306 else
4307 {
4308 return result;
4309 }
4310 }
4311
4312
4313 /**
4314 * @brief Return the size of a font.
4315 *
4316 * This function returns the size of a font that is built in the Orthanc core.
4317 *
4318 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4319 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4320 * @return The font size.
4321 * @ingroup Images
4322 **/
4323 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize(
4324 OrthancPluginContext* context,
4325 uint32_t fontIndex)
4326 {
4327 uint32_t result;
4328
4329 _OrthancPluginGetFontInfo params;
4330 memset(&params, 0, sizeof(params));
4331 params.size = &result;
4332 params.fontIndex = fontIndex;
4333
4334 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4335 {
4336 return 0;
4337 }
4338 else
4339 {
4340 return result;
4341 }
4342 }
4343
4344
4345
4346 typedef struct
4347 {
4348 OrthancPluginImage* image;
4349 uint32_t fontIndex;
4350 const char* utf8Text;
4351 int32_t x;
4352 int32_t y;
4353 uint8_t r;
4354 uint8_t g;
4355 uint8_t b;
4356 } _OrthancPluginDrawText;
4357
4358
4359 /**
4360 * @brief Draw text on an image.
4361 *
4362 * This function draws some text on some image.
4363 *
4364 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4365 * @param image The image upon which to draw the text.
4366 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4367 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string.
4368 * @param x The X position of the text over the image.
4369 * @param y The Y position of the text over the image.
4370 * @param r The value of the red color channel of the text.
4371 * @param g The value of the green color channel of the text.
4372 * @param b The value of the blue color channel of the text.
4373 * @return 0 if success, other value if error.
4374 * @ingroup Images
4375 **/
4376 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText(
4377 OrthancPluginContext* context,
4378 OrthancPluginImage* image,
4379 uint32_t fontIndex,
4380 const char* utf8Text,
4381 int32_t x,
4382 int32_t y,
4383 uint8_t r,
4384 uint8_t g,
4385 uint8_t b)
4386 {
4387 _OrthancPluginDrawText params;
4388 memset(&params, 0, sizeof(params));
4389 params.image = image;
4390 params.fontIndex = fontIndex;
4391 params.utf8Text = utf8Text;
4392 params.x = x;
4393 params.y = y;
4394 params.r = r;
4395 params.g = g;
4396 params.b = b;
4397
4398 return context->InvokeService(context, _OrthancPluginService_DrawText, &params);
4399 }
4400
4401
4402
4403 typedef struct
4404 {
4405 OrthancPluginStorageArea* storageArea;
4406 const char* uuid;
4407 const void* content;
4408 uint64_t size;
4409 OrthancPluginContentType type;
4410 } _OrthancPluginStorageAreaCreate;
4411
4412
4413 /**
4414 * @brief Create a file inside the storage area.
4415 *
4416 * This function creates a new file inside the storage area that is
4417 * currently used by Orthanc.
4418 *
4419 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4420 * @param storageArea The storage area.
4421 * @param uuid The identifier of the file to be created.
4422 * @param content The content to store in the newly created file.
4423 * @param size The size of the content.
4424 * @param type The type of the file content.
4425 * @return 0 if success, other value if error.
4426 * @ingroup Callbacks
4427 **/
4428 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate(
4429 OrthancPluginContext* context,
4430 OrthancPluginStorageArea* storageArea,
4431 const char* uuid,
4432 const void* content,
4433 uint64_t size,
4434 OrthancPluginContentType type)
4435 {
4436 _OrthancPluginStorageAreaCreate params;
4437 params.storageArea = storageArea;
4438 params.uuid = uuid;
4439 params.content = content;
4440 params.size = size;
4441 params.type = type;
4442
4443 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, &params);
4444 }
4445
4446
4447 typedef struct
4448 {
4449 OrthancPluginMemoryBuffer* target;
4450 OrthancPluginStorageArea* storageArea;
4451 const char* uuid;
4452 OrthancPluginContentType type;
4453 } _OrthancPluginStorageAreaRead;
4454
4455
4456 /**
4457 * @brief Read a file from the storage area.
4458 *
4459 * This function reads the content of a given file from the storage
4460 * area that is currently used by Orthanc.
4461 *
4462 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4463 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4464 * @param storageArea The storage area.
4465 * @param uuid The identifier of the file to be read.
4466 * @param type The type of the file content.
4467 * @return 0 if success, other value if error.
4468 * @ingroup Callbacks
4469 **/
4470 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead(
4471 OrthancPluginContext* context,
4472 OrthancPluginMemoryBuffer* target,
4473 OrthancPluginStorageArea* storageArea,
4474 const char* uuid,
4475 OrthancPluginContentType type)
4476 {
4477 _OrthancPluginStorageAreaRead params;
4478 params.target = target;
4479 params.storageArea = storageArea;
4480 params.uuid = uuid;
4481 params.type = type;
4482
4483 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, &params);
4484 }
4485
4486
4487 typedef struct
4488 {
4489 OrthancPluginStorageArea* storageArea;
4490 const char* uuid;
4491 OrthancPluginContentType type;
4492 } _OrthancPluginStorageAreaRemove;
4493
4494 /**
4495 * @brief Remove a file from the storage area.
4496 *
4497 * This function removes a given file from the storage area that is
4498 * currently used by Orthanc.
4499 *
4500 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4501 * @param storageArea The storage area.
4502 * @param uuid The identifier of the file to be removed.
4503 * @param type The type of the file content.
4504 * @return 0 if success, other value if error.
4505 * @ingroup Callbacks
4506 **/
4507 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove(
4508 OrthancPluginContext* context,
4509 OrthancPluginStorageArea* storageArea,
4510 const char* uuid,
4511 OrthancPluginContentType type)
4512 {
4513 _OrthancPluginStorageAreaRemove params;
4514 params.storageArea = storageArea;
4515 params.uuid = uuid;
4516 params.type = type;
4517
4518 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, &params);
4519 }
4520
4521
4522
4523 typedef struct
4524 {
4525 OrthancPluginErrorCode* target;
4526 int32_t code;
4527 uint16_t httpStatus;
4528 const char* message;
4529 } _OrthancPluginRegisterErrorCode;
4530
4531 /**
4532 * @brief Declare a custom error code for this plugin.
4533 *
4534 * This function declares a custom error code that can be generated
4535 * by this plugin. This declaration is used to enrich the body of
4536 * the HTTP answer in the case of an error, and to set the proper
4537 * HTTP status code.
4538 *
4539 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4540 * @param code The error code that is internal to this plugin.
4541 * @param httpStatus The HTTP status corresponding to this error.
4542 * @param message The description of the error.
4543 * @return The error code that has been assigned inside the Orthanc core.
4544 * @ingroup Toolbox
4545 **/
4546 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode(
4547 OrthancPluginContext* context,
4548 int32_t code,
4549 uint16_t httpStatus,
4550 const char* message)
4551 {
4552 OrthancPluginErrorCode target;
4553
4554 _OrthancPluginRegisterErrorCode params;
4555 params.target = &target;
4556 params.code = code;
4557 params.httpStatus = httpStatus;
4558 params.message = message;
4559
4560 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, &params) == OrthancPluginErrorCode_Success)
4561 {
4562 return target;
4563 }
4564 else
4565 {
4566 /* There was an error while assigned the error. Use a generic code. */
4567 return OrthancPluginErrorCode_Plugin;
4568 }
4569 }
4570
4571
4572
4573 typedef struct
4574 {
4575 uint16_t group;
4576 uint16_t element;
4577 OrthancPluginValueRepresentation vr;
4578 const char* name;
4579 uint32_t minMultiplicity;
4580 uint32_t maxMultiplicity;
4581 } _OrthancPluginRegisterDictionaryTag;
4582
4583 /**
4584 * @brief Register a new tag into the DICOM dictionary.
4585 *
4586 * This function declares a new public tag in the dictionary of
4587 * DICOM tags that are known to Orthanc. This function should be
4588 * used in the OrthancPluginInitialize() callback.
4589 *
4590 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4591 * @param group The group of the tag.
4592 * @param element The element of the tag.
4593 * @param vr The value representation of the tag.
4594 * @param name The nickname of the tag.
4595 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4596 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4597 * an arbitrary multiplicity ("<tt>n</tt>").
4598 * @return 0 if success, other value if error.
4599 * @see OrthancPluginRegisterPrivateDictionaryTag()
4600 * @ingroup Toolbox
4601 **/
4602 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag(
4603 OrthancPluginContext* context,
4604 uint16_t group,
4605 uint16_t element,
4606 OrthancPluginValueRepresentation vr,
4607 const char* name,
4608 uint32_t minMultiplicity,
4609 uint32_t maxMultiplicity)
4610 {
4611 _OrthancPluginRegisterDictionaryTag params;
4612 params.group = group;
4613 params.element = element;
4614 params.vr = vr;
4615 params.name = name;
4616 params.minMultiplicity = minMultiplicity;
4617 params.maxMultiplicity = maxMultiplicity;
4618
4619 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, &params);
4620 }
4621
4622
4623
4624 typedef struct
4625 {
4626 uint16_t group;
4627 uint16_t element;
4628 OrthancPluginValueRepresentation vr;
4629 const char* name;
4630 uint32_t minMultiplicity;
4631 uint32_t maxMultiplicity;
4632 const char* privateCreator;
4633 } _OrthancPluginRegisterPrivateDictionaryTag;
4634
4635 /**
4636 * @brief Register a new private tag into the DICOM dictionary.
4637 *
4638 * This function declares a new private tag in the dictionary of
4639 * DICOM tags that are known to Orthanc. This function should be
4640 * used in the OrthancPluginInitialize() callback.
4641 *
4642 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4643 * @param group The group of the tag.
4644 * @param element The element of the tag.
4645 * @param vr The value representation of the tag.
4646 * @param name The nickname of the tag.
4647 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4648 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4649 * an arbitrary multiplicity ("<tt>n</tt>").
4650 * @param privateCreator The private creator of this private tag.
4651 * @return 0 if success, other value if error.
4652 * @see OrthancPluginRegisterDictionaryTag()
4653 * @ingroup Toolbox
4654 **/
4655 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag(
4656 OrthancPluginContext* context,
4657 uint16_t group,
4658 uint16_t element,
4659 OrthancPluginValueRepresentation vr,
4660 const char* name,
4661 uint32_t minMultiplicity,
4662 uint32_t maxMultiplicity,
4663 const char* privateCreator)
4664 {
4665 _OrthancPluginRegisterPrivateDictionaryTag params;
4666 params.group = group;
4667 params.element = element;
4668 params.vr = vr;
4669 params.name = name;
4670 params.minMultiplicity = minMultiplicity;
4671 params.maxMultiplicity = maxMultiplicity;
4672 params.privateCreator = privateCreator;
4673
4674 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, &params);
4675 }
4676
4677
4678
4679 typedef struct
4680 {
4681 OrthancPluginStorageArea* storageArea;
4682 OrthancPluginResourceType level;
4683 } _OrthancPluginReconstructMainDicomTags;
4684
4685 /**
4686 * @brief Reconstruct the main DICOM tags.
4687 *
4688 * This function requests the Orthanc core to reconstruct the main
4689 * DICOM tags of all the resources of the given type. This function
4690 * can only be used as a part of the upgrade of a custom database
4691 * back-end. A database transaction will be automatically setup.
4692 *
4693 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4694 * @param storageArea The storage area.
4695 * @param level The type of the resources of interest.
4696 * @return 0 if success, other value if error.
4697 * @ingroup Callbacks
4698 **/
4699 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags(
4700 OrthancPluginContext* context,
4701 OrthancPluginStorageArea* storageArea,
4702 OrthancPluginResourceType level)
4703 {
4704 _OrthancPluginReconstructMainDicomTags params;
4705 params.level = level;
4706 params.storageArea = storageArea;
4707
4708 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, &params);
4709 }
4710
4711
4712 typedef struct
4713 {
4714 char** result;
4715 const char* instanceId;
4716 const void* buffer;
4717 uint32_t size;
4718 OrthancPluginDicomToJsonFormat format;
4719 OrthancPluginDicomToJsonFlags flags;
4720 uint32_t maxStringLength;
4721 } _OrthancPluginDicomToJson;
4722
4723
4724 /**
4725 * @brief Format a DICOM memory buffer as a JSON string.
4726 *
4727 * This function takes as input a memory buffer containing a DICOM
4728 * file, and outputs a JSON string representing the tags of this
4729 * DICOM file.
4730 *
4731 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4732 * @param buffer The memory buffer containing the DICOM file.
4733 * @param size The size of the memory buffer.
4734 * @param format The output format.
4735 * @param flags Flags governing the output.
4736 * @param maxStringLength The maximum length of a field. Too long fields will
4737 * be output as "null". The 0 value means no maximum length.
4738 * @return The NULL value if the case of an error, or the JSON
4739 * string. This string must be freed by OrthancPluginFreeString().
4740 * @ingroup Toolbox
4741 * @see OrthancPluginDicomInstanceToJson
4742 **/
4743 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson(
4744 OrthancPluginContext* context,
4745 const void* buffer,
4746 uint32_t size,
4747 OrthancPluginDicomToJsonFormat format,
4748 OrthancPluginDicomToJsonFlags flags,
4749 uint32_t maxStringLength)
4750 {
4751 char* result;
4752
4753 _OrthancPluginDicomToJson params;
4754 memset(&params, 0, sizeof(params));
4755 params.result = &result;
4756 params.buffer = buffer;
4757 params.size = size;
4758 params.format = format;
4759 params.flags = flags;
4760 params.maxStringLength = maxStringLength;
4761
4762 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, &params) != OrthancPluginErrorCode_Success)
4763 {
4764 /* Error */
4765 return NULL;
4766 }
4767 else
4768 {
4769 return result;
4770 }
4771 }
4772
4773
4774 /**
4775 * @brief Format a DICOM instance as a JSON string.
4776 *
4777 * This function formats a DICOM instance that is stored in Orthanc,
4778 * and outputs a JSON string representing the tags of this DICOM
4779 * instance.
4780 *
4781 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4782 * @param instanceId The Orthanc identifier of the instance.
4783 * @param format The output format.
4784 * @param flags Flags governing the output.
4785 * @param maxStringLength The maximum length of a field. Too long fields will
4786 * be output as "null". The 0 value means no maximum length.
4787 * @return The NULL value if the case of an error, or the JSON
4788 * string. This string must be freed by OrthancPluginFreeString().
4789 * @ingroup Toolbox
4790 * @see OrthancPluginDicomInstanceToJson
4791 **/
4792 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson(
4793 OrthancPluginContext* context,
4794 const char* instanceId,
4795 OrthancPluginDicomToJsonFormat format,
4796 OrthancPluginDicomToJsonFlags flags,
4797 uint32_t maxStringLength)
4798 {
4799 char* result;
4800
4801 _OrthancPluginDicomToJson params;
4802 memset(&params, 0, sizeof(params));
4803 params.result = &result;
4804 params.instanceId = instanceId;
4805 params.format = format;
4806 params.flags = flags;
4807 params.maxStringLength = maxStringLength;
4808
4809 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, &params) != OrthancPluginErrorCode_Success)
4810 {
4811 /* Error */
4812 return NULL;
4813 }
4814 else
4815 {
4816 return result;
4817 }
4818 }
4819
4820
4821 typedef struct
4822 {
4823 OrthancPluginMemoryBuffer* target;
4824 const char* uri;
4825 uint32_t headersCount;
4826 const char* const* headersKeys;
4827 const char* const* headersValues;
4828 int32_t afterPlugins;
4829 } _OrthancPluginRestApiGet2;
4830
4831 /**
4832 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers.
4833 *
4834 * Make a GET call to the Orthanc REST API with extended
4835 * parameters. The result to the query is stored into a newly
4836 * allocated memory buffer.
4837 *
4838 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4839 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4840 * @param uri The URI in the built-in Orthanc API.
4841 * @param headersCount The number of HTTP headers.
4842 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
4843 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
4844 * @param afterPlugins If 0, the built-in API of Orthanc is used.
4845 * If 1, the API is tainted by the plugins.
4846 * @return 0 if success, or the error code if failure.
4847 * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins
4848 * @ingroup Orthanc
4849 **/
4850 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2(
4851 OrthancPluginContext* context,
4852 OrthancPluginMemoryBuffer* target,
4853 const char* uri,
4854 uint32_t headersCount,
4855 const char* const* headersKeys,
4856 const char* const* headersValues,
4857 int32_t afterPlugins)
4858 {
4859 _OrthancPluginRestApiGet2 params;
4860 params.target = target;
4861 params.uri = uri;
4862 params.headersCount = headersCount;
4863 params.headersKeys = headersKeys;
4864 params.headersValues = headersValues;
4865 params.afterPlugins = afterPlugins;
4866
4867 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, &params);
4868 }
4869
4870
4871
4872 typedef struct
4873 {
4874 OrthancPluginWorklistCallback callback;
4875 } _OrthancPluginWorklistCallback;
4876
4877 /**
4878 * @brief Register a callback to handle modality worklists requests.
4879 *
4880 * This function registers a callback to handle C-Find SCP requests
4881 * on modality worklists.
4882 *
4883 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4884 * @param callback The callback.
4885 * @return 0 if success, other value if error.
4886 * @ingroup DicomCallbacks
4887 **/
4888 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback(
4889 OrthancPluginContext* context,
4890 OrthancPluginWorklistCallback callback)
4891 {
4892 _OrthancPluginWorklistCallback params;
4893 params.callback = callback;
4894
4895 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, &params);
4896 }
4897
4898
4899
4900 typedef struct
4901 {
4902 OrthancPluginWorklistAnswers* answers;
4903 const OrthancPluginWorklistQuery* query;
4904 const void* dicom;
4905 uint32_t size;
4906 } _OrthancPluginWorklistAnswersOperation;
4907
4908 /**
4909 * @brief Add one answer to some modality worklist request.
4910 *
4911 * This function adds one worklist (encoded as a DICOM file) to the
4912 * set of answers corresponding to some C-Find SCP request against
4913 * modality worklists.
4914 *
4915 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4916 * @param answers The set of answers.
4917 * @param query The worklist query, as received by the callback.
4918 * @param dicom The worklist to answer, encoded as a DICOM file.
4919 * @param size The size of the DICOM file.
4920 * @return 0 if success, other value if error.
4921 * @ingroup DicomCallbacks
4922 * @see OrthancPluginCreateDicom()
4923 **/
4924 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer(
4925 OrthancPluginContext* context,
4926 OrthancPluginWorklistAnswers* answers,
4927 const OrthancPluginWorklistQuery* query,
4928 const void* dicom,
4929 uint32_t size)
4930 {
4931 _OrthancPluginWorklistAnswersOperation params;
4932 params.answers = answers;
4933 params.query = query;
4934 params.dicom = dicom;
4935 params.size = size;
4936
4937 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, &params);
4938 }
4939
4940
4941 /**
4942 * @brief Mark the set of worklist answers as incomplete.
4943 *
4944 * This function marks as incomplete the set of answers
4945 * corresponding to some C-Find SCP request against modality
4946 * worklists. This must be used if canceling the handling of a
4947 * request when too many answers are to be returned.
4948 *
4949 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4950 * @param answers The set of answers.
4951 * @return 0 if success, other value if error.
4952 * @ingroup DicomCallbacks
4953 **/
4954 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete(
4955 OrthancPluginContext* context,
4956 OrthancPluginWorklistAnswers* answers)
4957 {
4958 _OrthancPluginWorklistAnswersOperation params;
4959 params.answers = answers;
4960 params.query = NULL;
4961 params.dicom = NULL;
4962 params.size = 0;
4963
4964 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, &params);
4965 }
4966
4967
4968 typedef struct
4969 {
4970 const OrthancPluginWorklistQuery* query;
4971 const void* dicom;
4972 uint32_t size;
4973 int32_t* isMatch;
4974 OrthancPluginMemoryBuffer* target;
4975 } _OrthancPluginWorklistQueryOperation;
4976
4977 /**
4978 * @brief Test whether a worklist matches the query.
4979 *
4980 * This function checks whether one worklist (encoded as a DICOM
4981 * file) matches the C-Find SCP query against modality
4982 * worklists. This function must be called before adding the
4983 * worklist as an answer through OrthancPluginWorklistAddAnswer().
4984 *
4985 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4986 * @param query The worklist query, as received by the callback.
4987 * @param dicom The worklist to answer, encoded as a DICOM file.
4988 * @param size The size of the DICOM file.
4989 * @return 1 if the worklist matches the query, 0 otherwise.
4990 * @ingroup DicomCallbacks
4991 **/
4992 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch(
4993 OrthancPluginContext* context,
4994 const OrthancPluginWorklistQuery* query,
4995 const void* dicom,
4996 uint32_t size)
4997 {
4998 int32_t isMatch = 0;
4999
5000 _OrthancPluginWorklistQueryOperation params;
5001 params.query = query;
5002 params.dicom = dicom;
5003 params.size = size;
5004 params.isMatch = &isMatch;
5005 params.target = NULL;
5006
5007 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, &params) == OrthancPluginErrorCode_Success)
5008 {
5009 return isMatch;
5010 }
5011 else
5012 {
5013 /* Error: Assume non-match */
5014 return 0;
5015 }
5016 }
5017
5018
5019 /**
5020 * @brief Retrieve the worklist query as a DICOM file.
5021 *
5022 * This function retrieves the DICOM file that underlies a C-Find
5023 * SCP query against modality worklists.
5024 *
5025 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5026 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer().
5027 * @param query The worklist query, as received by the callback.
5028 * @return 0 if success, other value if error.
5029 * @ingroup DicomCallbacks
5030 **/
5031 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery(
5032 OrthancPluginContext* context,
5033 OrthancPluginMemoryBuffer* target,
5034 const OrthancPluginWorklistQuery* query)
5035 {
5036 _OrthancPluginWorklistQueryOperation params;
5037 params.query = query;
5038 params.dicom = NULL;
5039 params.size = 0;
5040 params.isMatch = NULL;
5041 params.target = target;
5042
5043 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, &params);
5044 }
5045
5046
5047 /**
5048 * @brief Get the origin of a DICOM file.
5049 *
5050 * This function returns the origin of a DICOM instance that has been received by Orthanc.
5051 *
5052 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5053 * @param instance The instance of interest.
5054 * @return The origin of the instance.
5055 * @ingroup Callbacks
5056 **/
5057 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin(
5058 OrthancPluginContext* context,
5059 OrthancPluginDicomInstance* instance)
5060 {
5061 OrthancPluginInstanceOrigin origin;
5062
5063 _OrthancPluginAccessDicomInstance params;
5064 memset(&params, 0, sizeof(params));
5065 params.resultOrigin = &origin;
5066 params.instance = instance;
5067
5068 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, &params) != OrthancPluginErrorCode_Success)
5069 {
5070 /* Error */
5071 return OrthancPluginInstanceOrigin_Unknown;
5072 }
5073 else
5074 {
5075 return origin;
5076 }
5077 }
5078
5079
5080 typedef struct
5081 {
5082 OrthancPluginMemoryBuffer* target;
5083 const char* json;
5084 const OrthancPluginImage* pixelData;
5085 OrthancPluginCreateDicomFlags flags;
5086 } _OrthancPluginCreateDicom;
5087
5088 /**
5089 * @brief Create a DICOM instance from a JSON string and an image.
5090 *
5091 * This function takes as input a string containing a JSON file
5092 * describing the content of a DICOM instance. As an output, it
5093 * writes the corresponding DICOM instance to a newly allocated
5094 * memory buffer. Additionally, an image to be encoded within the
5095 * DICOM instance can also be provided.
5096 *
5097 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5098 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
5099 * @param json The input JSON file.
5100 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.
5101 * @param flags Flags governing the output.
5102 * @return 0 if success, other value if error.
5103 * @ingroup Toolbox
5104 * @see OrthancPluginDicomBufferToJson
5105 **/
5106 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom(
5107 OrthancPluginContext* context,
5108 OrthancPluginMemoryBuffer* target,
5109 const char* json,
5110 const OrthancPluginImage* pixelData,
5111 OrthancPluginCreateDicomFlags flags)
5112 {
5113 _OrthancPluginCreateDicom params;
5114 params.target = target;
5115 params.json = json;
5116 params.pixelData = pixelData;
5117 params.flags = flags;
5118
5119 return context->InvokeService(context, _OrthancPluginService_CreateDicom, &params);
5120 }
5121
5122
5123 typedef struct
5124 {
5125 OrthancPluginDecodeImageCallback callback;
5126 } _OrthancPluginDecodeImageCallback;
5127
5128 /**
5129 * @brief Register a callback to handle the decoding of DICOM images.
5130 *
5131 * This function registers a custom callback to the decoding of
5132 * DICOM images, replacing the built-in decoder of Orthanc.
5133 *
5134 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5135 * @param callback The callback.
5136 * @return 0 if success, other value if error.
5137 * @ingroup Callbacks
5138 **/
5139 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback(
5140 OrthancPluginContext* context,
5141 OrthancPluginDecodeImageCallback callback)
5142 {
5143 _OrthancPluginDecodeImageCallback params;
5144 params.callback = callback;
5145
5146 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, &params);
5147 }
5148
5149
5150
5151 typedef struct
5152 {
5153 OrthancPluginImage** target;
5154 OrthancPluginPixelFormat format;
5155 uint32_t width;
5156 uint32_t height;
5157 uint32_t pitch;
5158 void* buffer;
5159 const void* constBuffer;
5160 uint32_t bufferSize;
5161 uint32_t frameIndex;
5162 } _OrthancPluginCreateImage;
5163
5164
5165 /**
5166 * @brief Create an image.
5167 *
5168 * This function creates an image of given size and format.
5169 *
5170 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5171 * @param format The format of the pixels.
5172 * @param width The width of the image.
5173 * @param height The height of the image.
5174 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5175 * @ingroup Images
5176 **/
5177 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage(
5178 OrthancPluginContext* context,
5179 OrthancPluginPixelFormat format,
5180 uint32_t width,
5181 uint32_t height)
5182 {
5183 OrthancPluginImage* target = NULL;
5184
5185 _OrthancPluginCreateImage params;
5186 memset(&params, 0, sizeof(params));
5187 params.target = &target;
5188 params.format = format;
5189 params.width = width;
5190 params.height = height;
5191
5192 if (context->InvokeService(context, _OrthancPluginService_CreateImage, &params) != OrthancPluginErrorCode_Success)
5193 {
5194 return NULL;
5195 }
5196 else
5197 {
5198 return target;
5199 }
5200 }
5201
5202
5203 /**
5204 * @brief Create an image pointing to a memory buffer.
5205 *
5206 * This function creates an image whose content points to a memory
5207 * buffer managed by the plugin. Note that the buffer is directly
5208 * accessed, no memory is allocated and no data is copied.
5209 *
5210 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5211 * @param format The format of the pixels.
5212 * @param width The width of the image.
5213 * @param height The height of the image.
5214 * @param pitch The pitch of the image (i.e. the number of bytes
5215 * between 2 successive lines of the image in the memory buffer).
5216 * @param buffer The memory buffer.
5217 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5218 * @ingroup Images
5219 **/
5220 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor(
5221 OrthancPluginContext* context,
5222 OrthancPluginPixelFormat format,
5223 uint32_t width,
5224 uint32_t height,
5225 uint32_t pitch,
5226 void* buffer)
5227 {
5228 OrthancPluginImage* target = NULL;
5229
5230 _OrthancPluginCreateImage params;
5231 memset(&params, 0, sizeof(params));
5232 params.target = &target;
5233 params.format = format;
5234 params.width = width;
5235 params.height = height;
5236 params.pitch = pitch;
5237 params.buffer = buffer;
5238
5239 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, &params) != OrthancPluginErrorCode_Success)
5240 {
5241 return NULL;
5242 }
5243 else
5244 {
5245 return target;
5246 }
5247 }
5248
5249
5250
5251 /**
5252 * @brief Decode one frame from a DICOM instance.
5253 *
5254 * This function decodes one frame of a DICOM image that is stored
5255 * in a memory buffer. This function will give the same result as
5256 * OrthancPluginUncompressImage() for single-frame DICOM images.
5257 *
5258 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5259 * @param buffer Pointer to a memory buffer containing the DICOM image.
5260 * @param bufferSize Size of the memory buffer containing the DICOM image.
5261 * @param frameIndex The index of the frame of interest in a multi-frame image.
5262 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
5263 * @ingroup Images
5264 **/
5265 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage(
5266 OrthancPluginContext* context,
5267 const void* buffer,
5268 uint32_t bufferSize,
5269 uint32_t frameIndex)
5270 {
5271 OrthancPluginImage* target = NULL;
5272
5273 _OrthancPluginCreateImage params;
5274 memset(&params, 0, sizeof(params));
5275 params.target = &target;
5276 params.constBuffer = buffer;
5277 params.bufferSize = bufferSize;
5278 params.frameIndex = frameIndex;
5279
5280 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, &params) != OrthancPluginErrorCode_Success)
5281 {
5282 return NULL;
5283 }
5284 else
5285 {
5286 return target;
5287 }
5288 }
5289
5290
5291
5292 typedef struct
5293 {
5294 char** result;
5295 const void* buffer;
5296 uint32_t size;
5297 } _OrthancPluginComputeHash;
5298
5299 /**
5300 * @brief Compute an MD5 hash.
5301 *
5302 * This functions computes the MD5 cryptographic hash of the given memory buffer.
5303 *
5304 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5305 * @param buffer The source memory buffer.
5306 * @param size The size in bytes of the source buffer.
5307 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5308 * This string must be freed by OrthancPluginFreeString().
5309 * @ingroup Toolbox
5310 **/
5311 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5(
5312 OrthancPluginContext* context,
5313 const void* buffer,
5314 uint32_t size)
5315 {
5316 char* result;
5317
5318 _OrthancPluginComputeHash params;
5319 params.result = &result;
5320 params.buffer = buffer;
5321 params.size = size;
5322
5323 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, &params) != OrthancPluginErrorCode_Success)
5324 {
5325 /* Error */
5326 return NULL;
5327 }
5328 else
5329 {
5330 return result;
5331 }
5332 }
5333
5334
5335 /**
5336 * @brief Compute a SHA-1 hash.
5337 *
5338 * This functions computes the SHA-1 cryptographic hash of the given memory buffer.
5339 *
5340 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5341 * @param buffer The source memory buffer.
5342 * @param size The size in bytes of the source buffer.
5343 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5344 * This string must be freed by OrthancPluginFreeString().
5345 * @ingroup Toolbox
5346 **/
5347 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1(
5348 OrthancPluginContext* context,
5349 const void* buffer,
5350 uint32_t size)
5351 {
5352 char* result;
5353
5354 _OrthancPluginComputeHash params;
5355 params.result = &result;
5356 params.buffer = buffer;
5357 params.size = size;
5358
5359 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, &params) != OrthancPluginErrorCode_Success)
5360 {
5361 /* Error */
5362 return NULL;
5363 }
5364 else
5365 {
5366 return result;
5367 }
5368 }
5369
5370
5371
5372 typedef struct
5373 {
5374 OrthancPluginDictionaryEntry* target;
5375 const char* name;
5376 } _OrthancPluginLookupDictionary;
5377
5378 /**
5379 * @brief Get information about the given DICOM tag.
5380 *
5381 * This functions makes a lookup in the dictionary of DICOM tags
5382 * that are known to Orthanc, and returns information about this
5383 * tag. The tag can be specified using its human-readable name
5384 * (e.g. "PatientName") or a set of two hexadecimal numbers
5385 * (e.g. "0010-0020").
5386 *
5387 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5388 * @param target Where to store the information about the tag.
5389 * @param name The name of the DICOM tag.
5390 * @return 0 if success, other value if error.
5391 * @ingroup Toolbox
5392 **/
5393 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary(
5394 OrthancPluginContext* context,
5395 OrthancPluginDictionaryEntry* target,
5396 const char* name)
5397 {
5398 _OrthancPluginLookupDictionary params;
5399 params.target = target;
5400 params.name = name;
5401 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, &params);
5402 }
5403
5404
5405
5406 typedef struct
5407 {
5408 OrthancPluginRestOutput* output;
5409 const char* answer;
5410 uint32_t answerSize;
5411 uint32_t headersCount;
5412 const char* const* headersKeys;
5413 const char* const* headersValues;
5414 } _OrthancPluginSendMultipartItem2;
5415
5416 /**
5417 * @brief Send an item as a part of some HTTP multipart answer, with custom headers.
5418 *
5419 * This function sends an item as a part of some HTTP multipart
5420 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to
5421 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated
5422 * with the item.
5423 *
5424 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5425 * @param output The HTTP connection to the client application.
5426 * @param answer Pointer to the memory buffer containing the item.
5427 * @param answerSize Number of bytes of the item.
5428 * @param headersCount The number of HTTP headers.
5429 * @param headersKeys Array containing the keys of the HTTP headers.
5430 * @param headersValues Array containing the values of the HTTP headers.
5431 * @return 0 if success, or the error code if failure (this notably happens
5432 * if the connection is closed by the client).
5433 * @see OrthancPluginSendMultipartItem()
5434 * @ingroup REST
5435 **/
5436 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2(
5437 OrthancPluginContext* context,
5438 OrthancPluginRestOutput* output,
5439 const char* answer,
5440 uint32_t answerSize,
5441 uint32_t headersCount,
5442 const char* const* headersKeys,
5443 const char* const* headersValues)
5444 {
5445 _OrthancPluginSendMultipartItem2 params;
5446 params.output = output;
5447 params.answer = answer;
5448 params.answerSize = answerSize;
5449 params.headersCount = headersCount;
5450 params.headersKeys = headersKeys;
5451 params.headersValues = headersValues;
5452
5453 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, &params);
5454 }
5455
5456
5457 typedef struct
5458 {
5459 OrthancPluginIncomingHttpRequestFilter callback;
5460 } _OrthancPluginIncomingHttpRequestFilter;
5461
5462 /**
5463 * @brief Register a callback to filter incoming HTTP requests.
5464 *
5465 * This function registers a custom callback to filter incoming HTTP/REST
5466 * requests received by the HTTP server of Orthanc.
5467 *
5468 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5469 * @param callback The callback.
5470 * @return 0 if success, other value if error.
5471 * @ingroup Callbacks
5472 * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2()
5473 **/
5474 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter(
5475 OrthancPluginContext* context,
5476 OrthancPluginIncomingHttpRequestFilter callback)
5477 {
5478 _OrthancPluginIncomingHttpRequestFilter params;
5479 params.callback = callback;
5480
5481 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, &params);
5482 }
5483
5484
5485
5486 typedef struct
5487 {
5488 OrthancPluginMemoryBuffer* answerBody;
5489 OrthancPluginMemoryBuffer* answerHeaders;
5490 uint16_t* httpStatus;
5491 OrthancPluginHttpMethod method;
5492 const char* url;
5493 uint32_t headersCount;
5494 const char* const* headersKeys;
5495 const char* const* headersValues;
5496 const void* body;
5497 uint32_t bodySize;
5498 const char* username;
5499 const char* password;
5500 uint32_t timeout;
5501 const char* certificateFile;
5502 const char* certificateKeyFile;
5503 const char* certificateKeyPassword;
5504 uint8_t pkcs11;
5505 } _OrthancPluginCallHttpClient2;
5506
5507
5508
5509 /**
5510 * @brief Issue a HTTP call with full flexibility.
5511 *
5512 * Make a HTTP call to the given URL. The result to the query is
5513 * stored into a newly allocated memory buffer. The HTTP request
5514 * will be done accordingly to the global configuration of Orthanc
5515 * (in particular, the options "HttpProxy", "HttpTimeout",
5516 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be
5517 * taken into account).
5518 *
5519 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5520 * @param answerBody The target memory buffer (out argument).
5521 * It must be freed with OrthancPluginFreeMemoryBuffer().
5522 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
5523 * The answer headers are formatted as a JSON object (associative array).
5524 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
5525 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
5526 * @param httpStatus The HTTP status after the execution of the request (out argument).
5527 * @param method HTTP method to be used.
5528 * @param url The URL of interest.
5529 * @param headersCount The number of HTTP headers.
5530 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
5531 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
5532 * @param username The username (can be <tt>NULL</tt> if no password protection).
5533 * @param password The password (can be <tt>NULL</tt> if no password protection).
5534 * @param body The HTTP body for a POST or PUT request.
5535 * @param bodySize The size of the body.
5536 * @param timeout Timeout in seconds (0 for default timeout).
5537 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
5538 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5539 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
5540 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5541 * @param certificateKeyPassword Password to unlock the key of the client certificate
5542 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5543 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
5544 * @return 0 if success, or the error code if failure.
5545 * @see OrthancPluginCallPeerApi()
5546 * @ingroup Toolbox
5547 **/
5548 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient(
5549 OrthancPluginContext* context,
5550 OrthancPluginMemoryBuffer* answerBody,
5551 OrthancPluginMemoryBuffer* answerHeaders,
5552 uint16_t* httpStatus,
5553 OrthancPluginHttpMethod method,
5554 const char* url,
5555 uint32_t headersCount,
5556 const char* const* headersKeys,
5557 const char* const* headersValues,
5558 const void* body,
5559 uint32_t bodySize,
5560 const char* username,
5561 const char* password,
5562 uint32_t timeout,
5563 const char* certificateFile,
5564 const char* certificateKeyFile,
5565 const char* certificateKeyPassword,
5566 uint8_t pkcs11)
5567 {
5568 _OrthancPluginCallHttpClient2 params;
5569 memset(&params, 0, sizeof(params));
5570
5571 params.answerBody = answerBody;
5572 params.answerHeaders = answerHeaders;
5573 params.httpStatus = httpStatus;
5574 params.method = method;
5575 params.url = url;
5576 params.headersCount = headersCount;
5577 params.headersKeys = headersKeys;
5578 params.headersValues = headersValues;
5579 params.body = body;
5580 params.bodySize = bodySize;
5581 params.username = username;
5582 params.password = password;
5583 params.timeout = timeout;
5584 params.certificateFile = certificateFile;
5585 params.certificateKeyFile = certificateKeyFile;
5586 params.certificateKeyPassword = certificateKeyPassword;
5587 params.pkcs11 = pkcs11;
5588
5589 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, &params);
5590 }
5591
5592
5593 /**
5594 * @brief Generate an UUID.
5595 *
5596 * Generate a random GUID/UUID (globally unique identifier).
5597 *
5598 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5599 * @return NULL in the case of an error, or a newly allocated string
5600 * containing the UUID. This string must be freed by OrthancPluginFreeString().
5601 * @ingroup Toolbox
5602 **/
5603 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid(
5604 OrthancPluginContext* context)
5605 {
5606 char* result;
5607
5608 _OrthancPluginRetrieveDynamicString params;
5609 params.result = &result;
5610 params.argument = NULL;
5611
5612 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, &params) != OrthancPluginErrorCode_Success)
5613 {
5614 /* Error */
5615 return NULL;
5616 }
5617 else
5618 {
5619 return result;
5620 }
5621 }
5622
5623
5624
5625
5626 typedef struct
5627 {
5628 OrthancPluginFindCallback callback;
5629 } _OrthancPluginFindCallback;
5630
5631 /**
5632 * @brief Register a callback to handle C-Find requests.
5633 *
5634 * This function registers a callback to handle C-Find SCP requests
5635 * that are not related to modality worklists.
5636 *
5637 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5638 * @param callback The callback.
5639 * @return 0 if success, other value if error.
5640 * @ingroup DicomCallbacks
5641 **/
5642 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback(
5643 OrthancPluginContext* context,
5644 OrthancPluginFindCallback callback)
5645 {
5646 _OrthancPluginFindCallback params;
5647 params.callback = callback;
5648
5649 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, &params);
5650 }
5651
5652
5653 typedef struct
5654 {
5655 OrthancPluginFindAnswers *answers;
5656 const OrthancPluginFindQuery *query;
5657 const void *dicom;
5658 uint32_t size;
5659 uint32_t index;
5660 uint32_t *resultUint32;
5661 uint16_t *resultGroup;
5662 uint16_t *resultElement;
5663 char **resultString;
5664 } _OrthancPluginFindOperation;
5665
5666 /**
5667 * @brief Add one answer to some C-Find request.
5668 *
5669 * This function adds one answer (encoded as a DICOM file) to the
5670 * set of answers corresponding to some C-Find SCP request that is
5671 * not related to modality worklists.
5672 *
5673 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5674 * @param answers The set of answers.
5675 * @param dicom The answer to be added, encoded as a DICOM file.
5676 * @param size The size of the DICOM file.
5677 * @return 0 if success, other value if error.
5678 * @ingroup DicomCallbacks
5679 * @see OrthancPluginCreateDicom()
5680 **/
5681 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer(
5682 OrthancPluginContext* context,
5683 OrthancPluginFindAnswers* answers,
5684 const void* dicom,
5685 uint32_t size)
5686 {
5687 _OrthancPluginFindOperation params;
5688 memset(&params, 0, sizeof(params));
5689 params.answers = answers;
5690 params.dicom = dicom;
5691 params.size = size;
5692
5693 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, &params);
5694 }
5695
5696
5697 /**
5698 * @brief Mark the set of C-Find answers as incomplete.
5699 *
5700 * This function marks as incomplete the set of answers
5701 * corresponding to some C-Find SCP request that is not related to
5702 * modality worklists. This must be used if canceling the handling
5703 * of a request when too many answers are to be returned.
5704 *
5705 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5706 * @param answers The set of answers.
5707 * @return 0 if success, other value if error.
5708 * @ingroup DicomCallbacks
5709 **/
5710 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete(
5711 OrthancPluginContext* context,
5712 OrthancPluginFindAnswers* answers)
5713 {
5714 _OrthancPluginFindOperation params;
5715 memset(&params, 0, sizeof(params));
5716 params.answers = answers;
5717
5718 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, &params);
5719 }
5720
5721
5722
5723 /**
5724 * @brief Get the number of tags in a C-Find query.
5725 *
5726 * This function returns the number of tags that are contained in
5727 * the given C-Find query.
5728 *
5729 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5730 * @param query The C-Find query.
5731 * @return The number of tags.
5732 * @ingroup DicomCallbacks
5733 **/
5734 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize(
5735 OrthancPluginContext* context,
5736 const OrthancPluginFindQuery* query)
5737 {
5738 uint32_t count = 0;
5739
5740 _OrthancPluginFindOperation params;
5741 memset(&params, 0, sizeof(params));
5742 params.query = query;
5743 params.resultUint32 = &count;
5744
5745 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, &params) != OrthancPluginErrorCode_Success)
5746 {
5747 /* Error */
5748 return 0;
5749 }
5750 else
5751 {
5752 return count;
5753 }
5754 }
5755
5756
5757 /**
5758 * @brief Get one tag in a C-Find query.
5759 *
5760 * This function returns the group and the element of one DICOM tag
5761 * in the given C-Find query.
5762 *
5763 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5764 * @param group The group of the tag (output).
5765 * @param element The element of the tag (output).
5766 * @param query The C-Find query.
5767 * @param index The index of the tag of interest.
5768 * @return 0 if success, other value if error.
5769 * @ingroup DicomCallbacks
5770 **/
5771 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag(
5772 OrthancPluginContext* context,
5773 uint16_t* group,
5774 uint16_t* element,
5775 const OrthancPluginFindQuery* query,
5776 uint32_t index)
5777 {
5778 _OrthancPluginFindOperation params;
5779 memset(&params, 0, sizeof(params));
5780 params.query = query;
5781 params.index = index;
5782 params.resultGroup = group;
5783 params.resultElement = element;
5784
5785 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, &params);
5786 }
5787
5788
5789 /**
5790 * @brief Get the symbolic name of one tag in a C-Find query.
5791 *
5792 * This function returns the symbolic name of one DICOM tag in the
5793 * given C-Find query.
5794 *
5795 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5796 * @param query The C-Find query.
5797 * @param index The index of the tag of interest.
5798 * @return The NULL value in case of error, or a string containing the name of the tag.
5799 * @return 0 if success, other value if error.
5800 * @ingroup DicomCallbacks
5801 **/
5802 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName(
5803 OrthancPluginContext* context,
5804 const OrthancPluginFindQuery* query,
5805 uint32_t index)
5806 {
5807 char* result;
5808
5809 _OrthancPluginFindOperation params;
5810 memset(&params, 0, sizeof(params));
5811 params.query = query;
5812 params.index = index;
5813 params.resultString = &result;
5814
5815 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, &params) != OrthancPluginErrorCode_Success)
5816 {
5817 /* Error */
5818 return NULL;
5819 }
5820 else
5821 {
5822 return result;
5823 }
5824 }
5825
5826
5827 /**
5828 * @brief Get the value associated with one tag in a C-Find query.
5829 *
5830 * This function returns the value associated with one tag in the
5831 * given C-Find query.
5832 *
5833 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5834 * @param query The C-Find query.
5835 * @param index The index of the tag of interest.
5836 * @return The NULL value in case of error, or a string containing the value of the tag.
5837 * @return 0 if success, other value if error.
5838 * @ingroup DicomCallbacks
5839 **/
5840 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue(
5841 OrthancPluginContext* context,
5842 const OrthancPluginFindQuery* query,
5843 uint32_t index)
5844 {
5845 char* result;
5846
5847 _OrthancPluginFindOperation params;
5848 memset(&params, 0, sizeof(params));
5849 params.query = query;
5850 params.index = index;
5851 params.resultString = &result;
5852
5853 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, &params) != OrthancPluginErrorCode_Success)
5854 {
5855 /* Error */
5856 return NULL;
5857 }
5858 else
5859 {
5860 return result;
5861 }
5862 }
5863
5864
5865
5866
5867 typedef struct
5868 {
5869 OrthancPluginMoveCallback callback;
5870 OrthancPluginGetMoveSize getMoveSize;
5871 OrthancPluginApplyMove applyMove;
5872 OrthancPluginFreeMove freeMove;
5873 } _OrthancPluginMoveCallback;
5874
5875 /**
5876 * @brief Register a callback to handle C-Move requests.
5877 *
5878 * This function registers a callback to handle C-Move SCP requests.
5879 *
5880 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5881 * @param callback The main callback.
5882 * @param getMoveSize Callback to read the number of C-Move suboperations.
5883 * @param applyMove Callback to apply one C-Move suboperation.
5884 * @param freeMove Callback to free the C-Move driver.
5885 * @return 0 if success, other value if error.
5886 * @ingroup DicomCallbacks
5887 **/
5888 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback(
5889 OrthancPluginContext* context,
5890 OrthancPluginMoveCallback callback,
5891 OrthancPluginGetMoveSize getMoveSize,
5892 OrthancPluginApplyMove applyMove,
5893 OrthancPluginFreeMove freeMove)
5894 {
5895 _OrthancPluginMoveCallback params;
5896 params.callback = callback;
5897 params.getMoveSize = getMoveSize;
5898 params.applyMove = applyMove;
5899 params.freeMove = freeMove;
5900
5901 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, &params);
5902 }
5903
5904
5905
5906 typedef struct
5907 {
5908 OrthancPluginFindMatcher** target;
5909 const void* query;
5910 uint32_t size;
5911 } _OrthancPluginCreateFindMatcher;
5912
5913
5914 /**
5915 * @brief Create a C-Find matcher.
5916 *
5917 * This function creates a "matcher" object that can be used to
5918 * check whether a DICOM instance matches a C-Find query. The C-Find
5919 * query must be expressed as a DICOM buffer.
5920 *
5921 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5922 * @param query The C-Find DICOM query.
5923 * @param size The size of the DICOM query.
5924 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher().
5925 * @ingroup Toolbox
5926 **/
5927 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher(
5928 OrthancPluginContext* context,
5929 const void* query,
5930 uint32_t size)
5931 {
5932 OrthancPluginFindMatcher* target = NULL;
5933
5934 _OrthancPluginCreateFindMatcher params;
5935 memset(&params, 0, sizeof(params));
5936 params.target = &target;
5937 params.query = query;
5938 params.size = size;
5939
5940 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, &params) != OrthancPluginErrorCode_Success)
5941 {
5942 return NULL;
5943 }
5944 else
5945 {
5946 return target;
5947 }
5948 }
5949
5950
5951 typedef struct
5952 {
5953 OrthancPluginFindMatcher* matcher;
5954 } _OrthancPluginFreeFindMatcher;
5955
5956 /**
5957 * @brief Free a C-Find matcher.
5958 *
5959 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher().
5960 *
5961 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5962 * @param matcher The matcher of interest.
5963 * @ingroup Toolbox
5964 **/
5965 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher(
5966 OrthancPluginContext* context,
5967 OrthancPluginFindMatcher* matcher)
5968 {
5969 _OrthancPluginFreeFindMatcher params;
5970 params.matcher = matcher;
5971
5972 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, &params);
5973 }
5974
5975
5976 typedef struct
5977 {
5978 const OrthancPluginFindMatcher* matcher;
5979 const void* dicom;
5980 uint32_t size;
5981 int32_t* isMatch;
5982 } _OrthancPluginFindMatcherIsMatch;
5983
5984 /**
5985 * @brief Test whether a DICOM instance matches a C-Find query.
5986 *
5987 * This function checks whether one DICOM instance matches C-Find
5988 * matcher that was previously allocated using
5989 * OrthancPluginCreateFindMatcher().
5990 *
5991 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5992 * @param matcher The matcher of interest.
5993 * @param dicom The DICOM instance to be matched.
5994 * @param size The size of the DICOM instance.
5995 * @return 1 if the DICOM instance matches the query, 0 otherwise.
5996 * @ingroup Toolbox
5997 **/
5998 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch(
5999 OrthancPluginContext* context,
6000 const OrthancPluginFindMatcher* matcher,
6001 const void* dicom,
6002 uint32_t size)
6003 {
6004 int32_t isMatch = 0;
6005
6006 _OrthancPluginFindMatcherIsMatch params;
6007 params.matcher = matcher;
6008 params.dicom = dicom;
6009 params.size = size;
6010 params.isMatch = &isMatch;
6011
6012 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, &params) == OrthancPluginErrorCode_Success)
6013 {
6014 return isMatch;
6015 }
6016 else
6017 {
6018 /* Error: Assume non-match */
6019 return 0;
6020 }
6021 }
6022
6023
6024 typedef struct
6025 {
6026 OrthancPluginIncomingHttpRequestFilter2 callback;
6027 } _OrthancPluginIncomingHttpRequestFilter2;
6028
6029 /**
6030 * @brief Register a callback to filter incoming HTTP requests.
6031 *
6032 * This function registers a custom callback to filter incoming HTTP/REST
6033 * requests received by the HTTP server of Orthanc.
6034 *
6035 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6036 * @param callback The callback.
6037 * @return 0 if success, other value if error.
6038 * @ingroup Callbacks
6039 **/
6040 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter2(
6041 OrthancPluginContext* context,
6042 OrthancPluginIncomingHttpRequestFilter2 callback)
6043 {
6044 _OrthancPluginIncomingHttpRequestFilter2 params;
6045 params.callback = callback;
6046
6047 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, &params);
6048 }
6049
6050
6051
6052 typedef struct
6053 {
6054 OrthancPluginPeers** peers;
6055 } _OrthancPluginGetPeers;
6056
6057 /**
6058 * @brief Return the list of available Orthanc peers.
6059 *
6060 * This function returns the parameters of the Orthanc peers that are known to
6061 * the Orthanc server hosting the plugin.
6062 *
6063 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6064 * @return NULL if error, or a newly allocated opaque data structure containing the peers.
6065 * This structure must be freed with OrthancPluginFreePeers().
6066 * @ingroup Toolbox
6067 **/
6068 ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers(
6069 OrthancPluginContext* context)
6070 {
6071 OrthancPluginPeers* peers = NULL;
6072
6073 _OrthancPluginGetPeers params;
6074 memset(&params, 0, sizeof(params));
6075 params.peers = &peers;
6076
6077 if (context->InvokeService(context, _OrthancPluginService_GetPeers, &params) != OrthancPluginErrorCode_Success)
6078 {
6079 return NULL;
6080 }
6081 else
6082 {
6083 return peers;
6084 }
6085 }
6086
6087
6088 typedef struct
6089 {
6090 OrthancPluginPeers* peers;
6091 } _OrthancPluginFreePeers;
6092
6093 /**
6094 * @brief Free the list of available Orthanc peers.
6095 *
6096 * This function frees the data structure returned by OrthancPluginGetPeers().
6097 *
6098 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6099 * @param peers The data structure describing the Orthanc peers.
6100 * @ingroup Toolbox
6101 **/
6102 ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers(
6103 OrthancPluginContext* context,
6104 OrthancPluginPeers* peers)
6105 {
6106 _OrthancPluginFreePeers params;
6107 params.peers = peers;
6108
6109 context->InvokeService(context, _OrthancPluginService_FreePeers, &params);
6110 }
6111
6112
6113 typedef struct
6114 {
6115 uint32_t* target;
6116 const OrthancPluginPeers* peers;
6117 } _OrthancPluginGetPeersCount;
6118
6119 /**
6120 * @brief Get the number of Orthanc peers.
6121 *
6122 * This function returns the number of Orthanc peers.
6123 *
6124 * This function is thread-safe: Several threads sharing the same
6125 * OrthancPluginPeers object can simultaneously call this function.
6126 *
6127 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6128 * @param peers The data structure describing the Orthanc peers.
6129 * @result The number of peers.
6130 * @ingroup Toolbox
6131 **/
6132 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount(
6133 OrthancPluginContext* context,
6134 const OrthancPluginPeers* peers)
6135 {
6136 uint32_t target = 0;
6137
6138 _OrthancPluginGetPeersCount params;
6139 memset(&params, 0, sizeof(params));
6140 params.target = &target;
6141 params.peers = peers;
6142
6143 if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, &params) != OrthancPluginErrorCode_Success)
6144 {
6145 /* Error */
6146 return 0;
6147 }
6148 else
6149 {
6150 return target;
6151 }
6152 }
6153
6154
6155 typedef struct
6156 {
6157 const char** target;
6158 const OrthancPluginPeers* peers;
6159 uint32_t peerIndex;
6160 const char* userProperty;
6161 } _OrthancPluginGetPeerProperty;
6162
6163 /**
6164 * @brief Get the symbolic name of an Orthanc peer.
6165 *
6166 * This function returns the symbolic name of the Orthanc peer,
6167 * which corresponds to the key of the "OrthancPeers" configuration
6168 * option of Orthanc.
6169 *
6170 * This function is thread-safe: Several threads sharing the same
6171 * OrthancPluginPeers object can simultaneously call this function.
6172 *
6173 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6174 * @param peers The data structure describing the Orthanc peers.
6175 * @param peerIndex The index of the peer of interest.
6176 * This value must be lower than OrthancPluginGetPeersCount().
6177 * @result The symbolic name, or NULL in the case of an error.
6178 * @ingroup Toolbox
6179 **/
6180 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName(
6181 OrthancPluginContext* context,
6182 const OrthancPluginPeers* peers,
6183 uint32_t peerIndex)
6184 {
6185 const char* target = NULL;
6186
6187 _OrthancPluginGetPeerProperty params;
6188 memset(&params, 0, sizeof(params));
6189 params.target = &target;
6190 params.peers = peers;
6191 params.peerIndex = peerIndex;
6192 params.userProperty = NULL;
6193
6194 if (context->InvokeService(context, _OrthancPluginService_GetPeerName, &params) != OrthancPluginErrorCode_Success)
6195 {
6196 /* Error */
6197 return NULL;
6198 }
6199 else
6200 {
6201 return target;
6202 }
6203 }
6204
6205
6206 /**
6207 * @brief Get the base URL of an Orthanc peer.
6208 *
6209 * This function returns the base URL to the REST API of some Orthanc peer.
6210 *
6211 * This function is thread-safe: Several threads sharing the same
6212 * OrthancPluginPeers object can simultaneously call this function.
6213 *
6214 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6215 * @param peers The data structure describing the Orthanc peers.
6216 * @param peerIndex The index of the peer of interest.
6217 * This value must be lower than OrthancPluginGetPeersCount().
6218 * @result The URL, or NULL in the case of an error.
6219 * @ingroup Toolbox
6220 **/
6221 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl(
6222 OrthancPluginContext* context,
6223 const OrthancPluginPeers* peers,
6224 uint32_t peerIndex)
6225 {
6226 const char* target = NULL;
6227
6228 _OrthancPluginGetPeerProperty params;
6229 memset(&params, 0, sizeof(params));
6230 params.target = &target;
6231 params.peers = peers;
6232 params.peerIndex = peerIndex;
6233 params.userProperty = NULL;
6234
6235 if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, &params) != OrthancPluginErrorCode_Success)
6236 {
6237 /* Error */
6238 return NULL;
6239 }
6240 else
6241 {
6242 return target;
6243 }
6244 }
6245
6246
6247
6248 /**
6249 * @brief Get some user-defined property of an Orthanc peer.
6250 *
6251 * This function returns some user-defined property of some Orthanc
6252 * peer. An user-defined property is a property that is associated
6253 * with the peer in the Orthanc configuration file, but that is not
6254 * recognized by the Orthanc core.
6255 *
6256 * This function is thread-safe: Several threads sharing the same
6257 * OrthancPluginPeers object can simultaneously call this function.
6258 *
6259 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6260 * @param peers The data structure describing the Orthanc peers.
6261 * @param peerIndex The index of the peer of interest.
6262 * This value must be lower than OrthancPluginGetPeersCount().
6263 * @param userProperty The user property of interest.
6264 * @result The value of the user property, or NULL if it is not defined.
6265 * @ingroup Toolbox
6266 **/
6267 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty(
6268 OrthancPluginContext* context,
6269 const OrthancPluginPeers* peers,
6270 uint32_t peerIndex,
6271 const char* userProperty)
6272 {
6273 const char* target = NULL;
6274
6275 _OrthancPluginGetPeerProperty params;
6276 memset(&params, 0, sizeof(params));
6277 params.target = &target;
6278 params.peers = peers;
6279 params.peerIndex = peerIndex;
6280 params.userProperty = userProperty;
6281
6282 if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, &params) != OrthancPluginErrorCode_Success)
6283 {
6284 /* No such user property */
6285 return NULL;
6286 }
6287 else
6288 {
6289 return target;
6290 }
6291 }
6292
6293
6294
6295 typedef struct
6296 {
6297 OrthancPluginMemoryBuffer* answerBody;
6298 OrthancPluginMemoryBuffer* answerHeaders;
6299 uint16_t* httpStatus;
6300 const OrthancPluginPeers* peers;
6301 uint32_t peerIndex;
6302 OrthancPluginHttpMethod method;
6303 const char* uri;
6304 uint32_t additionalHeadersCount;
6305 const char* const* additionalHeadersKeys;
6306 const char* const* additionalHeadersValues;
6307 const void* body;
6308 uint32_t bodySize;
6309 uint32_t timeout;
6310 } _OrthancPluginCallPeerApi;
6311
6312 /**
6313 * @brief Call the REST API of an Orthanc peer.
6314 *
6315 * Make a REST call to the given URI in the REST API of a remote
6316 * Orthanc peer. The result to the query is stored into a newly
6317 * allocated memory buffer. The HTTP request will be done according
6318 * to the "OrthancPeers" configuration option of Orthanc.
6319 *
6320 * This function is thread-safe: Several threads sharing the same
6321 * OrthancPluginPeers object can simultaneously call this function.
6322 *
6323 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6324 * @param answerBody The target memory buffer (out argument).
6325 * It must be freed with OrthancPluginFreeMemoryBuffer().
6326 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
6327 * The answer headers are formatted as a JSON object (associative array).
6328 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
6329 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
6330 * @param httpStatus The HTTP status after the execution of the request (out argument).
6331 * @param peers The data structure describing the Orthanc peers.
6332 * @param peerIndex The index of the peer of interest.
6333 * This value must be lower than OrthancPluginGetPeersCount().
6334 * @param method HTTP method to be used.
6335 * @param uri The URI of interest in the REST API.
6336 * @param additionalHeadersCount The number of HTTP headers to be added to the
6337 * HTTP headers provided in the global configuration of Orthanc.
6338 * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
6339 * @param additionalHeadersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
6340 * @param body The HTTP body for a POST or PUT request.
6341 * @param bodySize The size of the body.
6342 * @param timeout Timeout in seconds (0 for default timeout).
6343 * @return 0 if success, or the error code if failure.
6344 * @see OrthancPluginHttpClient()
6345 * @ingroup Toolbox
6346 **/
6347 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi(
6348 OrthancPluginContext* context,
6349 OrthancPluginMemoryBuffer* answerBody,
6350 OrthancPluginMemoryBuffer* answerHeaders,
6351 uint16_t* httpStatus,
6352 const OrthancPluginPeers* peers,
6353 uint32_t peerIndex,
6354 OrthancPluginHttpMethod method,
6355 const char* uri,
6356 uint32_t additionalHeadersCount,
6357 const char* const* additionalHeadersKeys,
6358 const char* const* additionalHeadersValues,
6359 const void* body,
6360 uint32_t bodySize,
6361 uint32_t timeout)
6362 {
6363 _OrthancPluginCallPeerApi params;
6364 memset(&params, 0, sizeof(params));
6365
6366 params.answerBody = answerBody;
6367 params.answerHeaders = answerHeaders;
6368 params.httpStatus = httpStatus;
6369 params.peers = peers;
6370 params.peerIndex = peerIndex;
6371 params.method = method;
6372 params.uri = uri;
6373 params.additionalHeadersCount = additionalHeadersCount;
6374 params.additionalHeadersKeys = additionalHeadersKeys;
6375 params.additionalHeadersValues = additionalHeadersValues;
6376 params.body = body;
6377 params.bodySize = bodySize;
6378 params.timeout = timeout;
6379
6380 return context->InvokeService(context, _OrthancPluginService_CallPeerApi, &params);
6381 }
6382
6383
6384
6385
6386
6387 typedef struct
6388 {
6389 OrthancPluginJob** target;
6390 void *job;
6391 OrthancPluginJobFinalize finalize;
6392 const char *type;
6393 OrthancPluginJobGetProgress getProgress;
6394 OrthancPluginJobGetContent getContent;
6395 OrthancPluginJobGetSerialized getSerialized;
6396 OrthancPluginJobStep step;
6397 OrthancPluginJobStop stop;
6398 OrthancPluginJobReset reset;
6399 } _OrthancPluginCreateJob;
6400
6401 /**
6402 * @brief Create a custom job.
6403 *
6404 * This function creates a custom job to be run by the jobs engine
6405 * of Orthanc.
6406 *
6407 * Orthanc starts one dedicated thread per custom job that is
6408 * running. It is guaranteed that all the callbacks will only be
6409 * called from this single dedicated thread, in mutual exclusion: As
6410 * a consequence, it is *not* mandatory to protect the various
6411 * callbacks by mutexes.
6412 *
6413 * The custom job can nonetheless launch its own processing threads
6414 * on the first call to the "step()" callback, and stop them once
6415 * the "stop()" callback is called.
6416 *
6417 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6418 * @param job The job to be executed.
6419 * @param finalize The finalization callback.
6420 * @param type The type of the job, provided to the job unserializer.
6421 * See OrthancPluginRegisterJobsUnserializer().
6422 * @param getProgress The progress callback.
6423 * @param getContent The content callback.
6424 * @param getSerialized The serialization callback.
6425 * @param step The callback to execute the individual steps of the job.
6426 * @param stop The callback that is invoked once the job leaves the "running" state.
6427 * @param reset The callback that is invoked if a stopped job is started again.
6428 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(),
6429 * as long as it is not submitted with OrthancPluginSubmitJob().
6430 * @ingroup Toolbox
6431 **/
6432 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob(
6433 OrthancPluginContext *context,
6434 void *job,
6435 OrthancPluginJobFinalize finalize,
6436 const char *type,
6437 OrthancPluginJobGetProgress getProgress,
6438 OrthancPluginJobGetContent getContent,
6439 OrthancPluginJobGetSerialized getSerialized,
6440 OrthancPluginJobStep step,
6441 OrthancPluginJobStop stop,
6442 OrthancPluginJobReset reset)
6443 {
6444 OrthancPluginJob* target = NULL;
6445
6446 _OrthancPluginCreateJob params;
6447 memset(&params, 0, sizeof(params));
6448
6449 params.target = &target;
6450 params.job = job;
6451 params.finalize = finalize;
6452 params.type = type;
6453 params.getProgress = getProgress;
6454 params.getContent = getContent;
6455 params.getSerialized = getSerialized;
6456 params.step = step;
6457 params.stop = stop;
6458 params.reset = reset;
6459
6460 if (context->InvokeService(context, _OrthancPluginService_CreateJob, &params) != OrthancPluginErrorCode_Success ||
6461 target == NULL)
6462 {
6463 /* Error */
6464 return NULL;
6465 }
6466 else
6467 {
6468 return target;
6469 }
6470 }
6471
6472
6473 typedef struct
6474 {
6475 OrthancPluginJob* job;
6476 } _OrthancPluginFreeJob;
6477
6478 /**
6479 * @brief Free a custom job.
6480 *
6481 * This function frees an image that was created with OrthancPluginCreateJob().
6482 *
6483 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6484 * @param job The job.
6485 * @ingroup Toolbox
6486 **/
6487 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob(
6488 OrthancPluginContext* context,
6489 OrthancPluginJob* job)
6490 {
6491 _OrthancPluginFreeJob params;
6492 params.job = job;
6493
6494 context->InvokeService(context, _OrthancPluginService_FreeJob, &params);
6495 }
6496
6497
6498
6499 typedef struct
6500 {
6501 char** resultId;
6502 OrthancPluginJob *job;
6503 int priority;
6504 } _OrthancPluginSubmitJob;
6505
6506 /**
6507 * @brief Submit a new job to the jobs engine of Orthanc.
6508 *
6509 * This function adds the given job to the pending jobs of
6510 * Orthanc. Orthanc will take take of freeing it by invoking the
6511 * finalization callback provided to OrthancPluginCreateJob().
6512 *
6513 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6514 * @param job The job, as received by OrthancPluginCreateJob().
6515 * @param priority The priority of the job.
6516 * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString().
6517 * @ingroup Toolbox
6518 **/
6519 ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob(
6520 OrthancPluginContext *context,
6521 OrthancPluginJob *job,
6522 int priority)
6523 {
6524 char* resultId = NULL;
6525
6526 _OrthancPluginSubmitJob params;
6527 memset(&params, 0, sizeof(params));
6528
6529 params.resultId = &resultId;
6530 params.job = job;
6531 params.priority = priority;
6532
6533 if (context->InvokeService(context, _OrthancPluginService_SubmitJob, &params) != OrthancPluginErrorCode_Success ||
6534 resultId == NULL)
6535 {
6536 /* Error */
6537 return NULL;
6538 }
6539 else
6540 {
6541 return resultId;
6542 }
6543 }
6544
6545
6546
6547 typedef struct
6548 {
6549 OrthancPluginJobsUnserializer unserializer;
6550 } _OrthancPluginJobsUnserializer;
6551
6552 /**
6553 * @brief Register an unserializer for custom jobs.
6554 *
6555 * This function registers an unserializer that decodes custom jobs
6556 * from a JSON string. This callback is invoked when the jobs engine
6557 * of Orthanc is started (on Orthanc initialization), for each job
6558 * that is stored in the Orthanc database.
6559 *
6560 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6561 * @param unserializer The job unserializer.
6562 * @ingroup Callbacks
6563 **/
6564 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer(
6565 OrthancPluginContext* context,
6566 OrthancPluginJobsUnserializer unserializer)
6567 {
6568 _OrthancPluginJobsUnserializer params;
6569 params.unserializer = unserializer;
6570
6571 context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, &params);
6572 }
6573
6574
6575
6576 typedef struct
6577 {
6578 OrthancPluginRestOutput* output;
6579 const char* details;
6580 uint8_t log;
6581 } _OrthancPluginSetHttpErrorDetails;
6582
6583 /**
6584 * @brief Provide a detailed description for an HTTP error.
6585 *
6586 * This function sets the detailed description associated with an
6587 * HTTP error. This description will be displayed in the "Details"
6588 * field of the JSON body of the HTTP answer. It is only taken into
6589 * consideration if the REST callback returns an error code that is
6590 * different from "OrthancPluginErrorCode_Success", and if the
6591 * "HttpDescribeErrors" configuration option of Orthanc is set to
6592 * "true".
6593 *
6594 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6595 * @param output The HTTP connection to the client application.
6596 * @param details The details of the error message.
6597 * @param log Whether to also write the detailed error to the Orthanc logs.
6598 * @ingroup REST
6599 **/
6600 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails(
6601 OrthancPluginContext* context,
6602 OrthancPluginRestOutput* output,
6603 const char* details,
6604 uint8_t log)
6605 {
6606 _OrthancPluginSetHttpErrorDetails params;
6607 params.output = output;
6608 params.details = details;
6609 params.log = log;
6610 context->InvokeService(context, _OrthancPluginService_SetHttpErrorDetails, &params);
6611 }
6612
6613
6614
6615 typedef struct
6616 {
6617 const char** result;
6618 const char* argument;
6619 } _OrthancPluginRetrieveStaticString;
6620
6621 /**
6622 * @brief Detect the MIME type of a file.
6623 *
6624 * This function returns the MIME type of a file by inspecting its extension.
6625 *
6626 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6627 * @param path Path to the file.
6628 * @return The MIME type. This is a statically-allocated
6629 * string, do not free it.
6630 * @ingroup Toolbox
6631 **/
6632 ORTHANC_PLUGIN_INLINE const char* OrthancPluginAutodetectMimeType(
6633 OrthancPluginContext* context,
6634 const char* path)
6635 {
6636 const char* result = NULL;
6637
6638 _OrthancPluginRetrieveStaticString params;
6639 params.result = &result;
6640 params.argument = path;
6641
6642 if (context->InvokeService(context, _OrthancPluginService_AutodetectMimeType, &params) != OrthancPluginErrorCode_Success)
6643 {
6644 /* Error */
6645 return NULL;
6646 }
6647 else
6648 {
6649 return result;
6650 }
6651 }
6652
6653
6654
6655 typedef struct
6656 {
6657 const char* name;
6658 float value;
6659 OrthancPluginMetricsType type;
6660 } _OrthancPluginSetMetricsValue;
6661
6662 /**
6663 * @brief Set the value of a metrics.
6664 *
6665 * This function sets the value of a metrics to monitor the behavior
6666 * of the plugin through tools such as Prometheus. The values of all
6667 * the metrics are stored within the Orthanc context.
6668 *
6669 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6670 * @param name The name of the metrics to be set.
6671 * @param value The value of the metrics.
6672 * @param type The type of the metrics. This parameter is only taken into consideration
6673 * the first time this metrics is set.
6674 * @ingroup Toolbox
6675 **/
6676 ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsValue(
6677 OrthancPluginContext* context,
6678 const char* name,
6679 float value,
6680 OrthancPluginMetricsType type)
6681 {
6682 _OrthancPluginSetMetricsValue params;
6683 params.name = name;
6684 params.value = value;
6685 params.type = type;
6686 context->InvokeService(context, _OrthancPluginService_SetMetricsValue, &params);
6687 }
6688
6689
6690
6691 typedef struct
6692 {
6693 OrthancPluginRefreshMetricsCallback callback;
6694 } _OrthancPluginRegisterRefreshMetricsCallback;
6695
6696 /**
6697 * @brief Register a callback to refresh the metrics.
6698 *
6699 * This function registers a callback to refresh the metrics. The
6700 * callback must make calls to OrthancPluginSetMetricsValue().
6701 *
6702 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6703 * @param callback The callback function to handle the refresh.
6704 * @ingroup Callbacks
6705 **/
6706 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRefreshMetricsCallback(
6707 OrthancPluginContext* context,
6708 OrthancPluginRefreshMetricsCallback callback)
6709 {
6710 _OrthancPluginRegisterRefreshMetricsCallback params;
6711 params.callback = callback;
6712 context->InvokeService(context, _OrthancPluginService_RegisterRefreshMetricsCallback, &params);
6713 }
6714
6715
6716
6717
6718 typedef struct
6719 {
6720 char** target;
6721 const void* dicom;
6722 uint32_t dicomSize;
6723 OrthancPluginDicomWebBinaryCallback callback;
6724 } _OrthancPluginEncodeDicomWeb;
6725
6726 /**
6727 * @brief Convert a DICOM instance to DICOMweb JSON.
6728 *
6729 * This function converts a memory buffer containing a DICOM instance,
6730 * into its DICOMweb JSON representation.
6731 *
6732 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6733 * @param dicom Pointer to the DICOM instance.
6734 * @param dicomSize Size of the DICOM instance.
6735 * @param callback Callback to set the value of the binary tags.
6736 * @see OrthancPluginCreateDicom()
6737 * @return The NULL value in case of error, or the JSON document. This string must
6738 * be freed by OrthancPluginFreeString().
6739 * @ingroup Toolbox
6740 **/
6741 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson(
6742 OrthancPluginContext* context,
6743 const void* dicom,
6744 uint32_t dicomSize,
6745 OrthancPluginDicomWebBinaryCallback callback)
6746 {
6747 char* target = NULL;
6748
6749 _OrthancPluginEncodeDicomWeb params;
6750 params.target = &target;
6751 params.dicom = dicom;
6752 params.dicomSize = dicomSize;
6753 params.callback = callback;
6754
6755 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson, &params) != OrthancPluginErrorCode_Success)
6756 {
6757 /* Error */
6758 return NULL;
6759 }
6760 else
6761 {
6762 return target;
6763 }
6764 }
6765
6766
6767 /**
6768 * @brief Convert a DICOM instance to DICOMweb XML.
6769 *
6770 * This function converts a memory buffer containing a DICOM instance,
6771 * into its DICOMweb XML representation.
6772 *
6773 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6774 * @param dicom Pointer to the DICOM instance.
6775 * @param dicomSize Size of the DICOM instance.
6776 * @param callback Callback to set the value of the binary tags.
6777 * @return The NULL value in case of error, or the JSON document. This string must
6778 * be freed by OrthancPluginFreeString().
6779 * @see OrthancPluginCreateDicom()
6780 * @ingroup Toolbox
6781 **/
6782 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml(
6783 OrthancPluginContext* context,
6784 const void* dicom,
6785 uint32_t dicomSize,
6786 OrthancPluginDicomWebBinaryCallback callback)
6787 {
6788 char* target = NULL;
6789
6790 _OrthancPluginEncodeDicomWeb params;
6791 params.target = &target;
6792 params.dicom = dicom;
6793 params.dicomSize = dicomSize;
6794 params.callback = callback;
6795
6796 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml, &params) != OrthancPluginErrorCode_Success)
6797 {
6798 /* Error */
6799 return NULL;
6800 }
6801 else
6802 {
6803 return target;
6804 }
6805 }
6806
6807
6808
6809 /**
6810 * @brief Callback executed when a HTTP header is received during a chunked transfer.
6811 *
6812 * Signature of a callback function that is called by Orthanc acting
6813 * as a HTTP client during a chunked HTTP transfer, as soon as it
6814 * receives one HTTP header from the answer of the remote HTTP
6815 * server.
6816 *
6817 * @see OrthancPluginChunkedHttpClient()
6818 * @param answer The user payload, as provided by the calling plugin.
6819 * @param key The key of the HTTP header.
6820 * @param value The value of the HTTP header.
6821 * @return 0 if success, or the error code if failure.
6822 * @ingroup Toolbox
6823 **/
6824 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddHeader) (
6825 void* answer,
6826 const char* key,
6827 const char* value);
6828
6829
6830 /**
6831 * @brief Callback executed when an answer chunk is received during a chunked transfer.
6832 *
6833 * Signature of a callback function that is called by Orthanc acting
6834 * as a HTTP client during a chunked HTTP transfer, as soon as it
6835 * receives one data chunk from the answer of the remote HTTP
6836 * server.
6837 *
6838 * @see OrthancPluginChunkedHttpClient()
6839 * @param answer The user payload, as provided by the calling plugin.
6840 * @param data The content of the data chunk.
6841 * @param size The size of the data chunk.
6842 * @return 0 if success, or the error code if failure.
6843 * @ingroup Toolbox
6844 **/
6845 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddChunk) (
6846 void* answer,
6847 const void* data,
6848 uint32_t size);
6849
6850
6851 /**
6852 * @brief Callback to know whether the request body is entirely read during a chunked transfer
6853 *
6854 * Signature of a callback function that is called by Orthanc acting
6855 * as a HTTP client during a chunked HTTP transfer, while reading
6856 * the body of a POST or PUT request. The plugin must answer "1" as
6857 * soon as the body is entirely read: The "request" data structure
6858 * must act as an iterator.
6859 *
6860 * @see OrthancPluginChunkedHttpClient()
6861 * @param request The user payload, as provided by the calling plugin.
6862 * @return "1" if the body is over, or "0" if there is still data to be read.
6863 * @ingroup Toolbox
6864 **/
6865 typedef uint8_t (*OrthancPluginChunkedClientRequestIsDone) (void* request);
6866
6867
6868 /**
6869 * @brief Callback to advance in the request body during a chunked transfer
6870 *
6871 * Signature of a callback function that is called by Orthanc acting
6872 * as a HTTP client during a chunked HTTP transfer, while reading
6873 * the body of a POST or PUT request. This function asks the plugin
6874 * to advance to the next chunk of data of the request body: The
6875 * "request" data structure must act as an iterator.
6876 *
6877 * @see OrthancPluginChunkedHttpClient()
6878 * @param request The user payload, as provided by the calling plugin.
6879 * @return 0 if success, or the error code if failure.
6880 * @ingroup Toolbox
6881 **/
6882 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientRequestNext) (void* request);
6883
6884
6885 /**
6886 * @brief Callback to read the current chunk of the request body during a chunked transfer
6887 *
6888 * Signature of a callback function that is called by Orthanc acting
6889 * as a HTTP client during a chunked HTTP transfer, while reading
6890 * the body of a POST or PUT request. The plugin must provide the
6891 * content of the current chunk of data of the request body.
6892 *
6893 * @see OrthancPluginChunkedHttpClient()
6894 * @param request The user payload, as provided by the calling plugin.
6895 * @return The content of the current request chunk.
6896 * @ingroup Toolbox
6897 **/
6898 typedef const void* (*OrthancPluginChunkedClientRequestGetChunkData) (void* request);
6899
6900
6901 /**
6902 * @brief Callback to read the size of the current request chunk during a chunked transfer
6903 *
6904 * Signature of a callback function that is called by Orthanc acting
6905 * as a HTTP client during a chunked HTTP transfer, while reading
6906 * the body of a POST or PUT request. The plugin must provide the
6907 * size of the current chunk of data of the request body.
6908 *
6909 * @see OrthancPluginChunkedHttpClient()
6910 * @param request The user payload, as provided by the calling plugin.
6911 * @return The size of the current request chunk.
6912 * @ingroup Toolbox
6913 **/
6914 typedef uint32_t (*OrthancPluginChunkedClientRequestGetChunkSize) (void* request);
6915
6916
6917 typedef struct
6918 {
6919 void* answer;
6920 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk;
6921 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader;
6922 uint16_t* httpStatus;
6923 OrthancPluginHttpMethod method;
6924 const char* url;
6925 uint32_t headersCount;
6926 const char* const* headersKeys;
6927 const char* const* headersValues;
6928 void* request;
6929 OrthancPluginChunkedClientRequestIsDone requestIsDone;
6930 OrthancPluginChunkedClientRequestGetChunkData requestChunkData;
6931 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize;
6932 OrthancPluginChunkedClientRequestNext requestNext;
6933 const char* username;
6934 const char* password;
6935 uint32_t timeout;
6936 const char* certificateFile;
6937 const char* certificateKeyFile;
6938 const char* certificateKeyPassword;
6939 uint8_t pkcs11;
6940 } _OrthancPluginChunkedHttpClient;
6941
6942
6943 /**
6944 * @brief Issue a HTTP call, using chunked HTTP transfers.
6945 *
6946 * Make a HTTP call to the given URL using chunked HTTP
6947 * transfers. The request body is provided as an iterator over data
6948 * chunks. The answer is provided as a sequence of function calls
6949 * with the individual HTTP headers and answer chunks.
6950 *
6951 * Contrarily to OrthancPluginHttpClient() that entirely stores the
6952 * request body and the answer body in memory buffers, this function
6953 * uses chunked HTTP transfers. This results in a lower memory
6954 * consumption. Pay attention to the fact that Orthanc servers with
6955 * version <= 1.5.6 do not support chunked transfers: You must use
6956 * OrthancPluginHttpClient() if contacting such older servers.
6957 *
6958 * The HTTP request will be done accordingly to the global
6959 * configuration of Orthanc (in particular, the options "HttpProxy",
6960 * "HttpTimeout", "HttpsVerifyPeers", "HttpsCACertificates", and
6961 * "Pkcs11" will be taken into account).
6962 *
6963 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6964 * @param answer The user payload for the answer body. It will be provided to the callbacks for the answer.
6965 * @param answerAddChunk Callback function to report a data chunk from the answer body.
6966 * @param answerAddHeader Callback function to report an HTTP header sent by the remote server.
6967 * @param httpStatus The HTTP status after the execution of the request (out argument).
6968 * @param method HTTP method to be used.
6969 * @param url The URL of interest.
6970 * @param headersCount The number of HTTP headers.
6971 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
6972 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
6973 * @param request The user payload containing the request body, and acting as an iterator.
6974 * It will be provided to the callbacks for the request.
6975 * @param requestIsDone Callback function to tell whether the request body is entirely read.
6976 * @param requestChunkData Callback function to get the content of the current data chunk of the request body.
6977 * @param requestChunkSize Callback function to get the size of the current data chunk of the request body.
6978 * @param requestNext Callback function to advance to the next data chunk of the request body.
6979 * @param username The username (can be <tt>NULL</tt> if no password protection).
6980 * @param password The password (can be <tt>NULL</tt> if no password protection).
6981 * @param timeout Timeout in seconds (0 for default timeout).
6982 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
6983 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
6984 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
6985 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
6986 * @param certificateKeyPassword Password to unlock the key of the client certificate
6987 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
6988 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
6989 * @return 0 if success, or the error code if failure.
6990 * @see OrthancPluginHttpClient()
6991 * @ingroup Toolbox
6992 **/
6993 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginChunkedHttpClient(
6994 OrthancPluginContext* context,
6995 void* answer,
6996 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk,
6997 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader,
6998 uint16_t* httpStatus,
6999 OrthancPluginHttpMethod method,
7000 const char* url,
7001 uint32_t headersCount,
7002 const char* const* headersKeys,
7003 const char* const* headersValues,
7004 void* request,
7005 OrthancPluginChunkedClientRequestIsDone requestIsDone,
7006 OrthancPluginChunkedClientRequestGetChunkData requestChunkData,
7007 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize,
7008 OrthancPluginChunkedClientRequestNext requestNext,
7009 const char* username,
7010 const char* password,
7011 uint32_t timeout,
7012 const char* certificateFile,
7013 const char* certificateKeyFile,
7014 const char* certificateKeyPassword,
7015 uint8_t pkcs11)
7016 {
7017 _OrthancPluginChunkedHttpClient params;
7018 memset(&params, 0, sizeof(params));
7019
7020 /* In common with OrthancPluginHttpClient() */
7021 params.httpStatus = httpStatus;
7022 params.method = method;
7023 params.url = url;
7024 params.headersCount = headersCount;
7025 params.headersKeys = headersKeys;
7026 params.headersValues = headersValues;
7027 params.username = username;
7028 params.password = password;
7029 params.timeout = timeout;
7030 params.certificateFile = certificateFile;
7031 params.certificateKeyFile = certificateKeyFile;
7032 params.certificateKeyPassword = certificateKeyPassword;
7033 params.pkcs11 = pkcs11;
7034
7035 /* For chunked body/answer */
7036 params.answer = answer;
7037 params.answerAddChunk = answerAddChunk;
7038 params.answerAddHeader = answerAddHeader;
7039 params.request = request;
7040 params.requestIsDone = requestIsDone;
7041 params.requestChunkData = requestChunkData;
7042 params.requestChunkSize = requestChunkSize;
7043 params.requestNext = requestNext;
7044
7045 return context->InvokeService(context, _OrthancPluginService_ChunkedHttpClient, &params);
7046 }
7047
7048
7049
7050 /**
7051 * @brief Opaque structure that reads the content of a HTTP request body during a chunked HTTP transfer.
7052 * @ingroup Callback
7053 **/
7054 typedef struct _OrthancPluginServerChunkedRequestReader_t OrthancPluginServerChunkedRequestReader;
7055
7056
7057
7058 /**
7059 * @brief Callback to create a reader to handle incoming chunked HTTP transfers.
7060 *
7061 * Signature of a callback function that is called by Orthanc acting
7062 * as a HTTP server that supports chunked HTTP transfers. This
7063 * callback is only invoked if the HTTP method is POST or PUT. The
7064 * callback must create an user-specific "reader" object that will
7065 * be fed with the body of the incoming body.
7066 *
7067 * @see OrthancPluginRegisterChunkedRestCallback()
7068 * @param reader Memory location that must be filled with the newly-created reader.
7069 * @param url The URI that is accessed.
7070 * @param request The body of the HTTP request. Note that "body" and "bodySize" are not used.
7071 * @return 0 if success, or the error code if failure.
7072 **/
7073 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderFactory) (
7074 OrthancPluginServerChunkedRequestReader** reader,
7075 const char* url,
7076 const OrthancPluginHttpRequest* request);
7077
7078
7079 /**
7080 * @brief Callback invoked whenever a new data chunk is available during a chunked transfer.
7081 *
7082 * Signature of a callback function that is called by Orthanc acting
7083 * as a HTTP server that supports chunked HTTP transfers. This callback
7084 * is invoked as soon as a new data chunk is available for the request body.
7085 *
7086 * @see OrthancPluginRegisterChunkedRestCallback()
7087 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7088 * @param data The content of the data chunk.
7089 * @param size The size of the data chunk.
7090 * @return 0 if success, or the error code if failure.
7091 **/
7092 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderAddChunk) (
7093 OrthancPluginServerChunkedRequestReader* reader,
7094 const void* data,
7095 uint32_t size);
7096
7097
7098 /**
7099 * @brief Callback invoked whenever the request body is entirely received.
7100 *
7101 * Signature of a callback function that is called by Orthanc acting
7102 * as a HTTP server that supports chunked HTTP transfers. This
7103 * callback is invoked as soon as the full body of the HTTP request
7104 * is available. The plugin can then send its answer thanks to the
7105 * provided "output" object.
7106 *
7107 * @see OrthancPluginRegisterChunkedRestCallback()
7108 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7109 * @param output The HTTP connection to the client application.
7110 * @return 0 if success, or the error code if failure.
7111 **/
7112 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderExecute) (
7113 OrthancPluginServerChunkedRequestReader* reader,
7114 OrthancPluginRestOutput* output);
7115
7116
7117 /**
7118 * @brief Callback invoked to release the resources associated with an incoming HTTP chunked transfer.
7119 *
7120 * Signature of a callback function that is called by Orthanc acting
7121 * as a HTTP server that supports chunked HTTP transfers. This
7122 * callback is invoked to release all the resources allocated by the
7123 * given reader. Note that this function might be invoked even if
7124 * the entire body was not read, to deal with client error or
7125 * disconnection.
7126 *
7127 * @see OrthancPluginRegisterChunkedRestCallback()
7128 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7129 **/
7130 typedef void (*OrthancPluginServerChunkedRequestReaderFinalize) (
7131 OrthancPluginServerChunkedRequestReader* reader);
7132
7133 typedef struct
7134 {
7135 const char* pathRegularExpression;
7136 OrthancPluginRestCallback getHandler;
7137 OrthancPluginServerChunkedRequestReaderFactory postHandler;
7138 OrthancPluginRestCallback deleteHandler;
7139 OrthancPluginServerChunkedRequestReaderFactory putHandler;
7140 OrthancPluginServerChunkedRequestReaderAddChunk addChunk;
7141 OrthancPluginServerChunkedRequestReaderExecute execute;
7142 OrthancPluginServerChunkedRequestReaderFinalize finalize;
7143 } _OrthancPluginChunkedRestCallback;
7144
7145
7146 /**
7147 * @brief Register a REST callback to handle chunked HTTP transfers.
7148 *
7149 * This function registers a REST callback against a regular
7150 * expression for a URI. This function must be called during the
7151 * initialization of the plugin, i.e. inside the
7152 * OrthancPluginInitialize() public function.
7153 *
7154 * Contrarily to OrthancPluginRegisterRestCallback(), the callbacks
7155 * will NOT be invoked in mutual exclusion, so it is up to the
7156 * plugin to implement the required locking mechanisms.
7157 *
7158 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7159 * @param pathRegularExpression Regular expression for the URI. May contain groups.
7160 * @param getHandler The callback function to handle REST calls using the GET HTTP method.
7161 * @param postHandler The callback function to handle REST calls using the GET POST method.
7162 * @param deleteHandler The callback function to handle REST calls using the GET DELETE method.
7163 * @param putHandler The callback function to handle REST calls using the GET PUT method.
7164 * @param addChunk The callback invoked when a new chunk is available for the request body of a POST or PUT call.
7165 * @param execute The callback invoked once the entire body of a POST or PUT call is read.
7166 * @param finalize The callback invoked to release the resources associated with a POST or PUT call.
7167 * @see OrthancPluginRegisterRestCallbackNoLock()
7168 *
7169 * @note
7170 * The regular expression is case sensitive and must follow the
7171 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
7172 *
7173 * @ingroup Callbacks
7174 **/
7175 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterChunkedRestCallback(
7176 OrthancPluginContext* context,
7177 const char* pathRegularExpression,
7178 OrthancPluginRestCallback getHandler,
7179 OrthancPluginServerChunkedRequestReaderFactory postHandler,
7180 OrthancPluginRestCallback deleteHandler,
7181 OrthancPluginServerChunkedRequestReaderFactory putHandler,
7182 OrthancPluginServerChunkedRequestReaderAddChunk addChunk,
7183 OrthancPluginServerChunkedRequestReaderExecute execute,
7184 OrthancPluginServerChunkedRequestReaderFinalize finalize)
7185 {
7186 _OrthancPluginChunkedRestCallback params;
7187 params.pathRegularExpression = pathRegularExpression;
7188 params.getHandler = getHandler;
7189 params.postHandler = postHandler;
7190 params.deleteHandler = deleteHandler;
7191 params.putHandler = putHandler;
7192 params.addChunk = addChunk;
7193 params.execute = execute;
7194 params.finalize = finalize;
7195
7196 context->InvokeService(context, _OrthancPluginService_RegisterChunkedRestCallback, &params);
7197 }
7198
7199
7200
7201
7202
7203 typedef struct
7204 {
7205 char** result;
7206 uint16_t group;
7207 uint16_t element;
7208 const char* privateCreator;
7209 } _OrthancPluginGetTagName;
7210
7211 /**
7212 * @brief Returns the symbolic name of a DICOM tag.
7213 *
7214 * This function makes a lookup to the dictionary of DICOM tags that
7215 * are known to Orthanc, and returns the symbolic name of a DICOM tag.
7216 *
7217 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7218 * @param group The group of the tag.
7219 * @param element The element of the tag.
7220 * @param privateCreator For private tags, the name of the private creator (can be NULL).
7221 * @return NULL in the case of an error, or a newly allocated string
7222 * containing the path. This string must be freed by
7223 * OrthancPluginFreeString().
7224 * @ingroup Toolbox
7225 **/
7226 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetTagName(
7227 OrthancPluginContext* context,
7228 uint16_t group,
7229 uint16_t element,
7230 const char* privateCreator)
7231 {
7232 char* result;
7233
7234 _OrthancPluginGetTagName params;
7235 params.result = &result;
7236 params.group = group;
7237 params.element = element;
7238 params.privateCreator = privateCreator;
7239
7240 if (context->InvokeService(context, _OrthancPluginService_GetTagName, &params) != OrthancPluginErrorCode_Success)
7241 {
7242 /* Error */
7243 return NULL;
7244 }
7245 else
7246 {
7247 return result;
7248 }
7249 }
7250
7251
7252
7253 #ifdef __cplusplus
7254 }
7255 #endif
7256
7257
7258 /** @} */
7259
0 /**
1 * \mainpage
2 *
3 * This C/C++ SDK allows external developers to create plugins that
4 * can be loaded into Orthanc to extend its functionality. Each
5 * Orthanc plugin must expose 4 public functions with the following
6 * signatures:
7 *
8 * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>:
9 * This function is invoked by Orthanc when it loads the plugin on startup.
10 * The plugin must:
11 * - Check its compatibility with the Orthanc version using
12 * ::OrthancPluginCheckVersion().
13 * - Store the context pointer so that it can use the plugin
14 * services of Orthanc.
15 * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback().
16 * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback().
17 * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback().
18 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea().
19 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2().
20 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback().
21 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback().
22 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback().
23 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback().
24 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2().
25 * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer().
26 * - Possibly register a callback to refresh its metrics using OrthancPluginRegisterRefreshMetricsCallback().
27 * - Possibly register a callback to answer chunked HTTP transfers using ::OrthancPluginRegisterChunkedRestCallback().
28 * - Possibly register a callback for Storage Commitment SCP using ::OrthancPluginRegisterStorageCommitmentScpCallback().
29 * - Possibly register a callback to filter incoming DICOM instance using OrthancPluginRegisterIncomingDicomInstanceFilter().
30 * - Possibly register a custom transcoder for DICOM images using OrthancPluginRegisterTranscoderCallback().
31 * -# <tt>void OrthancPluginFinalize()</tt>:
32 * This function is invoked by Orthanc during its shutdown. The plugin
33 * must free all its memory.
34 * -# <tt>const char* OrthancPluginGetName()</tt>:
35 * The plugin must return a short string to identify itself.
36 * -# <tt>const char* OrthancPluginGetVersion()</tt>:
37 * The plugin must return a string containing its version number.
38 *
39 * The name and the version of a plugin is only used to prevent it
40 * from being loaded twice. Note that, in C++, it is mandatory to
41 * declare these functions within an <tt>extern "C"</tt> section.
42 *
43 * To ensure multi-threading safety, the various REST callbacks are
44 * guaranteed to be executed in mutual exclusion since Orthanc
45 * 0.8.5. If this feature is undesired (notably when developing
46 * high-performance plugins handling simultaneous requests), use
47 * ::OrthancPluginRegisterRestCallbackNoLock().
48 **/
49
50
51
52 /**
53 * @defgroup Images Images and compression
54 * @brief Functions to deal with images and compressed buffers.
55 *
56 * @defgroup REST REST
57 * @brief Functions to answer REST requests in a callback.
58 *
59 * @defgroup Callbacks Callbacks
60 * @brief Functions to register and manage callbacks by the plugins.
61 *
62 * @defgroup DicomCallbacks DicomCallbacks
63 * @brief Functions to register and manage DICOM callbacks (worklists, C-FIND, C-MOVE, storage commitment).
64 *
65 * @defgroup Orthanc Orthanc
66 * @brief Functions to access the content of the Orthanc server.
67 *
68 * @defgroup DicomInstance DicomInstance
69 * @brief Functions to access DICOM images that are managed by the Orthanc core.
70 **/
71
72
73
74 /**
75 * @defgroup Toolbox Toolbox
76 * @brief Generic functions to help with the creation of plugins.
77 **/
78
79
80
81 /**
82 * Orthanc - A Lightweight, RESTful DICOM Store
83 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
84 * Department, University Hospital of Liege, Belgium
85 * Copyright (C) 2017-2020 Osimis S.A., Belgium
86 *
87 * This program is free software: you can redistribute it and/or
88 * modify it under the terms of the GNU General Public License as
89 * published by the Free Software Foundation, either version 3 of the
90 * License, or (at your option) any later version.
91 *
92 * In addition, as a special exception, the copyright holders of this
93 * program give permission to link the code of its release with the
94 * OpenSSL project's "OpenSSL" library (or with modified versions of it
95 * that use the same license as the "OpenSSL" library), and distribute
96 * the linked executables. You must obey the GNU General Public License
97 * in all respects for all of the code used other than "OpenSSL". If you
98 * modify file(s) with this exception, you may extend this exception to
99 * your version of the file(s), but you are not obligated to do so. If
100 * you do not wish to do so, delete this exception statement from your
101 * version. If you delete this exception statement from all source files
102 * in the program, then also delete it here.
103 *
104 * This program is distributed in the hope that it will be useful, but
105 * WITHOUT ANY WARRANTY; without even the implied warranty of
106 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
107 * General Public License for more details.
108 *
109 * You should have received a copy of the GNU General Public License
110 * along with this program. If not, see <http://www.gnu.org/licenses/>.
111 **/
112
113
114
115 #pragma once
116
117
118 #include <stdio.h>
119 #include <string.h>
120
121 #ifdef WIN32
122 # define ORTHANC_PLUGINS_API __declspec(dllexport)
123 #elif __GNUC__ >= 4
124 # define ORTHANC_PLUGINS_API __attribute__ ((visibility ("default")))
125 #else
126 # define ORTHANC_PLUGINS_API
127 #endif
128
129 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1
130 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 7
131 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 0
132
133
134 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
135 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \
136 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \
137 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \
138 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \
139 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \
140 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision))))
141 #endif
142
143
144
145 /********************************************************************
146 ** Check that function inlining is properly supported. The use of
147 ** inlining is required, to avoid the duplication of object code
148 ** between two compilation modules that would use the Orthanc Plugin
149 ** API.
150 ********************************************************************/
151
152 /* If the auto-detection of the "inline" keyword below does not work
153 automatically and that your compiler is known to properly support
154 inlining, uncomment the following #define and adapt the definition
155 of "static inline". */
156
157 /* #define ORTHANC_PLUGIN_INLINE static inline */
158
159 #ifndef ORTHANC_PLUGIN_INLINE
160 # if __STDC_VERSION__ >= 199901L
161 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
162 # define ORTHANC_PLUGIN_INLINE static inline
163 # elif defined(__cplusplus)
164 /* This is C++ */
165 # define ORTHANC_PLUGIN_INLINE static inline
166 # elif defined(__GNUC__)
167 /* This is GCC running in C89 mode */
168 # define ORTHANC_PLUGIN_INLINE static __inline
169 # elif defined(_MSC_VER)
170 /* This is Visual Studio running in C89 mode */
171 # define ORTHANC_PLUGIN_INLINE static __inline
172 # else
173 # error Your compiler is not known to support the "inline" keyword
174 # endif
175 #endif
176
177
178
179 /********************************************************************
180 ** Inclusion of standard libraries.
181 ********************************************************************/
182
183 /**
184 * For Microsoft Visual Studio, a compatibility "stdint.h" can be
185 * downloaded at the following URL:
186 * https://hg.orthanc-server.com/orthanc/raw-file/tip/Resources/ThirdParty/VisualStudio/stdint.h
187 **/
188 #include <stdint.h>
189
190 #include <stdlib.h>
191
192
193
194 /********************************************************************
195 ** Definition of the Orthanc Plugin API.
196 ********************************************************************/
197
198 /** @{ */
199
200 #ifdef __cplusplus
201 extern "C"
202 {
203 #endif
204
205 /**
206 * The various error codes that can be returned by the Orthanc core.
207 **/
208 typedef enum
209 {
210 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */,
211 OrthancPluginErrorCode_Success = 0 /*!< Success */,
212 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */,
213 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */,
214 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */,
215 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */,
216 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */,
217 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */,
218 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */,
219 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */,
220 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */,
221 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */,
222 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */,
223 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */,
224 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */,
225 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */,
226 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */,
227 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */,
228 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */,
229 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */,
230 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */,
231 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */,
232 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */,
233 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */,
234 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */,
235 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */,
236 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */,
237 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */,
238 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */,
239 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */,
240 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */,
241 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */,
242 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */,
243 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */,
244 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */,
245 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */,
246 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */,
247 OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */,
248 OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */,
249 OrthancPluginErrorCode_BadGeometry = 38 /*!< Geometry error encountered in Stone */,
250 OrthancPluginErrorCode_SslInitialization = 39 /*!< Cannot initialize SSL encryption, check out your certificates */,
251 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */,
252 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */,
253 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */,
254 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */,
255 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */,
256 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */,
257 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */,
258 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */,
259 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */,
260 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */,
261 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */,
262 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */,
263 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */,
264 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */,
265 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */,
266 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */,
267 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */,
268 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */,
269 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */,
270 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */,
271 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */,
272 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */,
273 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */,
274 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */,
275 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */,
276 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */,
277 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */,
278 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */,
279 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */,
280 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */,
281 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */,
282 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */,
283 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */,
284 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */,
285 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */,
286 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */,
287 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */,
288 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */,
289 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */,
290 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */,
291 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */,
292 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */,
293 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */,
294 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */,
295 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */,
296 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */,
297 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */,
298 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */,
299 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */,
300 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */,
301 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */,
302 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */,
303 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */,
304 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */,
305 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */,
306 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */,
307 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */,
308 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */,
309 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */,
310 OrthancPluginErrorCode_NoStorageCommitmentHandler = 2043 /*!< No request handler factory for DICOM N-ACTION SCP (storage commitment) */,
311 OrthancPluginErrorCode_NoCGetHandler = 2044 /*!< No request handler factory for DICOM C-GET SCP */,
312 OrthancPluginErrorCode_UnsupportedMediaType = 3000 /*!< Unsupported media type */,
313
314 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff
315 } OrthancPluginErrorCode;
316
317
318 /**
319 * Forward declaration of one of the mandatory functions for Orthanc
320 * plugins.
321 **/
322 ORTHANC_PLUGINS_API const char* OrthancPluginGetName();
323
324
325 /**
326 * The various HTTP methods for a REST call.
327 **/
328 typedef enum
329 {
330 OrthancPluginHttpMethod_Get = 1, /*!< GET request */
331 OrthancPluginHttpMethod_Post = 2, /*!< POST request */
332 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
333 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */
334
335 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff
336 } OrthancPluginHttpMethod;
337
338
339 /**
340 * @brief The parameters of a REST request.
341 * @ingroup Callbacks
342 **/
343 typedef struct
344 {
345 /**
346 * @brief The HTTP method.
347 **/
348 OrthancPluginHttpMethod method;
349
350 /**
351 * @brief The number of groups of the regular expression.
352 **/
353 uint32_t groupsCount;
354
355 /**
356 * @brief The matched values for the groups of the regular expression.
357 **/
358 const char* const* groups;
359
360 /**
361 * @brief For a GET request, the number of GET parameters.
362 **/
363 uint32_t getCount;
364
365 /**
366 * @brief For a GET request, the keys of the GET parameters.
367 **/
368 const char* const* getKeys;
369
370 /**
371 * @brief For a GET request, the values of the GET parameters.
372 **/
373 const char* const* getValues;
374
375 /**
376 * @brief For a PUT or POST request, the content of the body.
377 **/
378 const void* body;
379
380 /**
381 * @brief For a PUT or POST request, the number of bytes of the body.
382 **/
383 uint32_t bodySize;
384
385
386 /* --------------------------------------------------
387 New in version 0.8.1
388 -------------------------------------------------- */
389
390 /**
391 * @brief The number of HTTP headers.
392 **/
393 uint32_t headersCount;
394
395 /**
396 * @brief The keys of the HTTP headers (always converted to low-case).
397 **/
398 const char* const* headersKeys;
399
400 /**
401 * @brief The values of the HTTP headers.
402 **/
403 const char* const* headersValues;
404
405 } OrthancPluginHttpRequest;
406
407
408 typedef enum
409 {
410 /* Generic services */
411 _OrthancPluginService_LogInfo = 1,
412 _OrthancPluginService_LogWarning = 2,
413 _OrthancPluginService_LogError = 3,
414 _OrthancPluginService_GetOrthancPath = 4,
415 _OrthancPluginService_GetOrthancDirectory = 5,
416 _OrthancPluginService_GetConfigurationPath = 6,
417 _OrthancPluginService_SetPluginProperty = 7,
418 _OrthancPluginService_GetGlobalProperty = 8,
419 _OrthancPluginService_SetGlobalProperty = 9,
420 _OrthancPluginService_GetCommandLineArgumentsCount = 10,
421 _OrthancPluginService_GetCommandLineArgument = 11,
422 _OrthancPluginService_GetExpectedDatabaseVersion = 12,
423 _OrthancPluginService_GetConfiguration = 13,
424 _OrthancPluginService_BufferCompression = 14,
425 _OrthancPluginService_ReadFile = 15,
426 _OrthancPluginService_WriteFile = 16,
427 _OrthancPluginService_GetErrorDescription = 17,
428 _OrthancPluginService_CallHttpClient = 18,
429 _OrthancPluginService_RegisterErrorCode = 19,
430 _OrthancPluginService_RegisterDictionaryTag = 20,
431 _OrthancPluginService_DicomBufferToJson = 21,
432 _OrthancPluginService_DicomInstanceToJson = 22,
433 _OrthancPluginService_CreateDicom = 23,
434 _OrthancPluginService_ComputeMd5 = 24,
435 _OrthancPluginService_ComputeSha1 = 25,
436 _OrthancPluginService_LookupDictionary = 26,
437 _OrthancPluginService_CallHttpClient2 = 27,
438 _OrthancPluginService_GenerateUuid = 28,
439 _OrthancPluginService_RegisterPrivateDictionaryTag = 29,
440 _OrthancPluginService_AutodetectMimeType = 30,
441 _OrthancPluginService_SetMetricsValue = 31,
442 _OrthancPluginService_EncodeDicomWebJson = 32,
443 _OrthancPluginService_EncodeDicomWebXml = 33,
444 _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */
445 _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */
446 _OrthancPluginService_EncodeDicomWebJson2 = 36, /* New in Orthanc 1.7.0 */
447 _OrthancPluginService_EncodeDicomWebXml2 = 37, /* New in Orthanc 1.7.0 */
448 _OrthancPluginService_CreateMemoryBuffer = 38, /* New in Orthanc 1.7.0 */
449
450 /* Registration of callbacks */
451 _OrthancPluginService_RegisterRestCallback = 1000,
452 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
453 _OrthancPluginService_RegisterStorageArea = 1002,
454 _OrthancPluginService_RegisterOnChangeCallback = 1003,
455 _OrthancPluginService_RegisterRestCallbackNoLock = 1004,
456 _OrthancPluginService_RegisterWorklistCallback = 1005,
457 _OrthancPluginService_RegisterDecodeImageCallback = 1006,
458 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007,
459 _OrthancPluginService_RegisterFindCallback = 1008,
460 _OrthancPluginService_RegisterMoveCallback = 1009,
461 _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010,
462 _OrthancPluginService_RegisterRefreshMetricsCallback = 1011,
463 _OrthancPluginService_RegisterChunkedRestCallback = 1012, /* New in Orthanc 1.5.7 */
464 _OrthancPluginService_RegisterStorageCommitmentScpCallback = 1013,
465 _OrthancPluginService_RegisterIncomingDicomInstanceFilter = 1014,
466 _OrthancPluginService_RegisterTranscoderCallback = 1015, /* New in Orthanc 1.7.0 */
467
468 /* Sending answers to REST calls */
469 _OrthancPluginService_AnswerBuffer = 2000,
470 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */
471 _OrthancPluginService_Redirect = 2002,
472 _OrthancPluginService_SendHttpStatusCode = 2003,
473 _OrthancPluginService_SendUnauthorized = 2004,
474 _OrthancPluginService_SendMethodNotAllowed = 2005,
475 _OrthancPluginService_SetCookie = 2006,
476 _OrthancPluginService_SetHttpHeader = 2007,
477 _OrthancPluginService_StartMultipartAnswer = 2008,
478 _OrthancPluginService_SendMultipartItem = 2009,
479 _OrthancPluginService_SendHttpStatus = 2010,
480 _OrthancPluginService_CompressAndAnswerImage = 2011,
481 _OrthancPluginService_SendMultipartItem2 = 2012,
482 _OrthancPluginService_SetHttpErrorDetails = 2013,
483
484 /* Access to the Orthanc database and API */
485 _OrthancPluginService_GetDicomForInstance = 3000,
486 _OrthancPluginService_RestApiGet = 3001,
487 _OrthancPluginService_RestApiPost = 3002,
488 _OrthancPluginService_RestApiDelete = 3003,
489 _OrthancPluginService_RestApiPut = 3004,
490 _OrthancPluginService_LookupPatient = 3005,
491 _OrthancPluginService_LookupStudy = 3006,
492 _OrthancPluginService_LookupSeries = 3007,
493 _OrthancPluginService_LookupInstance = 3008,
494 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
495 _OrthancPluginService_RestApiGetAfterPlugins = 3010,
496 _OrthancPluginService_RestApiPostAfterPlugins = 3011,
497 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012,
498 _OrthancPluginService_RestApiPutAfterPlugins = 3013,
499 _OrthancPluginService_ReconstructMainDicomTags = 3014,
500 _OrthancPluginService_RestApiGet2 = 3015,
501
502 /* Access to DICOM instances */
503 _OrthancPluginService_GetInstanceRemoteAet = 4000,
504 _OrthancPluginService_GetInstanceSize = 4001,
505 _OrthancPluginService_GetInstanceData = 4002,
506 _OrthancPluginService_GetInstanceJson = 4003,
507 _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
508 _OrthancPluginService_HasInstanceMetadata = 4005,
509 _OrthancPluginService_GetInstanceMetadata = 4006,
510 _OrthancPluginService_GetInstanceOrigin = 4007,
511 _OrthancPluginService_GetInstanceTransferSyntaxUid = 4008,
512 _OrthancPluginService_HasInstancePixelData = 4009,
513 _OrthancPluginService_CreateDicomInstance = 4010, /* New in Orthanc 1.7.0 */
514 _OrthancPluginService_FreeDicomInstance = 4011, /* New in Orthanc 1.7.0 */
515 _OrthancPluginService_GetInstanceFramesCount = 4012, /* New in Orthanc 1.7.0 */
516 _OrthancPluginService_GetInstanceRawFrame = 4013, /* New in Orthanc 1.7.0 */
517 _OrthancPluginService_GetInstanceDecodedFrame = 4014, /* New in Orthanc 1.7.0 */
518 _OrthancPluginService_TranscodeDicomInstance = 4015, /* New in Orthanc 1.7.0 */
519 _OrthancPluginService_SerializeDicomInstance = 4016, /* New in Orthanc 1.7.0 */
520 _OrthancPluginService_GetInstanceAdvancedJson = 4017, /* New in Orthanc 1.7.0 */
521 _OrthancPluginService_GetInstanceDicomWebJson = 4018, /* New in Orthanc 1.7.0 */
522 _OrthancPluginService_GetInstanceDicomWebXml = 4019, /* New in Orthanc 1.7.0 */
523
524 /* Services for plugins implementing a database back-end */
525 _OrthancPluginService_RegisterDatabaseBackend = 5000,
526 _OrthancPluginService_DatabaseAnswer = 5001,
527 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002,
528 _OrthancPluginService_StorageAreaCreate = 5003,
529 _OrthancPluginService_StorageAreaRead = 5004,
530 _OrthancPluginService_StorageAreaRemove = 5005,
531
532 /* Primitives for handling images */
533 _OrthancPluginService_GetImagePixelFormat = 6000,
534 _OrthancPluginService_GetImageWidth = 6001,
535 _OrthancPluginService_GetImageHeight = 6002,
536 _OrthancPluginService_GetImagePitch = 6003,
537 _OrthancPluginService_GetImageBuffer = 6004,
538 _OrthancPluginService_UncompressImage = 6005,
539 _OrthancPluginService_FreeImage = 6006,
540 _OrthancPluginService_CompressImage = 6007,
541 _OrthancPluginService_ConvertPixelFormat = 6008,
542 _OrthancPluginService_GetFontsCount = 6009,
543 _OrthancPluginService_GetFontInfo = 6010,
544 _OrthancPluginService_DrawText = 6011,
545 _OrthancPluginService_CreateImage = 6012,
546 _OrthancPluginService_CreateImageAccessor = 6013,
547 _OrthancPluginService_DecodeDicomImage = 6014,
548
549 /* Primitives for handling C-Find, C-Move and worklists */
550 _OrthancPluginService_WorklistAddAnswer = 7000,
551 _OrthancPluginService_WorklistMarkIncomplete = 7001,
552 _OrthancPluginService_WorklistIsMatch = 7002,
553 _OrthancPluginService_WorklistGetDicomQuery = 7003,
554 _OrthancPluginService_FindAddAnswer = 7004,
555 _OrthancPluginService_FindMarkIncomplete = 7005,
556 _OrthancPluginService_GetFindQuerySize = 7006,
557 _OrthancPluginService_GetFindQueryTag = 7007,
558 _OrthancPluginService_GetFindQueryTagName = 7008,
559 _OrthancPluginService_GetFindQueryValue = 7009,
560 _OrthancPluginService_CreateFindMatcher = 7010,
561 _OrthancPluginService_FreeFindMatcher = 7011,
562 _OrthancPluginService_FindMatcherIsMatch = 7012,
563
564 /* Primitives for accessing Orthanc Peers (new in 1.4.2) */
565 _OrthancPluginService_GetPeers = 8000,
566 _OrthancPluginService_FreePeers = 8001,
567 _OrthancPluginService_GetPeersCount = 8003,
568 _OrthancPluginService_GetPeerName = 8004,
569 _OrthancPluginService_GetPeerUrl = 8005,
570 _OrthancPluginService_CallPeerApi = 8006,
571 _OrthancPluginService_GetPeerUserProperty = 8007,
572
573 /* Primitives for handling jobs (new in 1.4.2) */
574 _OrthancPluginService_CreateJob = 9000,
575 _OrthancPluginService_FreeJob = 9001,
576 _OrthancPluginService_SubmitJob = 9002,
577 _OrthancPluginService_RegisterJobsUnserializer = 9003,
578
579 _OrthancPluginService_INTERNAL = 0x7fffffff
580 } _OrthancPluginService;
581
582
583 typedef enum
584 {
585 _OrthancPluginProperty_Description = 1,
586 _OrthancPluginProperty_RootUri = 2,
587 _OrthancPluginProperty_OrthancExplorer = 3,
588
589 _OrthancPluginProperty_INTERNAL = 0x7fffffff
590 } _OrthancPluginProperty;
591
592
593
594 /**
595 * The memory layout of the pixels of an image.
596 * @ingroup Images
597 **/
598 typedef enum
599 {
600 /**
601 * @brief Graylevel 8bpp image.
602 *
603 * The image is graylevel. Each pixel is unsigned and stored in
604 * one byte.
605 **/
606 OrthancPluginPixelFormat_Grayscale8 = 1,
607
608 /**
609 * @brief Graylevel, unsigned 16bpp image.
610 *
611 * The image is graylevel. Each pixel is unsigned and stored in
612 * two bytes.
613 **/
614 OrthancPluginPixelFormat_Grayscale16 = 2,
615
616 /**
617 * @brief Graylevel, signed 16bpp image.
618 *
619 * The image is graylevel. Each pixel is signed and stored in two
620 * bytes.
621 **/
622 OrthancPluginPixelFormat_SignedGrayscale16 = 3,
623
624 /**
625 * @brief Color image in RGB24 format.
626 *
627 * This format describes a color image. The pixels are stored in 3
628 * consecutive bytes. The memory layout is RGB.
629 **/
630 OrthancPluginPixelFormat_RGB24 = 4,
631
632 /**
633 * @brief Color image in RGBA32 format.
634 *
635 * This format describes a color image. The pixels are stored in 4
636 * consecutive bytes. The memory layout is RGBA.
637 **/
638 OrthancPluginPixelFormat_RGBA32 = 5,
639
640 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */
641
642 /**
643 * @brief Color image in RGB48 format.
644 *
645 * This format describes a color image. The pixels are stored in 6
646 * consecutive bytes. The memory layout is RRGGBB.
647 **/
648 OrthancPluginPixelFormat_RGB48 = 7,
649
650 /**
651 * @brief Graylevel, unsigned 32bpp image.
652 *
653 * The image is graylevel. Each pixel is unsigned and stored in
654 * four bytes.
655 **/
656 OrthancPluginPixelFormat_Grayscale32 = 8,
657
658 /**
659 * @brief Graylevel, floating-point 32bpp image.
660 *
661 * The image is graylevel. Each pixel is floating-point and stored
662 * in four bytes.
663 **/
664 OrthancPluginPixelFormat_Float32 = 9,
665
666 /**
667 * @brief Color image in BGRA32 format.
668 *
669 * This format describes a color image. The pixels are stored in 4
670 * consecutive bytes. The memory layout is BGRA.
671 **/
672 OrthancPluginPixelFormat_BGRA32 = 10,
673
674 /**
675 * @brief Graylevel, unsigned 64bpp image.
676 *
677 * The image is graylevel. Each pixel is unsigned and stored in
678 * eight bytes.
679 **/
680 OrthancPluginPixelFormat_Grayscale64 = 11,
681
682 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff
683 } OrthancPluginPixelFormat;
684
685
686
687 /**
688 * The content types that are supported by Orthanc plugins.
689 **/
690 typedef enum
691 {
692 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
693 OrthancPluginContentType_Dicom = 1, /*!< DICOM */
694 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */
695
696 _OrthancPluginContentType_INTERNAL = 0x7fffffff
697 } OrthancPluginContentType;
698
699
700
701 /**
702 * The supported types of DICOM resources.
703 **/
704 typedef enum
705 {
706 OrthancPluginResourceType_Patient = 0, /*!< Patient */
707 OrthancPluginResourceType_Study = 1, /*!< Study */
708 OrthancPluginResourceType_Series = 2, /*!< Series */
709 OrthancPluginResourceType_Instance = 3, /*!< Instance */
710 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */
711
712 _OrthancPluginResourceType_INTERNAL = 0x7fffffff
713 } OrthancPluginResourceType;
714
715
716
717 /**
718 * The supported types of changes that can happen to DICOM resources.
719 * @ingroup Callbacks
720 **/
721 typedef enum
722 {
723 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */
724 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */
725 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */
726 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */
727 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */
728 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */
729 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */
730 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */
731 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */
732 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */
733 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */
734 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */
735 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */
736 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */
737 OrthancPluginChangeType_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */
738 OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */
739
740 _OrthancPluginChangeType_INTERNAL = 0x7fffffff
741 } OrthancPluginChangeType;
742
743
744 /**
745 * The compression algorithms that are supported by the Orthanc core.
746 * @ingroup Images
747 **/
748 typedef enum
749 {
750 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */
751 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */
752 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */
753 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */
754
755 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff
756 } OrthancPluginCompressionType;
757
758
759 /**
760 * The image formats that are supported by the Orthanc core.
761 * @ingroup Images
762 **/
763 typedef enum
764 {
765 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */
766 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */
767 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */
768
769 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff
770 } OrthancPluginImageFormat;
771
772
773 /**
774 * The value representations present in the DICOM standard (version 2013).
775 * @ingroup Toolbox
776 **/
777 typedef enum
778 {
779 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */
780 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */
781 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */
782 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */
783 OrthancPluginValueRepresentation_DA = 5, /*!< Date */
784 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */
785 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */
786 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */
787 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */
788 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */
789 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */
790 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */
791 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */
792 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */
793 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */
794 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */
795 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */
796 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */
797 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */
798 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */
799 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */
800 OrthancPluginValueRepresentation_TM = 22, /*!< Time */
801 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */
802 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */
803 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */
804 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */
805 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */
806
807 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff
808 } OrthancPluginValueRepresentation;
809
810
811 /**
812 * The possible output formats for a DICOM-to-JSON conversion.
813 * @ingroup Toolbox
814 * @see OrthancPluginDicomToJson()
815 **/
816 typedef enum
817 {
818 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */
819 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */
820 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */
821
822 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff
823 } OrthancPluginDicomToJsonFormat;
824
825
826 /**
827 * Flags to customize a DICOM-to-JSON conversion. By default, binary
828 * tags are formatted using Data URI scheme.
829 * @ingroup Toolbox
830 **/
831 typedef enum
832 {
833 OrthancPluginDicomToJsonFlags_None = 0,
834 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */
835 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */
836 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */
837 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */
838 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */
839 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */
840
841 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff
842 } OrthancPluginDicomToJsonFlags;
843
844
845 /**
846 * Flags to the creation of a DICOM file.
847 * @ingroup Toolbox
848 * @see OrthancPluginCreateDicom()
849 **/
850 typedef enum
851 {
852 OrthancPluginCreateDicomFlags_None = 0,
853 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */
854 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */
855
856 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff
857 } OrthancPluginCreateDicomFlags;
858
859
860 /**
861 * The constraints on the DICOM identifiers that must be supported
862 * by the database plugins.
863 * @deprecated Plugins using OrthancPluginConstraintType will be faster
864 **/
865 typedef enum
866 {
867 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */
868 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */
869 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */
870 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */
871
872 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff
873 } OrthancPluginIdentifierConstraint;
874
875
876 /**
877 * The constraints on the tags (main DICOM tags and identifier tags)
878 * that must be supported by the database plugins.
879 **/
880 typedef enum
881 {
882 OrthancPluginConstraintType_Equal = 1, /*!< Equal */
883 OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */
884 OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */
885 OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */
886 OrthancPluginConstraintType_List = 5, /*!< List of values */
887
888 _OrthancPluginConstraintType_INTERNAL = 0x7fffffff
889 } OrthancPluginConstraintType;
890
891
892 /**
893 * The origin of a DICOM instance that has been received by Orthanc.
894 **/
895 typedef enum
896 {
897 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */
898 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */
899 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */
900 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */
901 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */
902
903 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff
904 } OrthancPluginInstanceOrigin;
905
906
907 /**
908 * The possible status for one single step of a job.
909 **/
910 typedef enum
911 {
912 OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */
913 OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */
914 OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */
915 } OrthancPluginJobStepStatus;
916
917
918 /**
919 * Explains why the job should stop and release the resources it has
920 * allocated. This is especially important to disambiguate between
921 * the "paused" condition and the "final" conditions (success,
922 * failure, or canceled).
923 **/
924 typedef enum
925 {
926 OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */
927 OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */
928 OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */
929 OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */
930 } OrthancPluginJobStopReason;
931
932
933 /**
934 * The available types of metrics.
935 **/
936 typedef enum
937 {
938 OrthancPluginMetricsType_Default = 0, /*!< Default metrics */
939
940 /**
941 * This metrics represents a time duration. Orthanc will keep the
942 * maximum value of the metrics over a sliding window of ten
943 * seconds, which is useful if the metrics is sampled frequently.
944 **/
945 OrthancPluginMetricsType_Timer = 1
946 } OrthancPluginMetricsType;
947
948
949 /**
950 * The available modes to export a binary DICOM tag into a DICOMweb
951 * JSON or XML document.
952 **/
953 typedef enum
954 {
955 OrthancPluginDicomWebBinaryMode_Ignore = 0, /*!< Don't include binary tags */
956 OrthancPluginDicomWebBinaryMode_InlineBinary = 1, /*!< Inline encoding using Base64 */
957 OrthancPluginDicomWebBinaryMode_BulkDataUri = 2 /*!< Use a bulk data URI field */
958 } OrthancPluginDicomWebBinaryMode;
959
960
961 /**
962 * The available values for the Failure Reason (0008,1197) during
963 * storage commitment.
964 * http://dicom.nema.org/medical/dicom/2019e/output/chtml/part03/sect_C.14.html#sect_C.14.1.1
965 **/
966 typedef enum
967 {
968 OrthancPluginStorageCommitmentFailureReason_Success = 0,
969 /*!< Success: The DICOM instance is properly stored in the SCP */
970
971 OrthancPluginStorageCommitmentFailureReason_ProcessingFailure = 1,
972 /*!< 0110H: A general failure in processing the operation was encountered */
973
974 OrthancPluginStorageCommitmentFailureReason_NoSuchObjectInstance = 2,
975 /*!< 0112H: One or more of the elements in the Referenced SOP
976 Instance Sequence was not available */
977
978 OrthancPluginStorageCommitmentFailureReason_ResourceLimitation = 3,
979 /*!< 0213H: The SCP does not currently have enough resources to
980 store the requested SOP Instance(s) */
981
982 OrthancPluginStorageCommitmentFailureReason_ReferencedSOPClassNotSupported = 4,
983 /*!< 0122H: Storage Commitment has been requested for a SOP
984 Instance with a SOP Class that is not supported by the SCP */
985
986 OrthancPluginStorageCommitmentFailureReason_ClassInstanceConflict = 5,
987 /*!< 0119H: The SOP Class of an element in the Referenced SOP
988 Instance Sequence did not correspond to the SOP class registered
989 for this SOP Instance at the SCP */
990
991 OrthancPluginStorageCommitmentFailureReason_DuplicateTransactionUID = 6
992 /*!< 0131H: The Transaction UID of the Storage Commitment Request
993 is already in use */
994 } OrthancPluginStorageCommitmentFailureReason;
995
996
997
998 /**
999 * @brief A memory buffer allocated by the core system of Orthanc.
1000 *
1001 * A memory buffer allocated by the core system of Orthanc. When the
1002 * content of the buffer is not useful anymore, it must be free by a
1003 * call to ::OrthancPluginFreeMemoryBuffer().
1004 **/
1005 typedef struct
1006 {
1007 /**
1008 * @brief The content of the buffer.
1009 **/
1010 void* data;
1011
1012 /**
1013 * @brief The number of bytes in the buffer.
1014 **/
1015 uint32_t size;
1016 } OrthancPluginMemoryBuffer;
1017
1018
1019
1020
1021 /**
1022 * @brief Opaque structure that represents the HTTP connection to the client application.
1023 * @ingroup Callback
1024 **/
1025 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
1026
1027
1028
1029 /**
1030 * @brief Opaque structure that represents a DICOM instance that is managed by the Orthanc core.
1031 * @ingroup DicomInstance
1032 **/
1033 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
1034
1035
1036
1037 /**
1038 * @brief Opaque structure that represents an image that is uncompressed in memory.
1039 * @ingroup Images
1040 **/
1041 typedef struct _OrthancPluginImage_t OrthancPluginImage;
1042
1043
1044
1045 /**
1046 * @brief Opaque structure that represents the storage area that is actually used by Orthanc.
1047 * @ingroup Images
1048 **/
1049 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea;
1050
1051
1052
1053 /**
1054 * @brief Opaque structure to an object that represents a C-Find query for worklists.
1055 * @ingroup DicomCallbacks
1056 **/
1057 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery;
1058
1059
1060
1061 /**
1062 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
1063 * @ingroup DicomCallbacks
1064 **/
1065 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers;
1066
1067
1068
1069 /**
1070 * @brief Opaque structure to an object that represents a C-Find query.
1071 * @ingroup DicomCallbacks
1072 **/
1073 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery;
1074
1075
1076
1077 /**
1078 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
1079 * @ingroup DicomCallbacks
1080 **/
1081 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers;
1082
1083
1084
1085 /**
1086 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query.
1087 * @ingroup Toolbox
1088 **/
1089 typedef struct _OrthancPluginFindMatcher_t OrthancPluginFindMatcher;
1090
1091
1092
1093 /**
1094 * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server.
1095 * @ingroup Toolbox
1096 **/
1097 typedef struct _OrthancPluginPeers_t OrthancPluginPeers;
1098
1099
1100
1101 /**
1102 * @brief Opaque structure to a job to be executed by Orthanc.
1103 * @ingroup Toolbox
1104 **/
1105 typedef struct _OrthancPluginJob_t OrthancPluginJob;
1106
1107
1108
1109 /**
1110 * @brief Opaque structure that represents a node in a JSON or XML
1111 * document used in DICOMweb.
1112 * @ingroup Toolbox
1113 **/
1114 typedef struct _OrthancPluginDicomWebNode_t OrthancPluginDicomWebNode;
1115
1116
1117
1118 /**
1119 * @brief Signature of a callback function that answers to a REST request.
1120 * @ingroup Callbacks
1121 **/
1122 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) (
1123 OrthancPluginRestOutput* output,
1124 const char* url,
1125 const OrthancPluginHttpRequest* request);
1126
1127
1128
1129 /**
1130 * @brief Signature of a callback function that is triggered when Orthanc stores a new DICOM instance.
1131 * @ingroup Callbacks
1132 **/
1133 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) (
1134 const OrthancPluginDicomInstance* instance,
1135 const char* instanceId);
1136
1137
1138
1139 /**
1140 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
1141 * @ingroup Callbacks
1142 **/
1143 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) (
1144 OrthancPluginChangeType changeType,
1145 OrthancPluginResourceType resourceType,
1146 const char* resourceId);
1147
1148
1149
1150 /**
1151 * @brief Signature of a callback function to decode a DICOM instance as an image.
1152 * @ingroup Callbacks
1153 **/
1154 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) (
1155 OrthancPluginImage** target,
1156 const void* dicom,
1157 const uint32_t size,
1158 uint32_t frameIndex);
1159
1160
1161
1162 /**
1163 * @brief Signature of a function to free dynamic memory.
1164 * @ingroup Callbacks
1165 **/
1166 typedef void (*OrthancPluginFree) (void* buffer);
1167
1168
1169
1170 /**
1171 * @brief Signature of a function to set the content of a node
1172 * encoding a binary DICOM tag, into a JSON or XML document
1173 * generated for DICOMweb.
1174 * @ingroup Callbacks
1175 **/
1176 typedef void (*OrthancPluginDicomWebSetBinaryNode) (
1177 OrthancPluginDicomWebNode* node,
1178 OrthancPluginDicomWebBinaryMode mode,
1179 const char* bulkDataUri);
1180
1181
1182
1183 /**
1184 * @brief Callback for writing to the storage area.
1185 *
1186 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
1187 *
1188 * @param uuid The UUID of the file.
1189 * @param content The content of the file.
1190 * @param size The size of the file.
1191 * @param type The content type corresponding to this file.
1192 * @return 0 if success, other value if error.
1193 * @ingroup Callbacks
1194 **/
1195 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) (
1196 const char* uuid,
1197 const void* content,
1198 int64_t size,
1199 OrthancPluginContentType type);
1200
1201
1202
1203 /**
1204 * @brief Callback for reading from the storage area.
1205 *
1206 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
1207 *
1208 * @param content The content of the file (output).
1209 * @param size The size of the file (output).
1210 * @param uuid The UUID of the file of interest.
1211 * @param type The content type corresponding to this file.
1212 * @return 0 if success, other value if error.
1213 * @ingroup Callbacks
1214 *
1215 * @warning The "content" buffer *must* have been allocated using
1216 * the "malloc()" function of your C standard library (i.e. nor
1217 * "new[]", neither a pointer to a buffer). The "free()" function of
1218 * your C standard library will automatically be invoked on the
1219 * "content" pointer.
1220 **/
1221 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) (
1222 void** content,
1223 int64_t* size,
1224 const char* uuid,
1225 OrthancPluginContentType type);
1226
1227
1228
1229 /**
1230 * @brief Callback for removing a file from the storage area.
1231 *
1232 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
1233 *
1234 * @param uuid The UUID of the file to be removed.
1235 * @param type The content type corresponding to this file.
1236 * @return 0 if success, other value if error.
1237 * @ingroup Callbacks
1238 **/
1239 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) (
1240 const char* uuid,
1241 OrthancPluginContentType type);
1242
1243
1244
1245 /**
1246 * @brief Callback to handle the C-Find SCP requests for worklists.
1247 *
1248 * Signature of a callback function that is triggered when Orthanc
1249 * receives a C-Find SCP request against modality worklists.
1250 *
1251 * @param answers The target structure where answers must be stored.
1252 * @param query The worklist query.
1253 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1254 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1255 * @return 0 if success, other value if error.
1256 * @ingroup DicomCallbacks
1257 **/
1258 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) (
1259 OrthancPluginWorklistAnswers* answers,
1260 const OrthancPluginWorklistQuery* query,
1261 const char* issuerAet,
1262 const char* calledAet);
1263
1264
1265
1266 /**
1267 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1268 *
1269 * Signature of a callback function that is triggered whenever
1270 * Orthanc receives an HTTP/REST request, and that answers whether
1271 * this request should be allowed. If the callback returns "0"
1272 * ("false"), the server answers with HTTP status code 403
1273 * (Forbidden).
1274 *
1275 * @param method The HTTP method used by the request.
1276 * @param uri The URI of interest.
1277 * @param ip The IP address of the HTTP client.
1278 * @param headersCount The number of HTTP headers.
1279 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1280 * @param headersValues The values of the HTTP headers.
1281 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1282 * @ingroup Callback
1283 * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2()
1284 **/
1285 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) (
1286 OrthancPluginHttpMethod method,
1287 const char* uri,
1288 const char* ip,
1289 uint32_t headersCount,
1290 const char* const* headersKeys,
1291 const char* const* headersValues);
1292
1293
1294
1295 /**
1296 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1297 *
1298 * Signature of a callback function that is triggered whenever
1299 * Orthanc receives an HTTP/REST request, and that answers whether
1300 * this request should be allowed. If the callback returns "0"
1301 * ("false"), the server answers with HTTP status code 403
1302 * (Forbidden).
1303 *
1304 * @param method The HTTP method used by the request.
1305 * @param uri The URI of interest.
1306 * @param ip The IP address of the HTTP client.
1307 * @param headersCount The number of HTTP headers.
1308 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1309 * @param headersValues The values of the HTTP headers.
1310 * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method).
1311 * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method).
1312 * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method).
1313 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1314 * @ingroup Callback
1315 **/
1316 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) (
1317 OrthancPluginHttpMethod method,
1318 const char* uri,
1319 const char* ip,
1320 uint32_t headersCount,
1321 const char* const* headersKeys,
1322 const char* const* headersValues,
1323 uint32_t getArgumentsCount,
1324 const char* const* getArgumentsKeys,
1325 const char* const* getArgumentsValues);
1326
1327
1328
1329 /**
1330 * @brief Callback to handle incoming C-Find SCP requests.
1331 *
1332 * Signature of a callback function that is triggered whenever
1333 * Orthanc receives a C-Find SCP request not concerning modality
1334 * worklists.
1335 *
1336 * @param answers The target structure where answers must be stored.
1337 * @param query The worklist query.
1338 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1339 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1340 * @return 0 if success, other value if error.
1341 * @ingroup DicomCallbacks
1342 **/
1343 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) (
1344 OrthancPluginFindAnswers* answers,
1345 const OrthancPluginFindQuery* query,
1346 const char* issuerAet,
1347 const char* calledAet);
1348
1349
1350
1351 /**
1352 * @brief Callback to handle incoming C-Move SCP requests.
1353 *
1354 * Signature of a callback function that is triggered whenever
1355 * Orthanc receives a C-Move SCP request. The callback receives the
1356 * type of the resource of interest (study, series, instance...)
1357 * together with the DICOM tags containing its identifiers. In turn,
1358 * the plugin must create a driver object that will be responsible
1359 * for driving the successive move suboperations.
1360 *
1361 * @param resourceType The type of the resource of interest. Note
1362 * that this might be set to ResourceType_None if the
1363 * QueryRetrieveLevel (0008,0052) tag was not provided by the
1364 * issuer (i.e. the originator modality).
1365 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL.
1366 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL.
1367 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL.
1368 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL.
1369 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL.
1370 * @param originatorAet The Application Entity Title (AET) of the
1371 * modality from which the request originates.
1372 * @param sourceAet The Application Entity Title (AET) of the
1373 * modality that should send its DICOM files to another modality.
1374 * @param targetAet The Application Entity Title (AET) of the
1375 * modality that should receive the DICOM files.
1376 * @param originatorId The Message ID issued by the originator modality,
1377 * as found in tag (0000,0110) of the DICOM query emitted by the issuer.
1378 *
1379 * @return The NULL value if the plugin cannot deal with this query,
1380 * or a pointer to the driver object that is responsible for
1381 * handling the successive move suboperations.
1382 *
1383 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation.
1384 * @ingroup DicomCallbacks
1385 **/
1386 typedef void* (*OrthancPluginMoveCallback) (
1387 OrthancPluginResourceType resourceType,
1388 const char* patientId,
1389 const char* accessionNumber,
1390 const char* studyInstanceUid,
1391 const char* seriesInstanceUid,
1392 const char* sopInstanceUid,
1393 const char* originatorAet,
1394 const char* sourceAet,
1395 const char* targetAet,
1396 uint16_t originatorId);
1397
1398
1399 /**
1400 * @brief Callback to read the size of a C-Move driver.
1401 *
1402 * Signature of a callback function that returns the number of
1403 * C-Move suboperations that are to be achieved by the given C-Move
1404 * driver. This driver is the return value of a previous call to the
1405 * OrthancPluginMoveCallback() callback.
1406 *
1407 * @param moveDriver The C-Move driver of interest.
1408 * @return The number of suboperations.
1409 * @ingroup DicomCallbacks
1410 **/
1411 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver);
1412
1413
1414 /**
1415 * @brief Callback to apply one C-Move suboperation.
1416 *
1417 * Signature of a callback function that applies the next C-Move
1418 * suboperation that os to be achieved by the given C-Move
1419 * driver. This driver is the return value of a previous call to the
1420 * OrthancPluginMoveCallback() callback.
1421 *
1422 * @param moveDriver The C-Move driver of interest.
1423 * @return 0 if success, or the error code if failure.
1424 * @ingroup DicomCallbacks
1425 **/
1426 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver);
1427
1428
1429 /**
1430 * @brief Callback to free one C-Move driver.
1431 *
1432 * Signature of a callback function that releases the resources
1433 * allocated by the given C-Move driver. This driver is the return
1434 * value of a previous call to the OrthancPluginMoveCallback()
1435 * callback.
1436 *
1437 * @param moveDriver The C-Move driver of interest.
1438 * @ingroup DicomCallbacks
1439 **/
1440 typedef void (*OrthancPluginFreeMove) (void* moveDriver);
1441
1442
1443 /**
1444 * @brief Callback to finalize one custom job.
1445 *
1446 * Signature of a callback function that releases all the resources
1447 * allocated by the given job. This job is the argument provided to
1448 * OrthancPluginCreateJob().
1449 *
1450 * @param job The job of interest.
1451 * @ingroup Toolbox
1452 **/
1453 typedef void (*OrthancPluginJobFinalize) (void* job);
1454
1455
1456 /**
1457 * @brief Callback to check the progress of one custom job.
1458 *
1459 * Signature of a callback function that returns the progress of the
1460 * job.
1461 *
1462 * @param job The job of interest.
1463 * @return The progress, as a floating-point number ranging from 0 to 1.
1464 * @ingroup Toolbox
1465 **/
1466 typedef float (*OrthancPluginJobGetProgress) (void* job);
1467
1468
1469 /**
1470 * @brief Callback to retrieve the content of one custom job.
1471 *
1472 * Signature of a callback function that returns human-readable
1473 * statistics about the job. This statistics must be formatted as a
1474 * JSON object. This information is notably displayed in the "Jobs"
1475 * tab of "Orthanc Explorer".
1476 *
1477 * @param job The job of interest.
1478 * @return The statistics, as a JSON object encoded as a string.
1479 * @ingroup Toolbox
1480 **/
1481 typedef const char* (*OrthancPluginJobGetContent) (void* job);
1482
1483
1484 /**
1485 * @brief Callback to serialize one custom job.
1486 *
1487 * Signature of a callback function that returns a serialized
1488 * version of the job, formatted as a JSON object. This
1489 * serialization is stored in the Orthanc database, and is used to
1490 * reload the job on the restart of Orthanc. The "unserialization"
1491 * callback (with OrthancPluginJobsUnserializer signature) will
1492 * receive this serialized object.
1493 *
1494 * @param job The job of interest.
1495 * @return The serialized job, as a JSON object encoded as a string.
1496 * @see OrthancPluginRegisterJobsUnserializer()
1497 * @ingroup Toolbox
1498 **/
1499 typedef const char* (*OrthancPluginJobGetSerialized) (void* job);
1500
1501
1502 /**
1503 * @brief Callback to execute one step of a custom job.
1504 *
1505 * Signature of a callback function that executes one step in the
1506 * job. The jobs engine of Orthanc will make successive calls to
1507 * this method, as long as it returns
1508 * OrthancPluginJobStepStatus_Continue.
1509 *
1510 * @param job The job of interest.
1511 * @return The status of execution.
1512 * @ingroup Toolbox
1513 **/
1514 typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job);
1515
1516
1517 /**
1518 * @brief Callback executed once one custom job leaves the "running" state.
1519 *
1520 * Signature of a callback function that is invoked once a job
1521 * leaves the "running" state. This can happen if the previous call
1522 * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc
1523 * server is being stopped, or if the user manually tags the job as
1524 * paused/canceled. This callback allows the plugin to free
1525 * resources allocated for running this custom job (e.g. to stop
1526 * threads, or to remove temporary files).
1527 *
1528 * Note that handling pauses might involves a specific treatment
1529 * (such a stopping threads, but keeping temporary files on the
1530 * disk). This "paused" situation can be checked by looking at the
1531 * "reason" parameter.
1532 *
1533 * @param job The job of interest.
1534 * @param reason The reason for leaving the "running" state.
1535 * @return 0 if success, or the error code if failure.
1536 * @ingroup Toolbox
1537 **/
1538 typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job,
1539 OrthancPluginJobStopReason reason);
1540
1541
1542 /**
1543 * @brief Callback executed once one stopped custom job is started again.
1544 *
1545 * Signature of a callback function that is invoked once a job
1546 * leaves the "failure/canceled" state, to be started again. This
1547 * function will typically reset the progress to zero. Note that
1548 * before being actually executed, the job would first be tagged as
1549 * "pending" in the Orthanc jobs engine.
1550 *
1551 * @param job The job of interest.
1552 * @return 0 if success, or the error code if failure.
1553 * @ingroup Toolbox
1554 **/
1555 typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job);
1556
1557
1558 /**
1559 * @brief Callback executed to unserialize a custom job.
1560 *
1561 * Signature of a callback function that unserializes a job that was
1562 * saved in the Orthanc database.
1563 *
1564 * @param jobType The type of the job, as provided to OrthancPluginCreateJob().
1565 * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized.
1566 * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL
1567 * if this unserializer cannot handle this job type.
1568 * @see OrthancPluginRegisterJobsUnserializer()
1569 * @ingroup Callbacks
1570 **/
1571 typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType,
1572 const char* serialized);
1573
1574
1575
1576 /**
1577 * @brief Callback executed to update the metrics of the plugin.
1578 *
1579 * Signature of a callback function that is called by Orthanc
1580 * whenever a monitoring tool (such as Prometheus) asks the current
1581 * values of the metrics. This callback gives the plugin a chance to
1582 * update its metrics, by calling OrthancPluginSetMetricsValue().
1583 * This is typically useful for metrics that are expensive to
1584 * acquire.
1585 *
1586 * @see OrthancPluginRegisterRefreshMetrics()
1587 * @ingroup Callbacks
1588 **/
1589 typedef void (*OrthancPluginRefreshMetricsCallback) ();
1590
1591
1592
1593 /**
1594 * @brief Callback executed to encode a binary tag in DICOMweb.
1595 *
1596 * Signature of a callback function that is called by Orthanc
1597 * whenever a DICOM tag that contains a binary value must be written
1598 * to a JSON or XML node, while a DICOMweb document is being
1599 * generated. The value representation (VR) of the DICOM tag can be
1600 * OB, OD, OF, OL, OW, or UN.
1601 *
1602 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
1603 * @param node The node being generated, as provided by Orthanc.
1604 * @param setter The setter to be used to encode the content of the node. If
1605 * the setter is not called, the binary tag is not written to the output document.
1606 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences.
1607 * This parameter gives the number of elements in the "levelTagGroup",
1608 * "levelTagElement", and "levelIndex" arrays.
1609 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy.
1610 * @param levelTagElement The element of the parent DICOM tags in the hierarchy.
1611 * @param levelIndex The index of the node in the parent sequences of the hierarchy.
1612 * @param tagGroup The group of the DICOM tag of interest.
1613 * @param tagElement The element of the DICOM tag of interest.
1614 * @param vr The value representation of the binary DICOM node.
1615 * @ingroup Callbacks
1616 **/
1617 typedef void (*OrthancPluginDicomWebBinaryCallback) (
1618 OrthancPluginDicomWebNode* node,
1619 OrthancPluginDicomWebSetBinaryNode setter,
1620 uint32_t levelDepth,
1621 const uint16_t* levelTagGroup,
1622 const uint16_t* levelTagElement,
1623 const uint32_t* levelIndex,
1624 uint16_t tagGroup,
1625 uint16_t tagElement,
1626 OrthancPluginValueRepresentation vr);
1627
1628
1629
1630 /**
1631 * @brief Callback executed to encode a binary tag in DICOMweb.
1632 *
1633 * Signature of a callback function that is called by Orthanc
1634 * whenever a DICOM tag that contains a binary value must be written
1635 * to a JSON or XML node, while a DICOMweb document is being
1636 * generated. The value representation (VR) of the DICOM tag can be
1637 * OB, OD, OF, OL, OW, or UN.
1638 *
1639 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
1640 * @param node The node being generated, as provided by Orthanc.
1641 * @param setter The setter to be used to encode the content of the node. If
1642 * the setter is not called, the binary tag is not written to the output document.
1643 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences.
1644 * This parameter gives the number of elements in the "levelTagGroup",
1645 * "levelTagElement", and "levelIndex" arrays.
1646 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy.
1647 * @param levelTagElement The element of the parent DICOM tags in the hierarchy.
1648 * @param levelIndex The index of the node in the parent sequences of the hierarchy.
1649 * @param tagGroup The group of the DICOM tag of interest.
1650 * @param tagElement The element of the DICOM tag of interest.
1651 * @param vr The value representation of the binary DICOM node.
1652 * @param payload The user payload.
1653 * @ingroup Callbacks
1654 **/
1655 typedef void (*OrthancPluginDicomWebBinaryCallback2) (
1656 OrthancPluginDicomWebNode* node,
1657 OrthancPluginDicomWebSetBinaryNode setter,
1658 uint32_t levelDepth,
1659 const uint16_t* levelTagGroup,
1660 const uint16_t* levelTagElement,
1661 const uint32_t* levelIndex,
1662 uint16_t tagGroup,
1663 uint16_t tagElement,
1664 OrthancPluginValueRepresentation vr,
1665 void* payload);
1666
1667
1668
1669 /**
1670 * @brief Data structure that contains information about the Orthanc core.
1671 **/
1672 typedef struct _OrthancPluginContext_t
1673 {
1674 void* pluginsManager;
1675 const char* orthancVersion;
1676 OrthancPluginFree Free;
1677 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context,
1678 _OrthancPluginService service,
1679 const void* params);
1680 } OrthancPluginContext;
1681
1682
1683
1684 /**
1685 * @brief An entry in the dictionary of DICOM tags.
1686 **/
1687 typedef struct
1688 {
1689 uint16_t group; /*!< The group of the tag */
1690 uint16_t element; /*!< The element of the tag */
1691 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */
1692 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */
1693 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */
1694 } OrthancPluginDictionaryEntry;
1695
1696
1697
1698 /**
1699 * @brief Free a string.
1700 *
1701 * Free a string that was allocated by the core system of Orthanc.
1702 *
1703 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1704 * @param str The string to be freed.
1705 **/
1706 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
1707 OrthancPluginContext* context,
1708 char* str)
1709 {
1710 if (str != NULL)
1711 {
1712 context->Free(str);
1713 }
1714 }
1715
1716
1717 /**
1718 * @brief Check that the version of the hosting Orthanc is above a given version.
1719 *
1720 * This function checks whether the version of the Orthanc server
1721 * running this plugin, is above the given version. Contrarily to
1722 * OrthancPluginCheckVersion(), it is up to the developer of the
1723 * plugin to make sure that all the Orthanc SDK services called by
1724 * the plugin are actually implemented in the given version of
1725 * Orthanc.
1726 *
1727 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1728 * @param expectedMajor Expected major version.
1729 * @param expectedMinor Expected minor version.
1730 * @param expectedRevision Expected revision.
1731 * @return 1 if and only if the versions are compatible. If the
1732 * result is 0, the initialization of the plugin should fail.
1733 * @see OrthancPluginCheckVersion
1734 * @ingroup Callbacks
1735 **/
1736 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersionAdvanced(
1737 OrthancPluginContext* context,
1738 int expectedMajor,
1739 int expectedMinor,
1740 int expectedRevision)
1741 {
1742 int major, minor, revision;
1743
1744 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
1745 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
1746 sizeof(int32_t) != sizeof(_OrthancPluginService) ||
1747 sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
1748 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
1749 sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
1750 sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
1751 sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
1752 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
1753 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) ||
1754 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
1755 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
1756 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
1757 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) ||
1758 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
1759 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
1760 sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) ||
1761 sizeof(int32_t) != sizeof(OrthancPluginConstraintType) ||
1762 sizeof(int32_t) != sizeof(OrthancPluginMetricsType) ||
1763 sizeof(int32_t) != sizeof(OrthancPluginDicomWebBinaryMode) ||
1764 sizeof(int32_t) != sizeof(OrthancPluginStorageCommitmentFailureReason))
1765 {
1766 /* Mismatch in the size of the enumerations */
1767 return 0;
1768 }
1769
1770 /* Assume compatibility with the mainline */
1771 if (!strcmp(context->orthancVersion, "mainline"))
1772 {
1773 return 1;
1774 }
1775
1776 /* Parse the version of the Orthanc core */
1777 if (
1778 #ifdef _MSC_VER
1779 sscanf_s
1780 #else
1781 sscanf
1782 #endif
1783 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3)
1784 {
1785 return 0;
1786 }
1787
1788 /* Check the major number of the version */
1789
1790 if (major > expectedMajor)
1791 {
1792 return 1;
1793 }
1794
1795 if (major < expectedMajor)
1796 {
1797 return 0;
1798 }
1799
1800 /* Check the minor number of the version */
1801
1802 if (minor > expectedMinor)
1803 {
1804 return 1;
1805 }
1806
1807 if (minor < expectedMinor)
1808 {
1809 return 0;
1810 }
1811
1812 /* Check the revision number of the version */
1813
1814 if (revision >= expectedRevision)
1815 {
1816 return 1;
1817 }
1818 else
1819 {
1820 return 0;
1821 }
1822 }
1823
1824
1825 /**
1826 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
1827 *
1828 * This function checks whether the version of the Orthanc server
1829 * running this plugin, is above the version of the current Orthanc
1830 * SDK header. This guarantees that the plugin is compatible with
1831 * the hosting Orthanc (i.e. it will not call unavailable services).
1832 * The result of this function should always be checked in the
1833 * OrthancPluginInitialize() entry point of the plugin.
1834 *
1835 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1836 * @return 1 if and only if the versions are compatible. If the
1837 * result is 0, the initialization of the plugin should fail.
1838 * @see OrthancPluginCheckVersionAdvanced
1839 * @ingroup Callbacks
1840 **/
1841 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion(
1842 OrthancPluginContext* context)
1843 {
1844 return OrthancPluginCheckVersionAdvanced(
1845 context,
1846 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
1847 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
1848 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1849 }
1850
1851
1852 /**
1853 * @brief Free a memory buffer.
1854 *
1855 * Free a memory buffer that was allocated by the core system of Orthanc.
1856 *
1857 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1858 * @param buffer The memory buffer to release.
1859 **/
1860 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
1861 OrthancPluginContext* context,
1862 OrthancPluginMemoryBuffer* buffer)
1863 {
1864 context->Free(buffer->data);
1865 }
1866
1867
1868 /**
1869 * @brief Log an error.
1870 *
1871 * Log an error message using the Orthanc logging system.
1872 *
1873 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1874 * @param message The message to be logged.
1875 **/
1876 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
1877 OrthancPluginContext* context,
1878 const char* message)
1879 {
1880 context->InvokeService(context, _OrthancPluginService_LogError, message);
1881 }
1882
1883
1884 /**
1885 * @brief Log a warning.
1886 *
1887 * Log a warning message using the Orthanc logging system.
1888 *
1889 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1890 * @param message The message to be logged.
1891 **/
1892 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
1893 OrthancPluginContext* context,
1894 const char* message)
1895 {
1896 context->InvokeService(context, _OrthancPluginService_LogWarning, message);
1897 }
1898
1899
1900 /**
1901 * @brief Log an information.
1902 *
1903 * Log an information message using the Orthanc logging system.
1904 *
1905 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1906 * @param message The message to be logged.
1907 **/
1908 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
1909 OrthancPluginContext* context,
1910 const char* message)
1911 {
1912 context->InvokeService(context, _OrthancPluginService_LogInfo, message);
1913 }
1914
1915
1916
1917 typedef struct
1918 {
1919 const char* pathRegularExpression;
1920 OrthancPluginRestCallback callback;
1921 } _OrthancPluginRestCallback;
1922
1923 /**
1924 * @brief Register a REST callback.
1925 *
1926 * This function registers a REST callback against a regular
1927 * expression for a URI. This function must be called during the
1928 * initialization of the plugin, i.e. inside the
1929 * OrthancPluginInitialize() public function.
1930 *
1931 * Each REST callback is guaranteed to run in mutual exclusion.
1932 *
1933 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1934 * @param pathRegularExpression Regular expression for the URI. May contain groups.
1935 * @param callback The callback function to handle the REST call.
1936 * @see OrthancPluginRegisterRestCallbackNoLock()
1937 *
1938 * @note
1939 * The regular expression is case sensitive and must follow the
1940 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
1941 *
1942 * @ingroup Callbacks
1943 **/
1944 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
1945 OrthancPluginContext* context,
1946 const char* pathRegularExpression,
1947 OrthancPluginRestCallback callback)
1948 {
1949 _OrthancPluginRestCallback params;
1950 params.pathRegularExpression = pathRegularExpression;
1951 params.callback = callback;
1952 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, &params);
1953 }
1954
1955
1956
1957 /**
1958 * @brief Register a REST callback, without locking.
1959 *
1960 * This function registers a REST callback against a regular
1961 * expression for a URI. This function must be called during the
1962 * initialization of the plugin, i.e. inside the
1963 * OrthancPluginInitialize() public function.
1964 *
1965 * Contrarily to OrthancPluginRegisterRestCallback(), the callback
1966 * will NOT be invoked in mutual exclusion. This can be useful for
1967 * high-performance plugins that must handle concurrent requests
1968 * (Orthanc uses a pool of threads, one thread being assigned to
1969 * each incoming HTTP request). Of course, if using this function,
1970 * it is up to the plugin to implement the required locking
1971 * mechanisms.
1972 *
1973 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1974 * @param pathRegularExpression Regular expression for the URI. May contain groups.
1975 * @param callback The callback function to handle the REST call.
1976 * @see OrthancPluginRegisterRestCallback()
1977 *
1978 * @note
1979 * The regular expression is case sensitive and must follow the
1980 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
1981 *
1982 * @ingroup Callbacks
1983 **/
1984 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock(
1985 OrthancPluginContext* context,
1986 const char* pathRegularExpression,
1987 OrthancPluginRestCallback callback)
1988 {
1989 _OrthancPluginRestCallback params;
1990 params.pathRegularExpression = pathRegularExpression;
1991 params.callback = callback;
1992 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, &params);
1993 }
1994
1995
1996
1997 typedef struct
1998 {
1999 OrthancPluginOnStoredInstanceCallback callback;
2000 } _OrthancPluginOnStoredInstanceCallback;
2001
2002 /**
2003 * @brief Register a callback for received instances.
2004 *
2005 * This function registers a callback function that is called
2006 * whenever a new DICOM instance is stored into the Orthanc core.
2007 *
2008 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2009 * @param callback The callback function.
2010 * @ingroup Callbacks
2011 **/
2012 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
2013 OrthancPluginContext* context,
2014 OrthancPluginOnStoredInstanceCallback callback)
2015 {
2016 _OrthancPluginOnStoredInstanceCallback params;
2017 params.callback = callback;
2018
2019 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, &params);
2020 }
2021
2022
2023
2024 typedef struct
2025 {
2026 OrthancPluginRestOutput* output;
2027 const void* answer;
2028 uint32_t answerSize;
2029 const char* mimeType;
2030 } _OrthancPluginAnswerBuffer;
2031
2032 /**
2033 * @brief Answer to a REST request.
2034 *
2035 * This function answers to a REST request with the content of a memory buffer.
2036 *
2037 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2038 * @param output The HTTP connection to the client application.
2039 * @param answer Pointer to the memory buffer containing the answer.
2040 * @param answerSize Number of bytes of the answer.
2041 * @param mimeType The MIME type of the answer.
2042 * @ingroup REST
2043 **/
2044 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
2045 OrthancPluginContext* context,
2046 OrthancPluginRestOutput* output,
2047 const void* answer,
2048 uint32_t answerSize,
2049 const char* mimeType)
2050 {
2051 _OrthancPluginAnswerBuffer params;
2052 params.output = output;
2053 params.answer = answer;
2054 params.answerSize = answerSize;
2055 params.mimeType = mimeType;
2056 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, &params);
2057 }
2058
2059
2060 typedef struct
2061 {
2062 OrthancPluginRestOutput* output;
2063 OrthancPluginPixelFormat format;
2064 uint32_t width;
2065 uint32_t height;
2066 uint32_t pitch;
2067 const void* buffer;
2068 } _OrthancPluginCompressAndAnswerPngImage;
2069
2070 typedef struct
2071 {
2072 OrthancPluginRestOutput* output;
2073 OrthancPluginImageFormat imageFormat;
2074 OrthancPluginPixelFormat pixelFormat;
2075 uint32_t width;
2076 uint32_t height;
2077 uint32_t pitch;
2078 const void* buffer;
2079 uint8_t quality;
2080 } _OrthancPluginCompressAndAnswerImage;
2081
2082
2083 /**
2084 * @brief Answer to a REST request with a PNG image.
2085 *
2086 * This function answers to a REST request with a PNG image. The
2087 * parameters of this function describe a memory buffer that
2088 * contains an uncompressed image. The image will be automatically compressed
2089 * as a PNG image by the core system of Orthanc.
2090 *
2091 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2092 * @param output The HTTP connection to the client application.
2093 * @param format The memory layout of the uncompressed image.
2094 * @param width The width of the image.
2095 * @param height The height of the image.
2096 * @param pitch The pitch of the image (i.e. the number of bytes
2097 * between 2 successive lines of the image in the memory buffer).
2098 * @param buffer The memory buffer containing the uncompressed image.
2099 * @ingroup REST
2100 **/
2101 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
2102 OrthancPluginContext* context,
2103 OrthancPluginRestOutput* output,
2104 OrthancPluginPixelFormat format,
2105 uint32_t width,
2106 uint32_t height,
2107 uint32_t pitch,
2108 const void* buffer)
2109 {
2110 _OrthancPluginCompressAndAnswerImage params;
2111 params.output = output;
2112 params.imageFormat = OrthancPluginImageFormat_Png;
2113 params.pixelFormat = format;
2114 params.width = width;
2115 params.height = height;
2116 params.pitch = pitch;
2117 params.buffer = buffer;
2118 params.quality = 0; /* No quality for PNG */
2119 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
2120 }
2121
2122
2123
2124 typedef struct
2125 {
2126 OrthancPluginMemoryBuffer* target;
2127 const char* instanceId;
2128 } _OrthancPluginGetDicomForInstance;
2129
2130 /**
2131 * @brief Retrieve a DICOM instance using its Orthanc identifier.
2132 *
2133 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM
2134 * file is stored into a newly allocated memory buffer.
2135 *
2136 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2137 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2138 * @param instanceId The Orthanc identifier of the DICOM instance of interest.
2139 * @return 0 if success, or the error code if failure.
2140 * @ingroup Orthanc
2141 **/
2142 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance(
2143 OrthancPluginContext* context,
2144 OrthancPluginMemoryBuffer* target,
2145 const char* instanceId)
2146 {
2147 _OrthancPluginGetDicomForInstance params;
2148 params.target = target;
2149 params.instanceId = instanceId;
2150 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, &params);
2151 }
2152
2153
2154
2155 typedef struct
2156 {
2157 OrthancPluginMemoryBuffer* target;
2158 const char* uri;
2159 } _OrthancPluginRestApiGet;
2160
2161 /**
2162 * @brief Make a GET call to the built-in Orthanc REST API.
2163 *
2164 * Make a GET call to the built-in Orthanc REST API. The result to
2165 * the query is stored into a newly allocated memory buffer.
2166 *
2167 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2168 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2169 * @param uri The URI in the built-in Orthanc API.
2170 * @return 0 if success, or the error code if failure.
2171 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2172 * @see OrthancPluginRestApiGetAfterPlugins
2173 * @ingroup Orthanc
2174 **/
2175 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet(
2176 OrthancPluginContext* context,
2177 OrthancPluginMemoryBuffer* target,
2178 const char* uri)
2179 {
2180 _OrthancPluginRestApiGet params;
2181 params.target = target;
2182 params.uri = uri;
2183 return context->InvokeService(context, _OrthancPluginService_RestApiGet, &params);
2184 }
2185
2186
2187
2188 /**
2189 * @brief Make a GET call to the REST API, as tainted by the plugins.
2190 *
2191 * Make a GET call to the Orthanc REST API, after all the plugins
2192 * are applied. In other words, if some plugin overrides or adds the
2193 * called URI to the built-in Orthanc REST API, this call will
2194 * return the result provided by this plugin. The result to the
2195 * query is stored into a newly allocated memory buffer.
2196 *
2197 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2198 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2199 * @param uri The URI in the built-in Orthanc API.
2200 * @return 0 if success, or the error code if failure.
2201 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2202 * @see OrthancPluginRestApiGet
2203 * @ingroup Orthanc
2204 **/
2205 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins(
2206 OrthancPluginContext* context,
2207 OrthancPluginMemoryBuffer* target,
2208 const char* uri)
2209 {
2210 _OrthancPluginRestApiGet params;
2211 params.target = target;
2212 params.uri = uri;
2213 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, &params);
2214 }
2215
2216
2217
2218 typedef struct
2219 {
2220 OrthancPluginMemoryBuffer* target;
2221 const char* uri;
2222 const void* body;
2223 uint32_t bodySize;
2224 } _OrthancPluginRestApiPostPut;
2225
2226 /**
2227 * @brief Make a POST call to the built-in Orthanc REST API.
2228 *
2229 * Make a POST call to the built-in Orthanc REST API. The result to
2230 * the query is stored into a newly allocated memory buffer.
2231 *
2232 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2233 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2234 * @param uri The URI in the built-in Orthanc API.
2235 * @param body The body of the POST request.
2236 * @param bodySize The size of the body.
2237 * @return 0 if success, or the error code if failure.
2238 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2239 * @see OrthancPluginRestApiPostAfterPlugins
2240 * @ingroup Orthanc
2241 **/
2242 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost(
2243 OrthancPluginContext* context,
2244 OrthancPluginMemoryBuffer* target,
2245 const char* uri,
2246 const void* body,
2247 uint32_t bodySize)
2248 {
2249 _OrthancPluginRestApiPostPut params;
2250 params.target = target;
2251 params.uri = uri;
2252 params.body = body;
2253 params.bodySize = bodySize;
2254 return context->InvokeService(context, _OrthancPluginService_RestApiPost, &params);
2255 }
2256
2257
2258 /**
2259 * @brief Make a POST call to the REST API, as tainted by the plugins.
2260 *
2261 * Make a POST call to the Orthanc REST API, after all the plugins
2262 * are applied. In other words, if some plugin overrides or adds the
2263 * called URI to the built-in Orthanc REST API, this call will
2264 * return the result provided by this plugin. The result to the
2265 * query is stored into a newly allocated memory buffer.
2266 *
2267 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2268 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2269 * @param uri The URI in the built-in Orthanc API.
2270 * @param body The body of the POST request.
2271 * @param bodySize The size of the body.
2272 * @return 0 if success, or the error code if failure.
2273 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2274 * @see OrthancPluginRestApiPost
2275 * @ingroup Orthanc
2276 **/
2277 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins(
2278 OrthancPluginContext* context,
2279 OrthancPluginMemoryBuffer* target,
2280 const char* uri,
2281 const void* body,
2282 uint32_t bodySize)
2283 {
2284 _OrthancPluginRestApiPostPut params;
2285 params.target = target;
2286 params.uri = uri;
2287 params.body = body;
2288 params.bodySize = bodySize;
2289 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, &params);
2290 }
2291
2292
2293
2294 /**
2295 * @brief Make a DELETE call to the built-in Orthanc REST API.
2296 *
2297 * Make a DELETE call to the built-in Orthanc REST API.
2298 *
2299 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2300 * @param uri The URI to delete in the built-in Orthanc API.
2301 * @return 0 if success, or the error code if failure.
2302 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2303 * @see OrthancPluginRestApiDeleteAfterPlugins
2304 * @ingroup Orthanc
2305 **/
2306 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete(
2307 OrthancPluginContext* context,
2308 const char* uri)
2309 {
2310 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
2311 }
2312
2313
2314 /**
2315 * @brief Make a DELETE call to the REST API, as tainted by the plugins.
2316 *
2317 * Make a DELETE call to the Orthanc REST API, after all the plugins
2318 * are applied. In other words, if some plugin overrides or adds the
2319 * called URI to the built-in Orthanc REST API, this call will
2320 * return the result provided by this plugin.
2321 *
2322 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2323 * @param uri The URI to delete in the built-in Orthanc API.
2324 * @return 0 if success, or the error code if failure.
2325 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2326 * @see OrthancPluginRestApiDelete
2327 * @ingroup Orthanc
2328 **/
2329 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins(
2330 OrthancPluginContext* context,
2331 const char* uri)
2332 {
2333 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri);
2334 }
2335
2336
2337
2338 /**
2339 * @brief Make a PUT call to the built-in Orthanc REST API.
2340 *
2341 * Make a PUT call to the built-in Orthanc REST API. The result to
2342 * the query is stored into a newly allocated memory buffer.
2343 *
2344 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2345 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2346 * @param uri The URI in the built-in Orthanc API.
2347 * @param body The body of the PUT request.
2348 * @param bodySize The size of the body.
2349 * @return 0 if success, or the error code if failure.
2350 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2351 * @see OrthancPluginRestApiPutAfterPlugins
2352 * @ingroup Orthanc
2353 **/
2354 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut(
2355 OrthancPluginContext* context,
2356 OrthancPluginMemoryBuffer* target,
2357 const char* uri,
2358 const void* body,
2359 uint32_t bodySize)
2360 {
2361 _OrthancPluginRestApiPostPut params;
2362 params.target = target;
2363 params.uri = uri;
2364 params.body = body;
2365 params.bodySize = bodySize;
2366 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
2367 }
2368
2369
2370
2371 /**
2372 * @brief Make a PUT call to the REST API, as tainted by the plugins.
2373 *
2374 * Make a PUT call to the Orthanc REST API, after all the plugins
2375 * are applied. In other words, if some plugin overrides or adds the
2376 * called URI to the built-in Orthanc REST API, this call will
2377 * return the result provided by this plugin. The result to the
2378 * query is stored into a newly allocated memory buffer.
2379 *
2380 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2381 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2382 * @param uri The URI in the built-in Orthanc API.
2383 * @param body The body of the PUT request.
2384 * @param bodySize The size of the body.
2385 * @return 0 if success, or the error code if failure.
2386 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2387 * @see OrthancPluginRestApiPut
2388 * @ingroup Orthanc
2389 **/
2390 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins(
2391 OrthancPluginContext* context,
2392 OrthancPluginMemoryBuffer* target,
2393 const char* uri,
2394 const void* body,
2395 uint32_t bodySize)
2396 {
2397 _OrthancPluginRestApiPostPut params;
2398 params.target = target;
2399 params.uri = uri;
2400 params.body = body;
2401 params.bodySize = bodySize;
2402 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, &params);
2403 }
2404
2405
2406
2407 typedef struct
2408 {
2409 OrthancPluginRestOutput* output;
2410 const char* argument;
2411 } _OrthancPluginOutputPlusArgument;
2412
2413 /**
2414 * @brief Redirect a REST request.
2415 *
2416 * This function answers to a REST request by redirecting the user
2417 * to another URI using HTTP status 301.
2418 *
2419 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2420 * @param output The HTTP connection to the client application.
2421 * @param redirection Where to redirect.
2422 * @ingroup REST
2423 **/
2424 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
2425 OrthancPluginContext* context,
2426 OrthancPluginRestOutput* output,
2427 const char* redirection)
2428 {
2429 _OrthancPluginOutputPlusArgument params;
2430 params.output = output;
2431 params.argument = redirection;
2432 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
2433 }
2434
2435
2436
2437 typedef struct
2438 {
2439 char** result;
2440 const char* argument;
2441 } _OrthancPluginRetrieveDynamicString;
2442
2443 /**
2444 * @brief Look for a patient.
2445 *
2446 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
2447 * This function uses the database index to run as fast as possible (it does not loop
2448 * over all the stored patients).
2449 *
2450 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2451 * @param patientID The Patient ID of interest.
2452 * @return The NULL value if the patient is non-existent, or a string containing the
2453 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
2454 * @ingroup Orthanc
2455 **/
2456 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
2457 OrthancPluginContext* context,
2458 const char* patientID)
2459 {
2460 char* result;
2461
2462 _OrthancPluginRetrieveDynamicString params;
2463 params.result = &result;
2464 params.argument = patientID;
2465
2466 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, &params) != OrthancPluginErrorCode_Success)
2467 {
2468 /* Error */
2469 return NULL;
2470 }
2471 else
2472 {
2473 return result;
2474 }
2475 }
2476
2477
2478 /**
2479 * @brief Look for a study.
2480 *
2481 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
2482 * This function uses the database index to run as fast as possible (it does not loop
2483 * over all the stored studies).
2484 *
2485 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2486 * @param studyUID The Study Instance UID of interest.
2487 * @return The NULL value if the study is non-existent, or a string containing the
2488 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2489 * @ingroup Orthanc
2490 **/
2491 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
2492 OrthancPluginContext* context,
2493 const char* studyUID)
2494 {
2495 char* result;
2496
2497 _OrthancPluginRetrieveDynamicString params;
2498 params.result = &result;
2499 params.argument = studyUID;
2500
2501 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, &params) != OrthancPluginErrorCode_Success)
2502 {
2503 /* Error */
2504 return NULL;
2505 }
2506 else
2507 {
2508 return result;
2509 }
2510 }
2511
2512
2513 /**
2514 * @brief Look for a study, using the accession number.
2515 *
2516 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
2517 * This function uses the database index to run as fast as possible (it does not loop
2518 * over all the stored studies).
2519 *
2520 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2521 * @param accessionNumber The Accession Number of interest.
2522 * @return The NULL value if the study is non-existent, or a string containing the
2523 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2524 * @ingroup Orthanc
2525 **/
2526 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
2527 OrthancPluginContext* context,
2528 const char* accessionNumber)
2529 {
2530 char* result;
2531
2532 _OrthancPluginRetrieveDynamicString params;
2533 params.result = &result;
2534 params.argument = accessionNumber;
2535
2536 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, &params) != OrthancPluginErrorCode_Success)
2537 {
2538 /* Error */
2539 return NULL;
2540 }
2541 else
2542 {
2543 return result;
2544 }
2545 }
2546
2547
2548 /**
2549 * @brief Look for a series.
2550 *
2551 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
2552 * This function uses the database index to run as fast as possible (it does not loop
2553 * over all the stored series).
2554 *
2555 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2556 * @param seriesUID The Series Instance UID of interest.
2557 * @return The NULL value if the series is non-existent, or a string containing the
2558 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
2559 * @ingroup Orthanc
2560 **/
2561 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
2562 OrthancPluginContext* context,
2563 const char* seriesUID)
2564 {
2565 char* result;
2566
2567 _OrthancPluginRetrieveDynamicString params;
2568 params.result = &result;
2569 params.argument = seriesUID;
2570
2571 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, &params) != OrthancPluginErrorCode_Success)
2572 {
2573 /* Error */
2574 return NULL;
2575 }
2576 else
2577 {
2578 return result;
2579 }
2580 }
2581
2582
2583 /**
2584 * @brief Look for an instance.
2585 *
2586 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
2587 * This function uses the database index to run as fast as possible (it does not loop
2588 * over all the stored instances).
2589 *
2590 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2591 * @param sopInstanceUID The SOP Instance UID of interest.
2592 * @return The NULL value if the instance is non-existent, or a string containing the
2593 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
2594 * @ingroup Orthanc
2595 **/
2596 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
2597 OrthancPluginContext* context,
2598 const char* sopInstanceUID)
2599 {
2600 char* result;
2601
2602 _OrthancPluginRetrieveDynamicString params;
2603 params.result = &result;
2604 params.argument = sopInstanceUID;
2605
2606 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, &params) != OrthancPluginErrorCode_Success)
2607 {
2608 /* Error */
2609 return NULL;
2610 }
2611 else
2612 {
2613 return result;
2614 }
2615 }
2616
2617
2618
2619 typedef struct
2620 {
2621 OrthancPluginRestOutput* output;
2622 uint16_t status;
2623 } _OrthancPluginSendHttpStatusCode;
2624
2625 /**
2626 * @brief Send a HTTP status code.
2627 *
2628 * This function answers to a REST request by sending a HTTP status
2629 * code (such as "400 - Bad Request"). Note that:
2630 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
2631 * - Redirections (status 301) must use ::OrthancPluginRedirect().
2632 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
2633 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
2634 *
2635 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2636 * @param output The HTTP connection to the client application.
2637 * @param status The HTTP status code to be sent.
2638 * @ingroup REST
2639 * @see OrthancPluginSendHttpStatus()
2640 **/
2641 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
2642 OrthancPluginContext* context,
2643 OrthancPluginRestOutput* output,
2644 uint16_t status)
2645 {
2646 _OrthancPluginSendHttpStatusCode params;
2647 params.output = output;
2648 params.status = status;
2649 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
2650 }
2651
2652
2653 /**
2654 * @brief Signal that a REST request is not authorized.
2655 *
2656 * This function answers to a REST request by signaling that it is
2657 * not authorized.
2658 *
2659 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2660 * @param output The HTTP connection to the client application.
2661 * @param realm The realm for the authorization process.
2662 * @ingroup REST
2663 **/
2664 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
2665 OrthancPluginContext* context,
2666 OrthancPluginRestOutput* output,
2667 const char* realm)
2668 {
2669 _OrthancPluginOutputPlusArgument params;
2670 params.output = output;
2671 params.argument = realm;
2672 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
2673 }
2674
2675
2676 /**
2677 * @brief Signal that this URI does not support this HTTP method.
2678 *
2679 * This function answers to a REST request by signaling that the
2680 * queried URI does not support this method.
2681 *
2682 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2683 * @param output The HTTP connection to the client application.
2684 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
2685 * @ingroup REST
2686 **/
2687 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
2688 OrthancPluginContext* context,
2689 OrthancPluginRestOutput* output,
2690 const char* allowedMethods)
2691 {
2692 _OrthancPluginOutputPlusArgument params;
2693 params.output = output;
2694 params.argument = allowedMethods;
2695 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
2696 }
2697
2698
2699 typedef struct
2700 {
2701 OrthancPluginRestOutput* output;
2702 const char* key;
2703 const char* value;
2704 } _OrthancPluginSetHttpHeader;
2705
2706 /**
2707 * @brief Set a cookie.
2708 *
2709 * This function sets a cookie in the HTTP client.
2710 *
2711 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2712 * @param output The HTTP connection to the client application.
2713 * @param cookie The cookie to be set.
2714 * @param value The value of the cookie.
2715 * @ingroup REST
2716 **/
2717 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
2718 OrthancPluginContext* context,
2719 OrthancPluginRestOutput* output,
2720 const char* cookie,
2721 const char* value)
2722 {
2723 _OrthancPluginSetHttpHeader params;
2724 params.output = output;
2725 params.key = cookie;
2726 params.value = value;
2727 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
2728 }
2729
2730
2731 /**
2732 * @brief Set some HTTP header.
2733 *
2734 * This function sets a HTTP header in the HTTP answer.
2735 *
2736 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2737 * @param output The HTTP connection to the client application.
2738 * @param key The HTTP header to be set.
2739 * @param value The value of the HTTP header.
2740 * @ingroup REST
2741 **/
2742 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
2743 OrthancPluginContext* context,
2744 OrthancPluginRestOutput* output,
2745 const char* key,
2746 const char* value)
2747 {
2748 _OrthancPluginSetHttpHeader params;
2749 params.output = output;
2750 params.key = key;
2751 params.value = value;
2752 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, &params);
2753 }
2754
2755
2756 typedef struct
2757 {
2758 char** resultStringToFree;
2759 const char** resultString;
2760 int64_t* resultInt64;
2761 const char* key;
2762 const OrthancPluginDicomInstance* instance;
2763 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */
2764 } _OrthancPluginAccessDicomInstance;
2765
2766
2767 /**
2768 * @brief Get the AET of a DICOM instance.
2769 *
2770 * This function returns the Application Entity Title (AET) of the
2771 * DICOM modality from which a DICOM instance originates.
2772 *
2773 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2774 * @param instance The instance of interest.
2775 * @return The AET if success, NULL if error.
2776 * @ingroup DicomInstance
2777 **/
2778 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
2779 OrthancPluginContext* context,
2780 const OrthancPluginDicomInstance* instance)
2781 {
2782 const char* result;
2783
2784 _OrthancPluginAccessDicomInstance params;
2785 memset(&params, 0, sizeof(params));
2786 params.resultString = &result;
2787 params.instance = instance;
2788
2789 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, &params) != OrthancPluginErrorCode_Success)
2790 {
2791 /* Error */
2792 return NULL;
2793 }
2794 else
2795 {
2796 return result;
2797 }
2798 }
2799
2800
2801 /**
2802 * @brief Get the size of a DICOM file.
2803 *
2804 * This function returns the number of bytes of the given DICOM instance.
2805 *
2806 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2807 * @param instance The instance of interest.
2808 * @return The size of the file, -1 in case of error.
2809 * @ingroup DicomInstance
2810 **/
2811 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
2812 OrthancPluginContext* context,
2813 const OrthancPluginDicomInstance* instance)
2814 {
2815 int64_t size;
2816
2817 _OrthancPluginAccessDicomInstance params;
2818 memset(&params, 0, sizeof(params));
2819 params.resultInt64 = &size;
2820 params.instance = instance;
2821
2822 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, &params) != OrthancPluginErrorCode_Success)
2823 {
2824 /* Error */
2825 return -1;
2826 }
2827 else
2828 {
2829 return size;
2830 }
2831 }
2832
2833
2834 /**
2835 * @brief Get the data of a DICOM file.
2836 *
2837 * This function returns a pointer to the content of the given DICOM instance.
2838 *
2839 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2840 * @param instance The instance of interest.
2841 * @return The pointer to the DICOM data, NULL in case of error.
2842 * @ingroup DicomInstance
2843 **/
2844 ORTHANC_PLUGIN_INLINE const void* OrthancPluginGetInstanceData(
2845 OrthancPluginContext* context,
2846 const OrthancPluginDicomInstance* instance)
2847 {
2848 const char* result;
2849
2850 _OrthancPluginAccessDicomInstance params;
2851 memset(&params, 0, sizeof(params));
2852 params.resultString = &result;
2853 params.instance = instance;
2854
2855 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, &params) != OrthancPluginErrorCode_Success)
2856 {
2857 /* Error */
2858 return NULL;
2859 }
2860 else
2861 {
2862 return result;
2863 }
2864 }
2865
2866
2867 /**
2868 * @brief Get the DICOM tag hierarchy as a JSON file.
2869 *
2870 * This function returns a pointer to a newly created string
2871 * containing a JSON file. This JSON file encodes the tag hierarchy
2872 * of the given DICOM instance.
2873 *
2874 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2875 * @param instance The instance of interest.
2876 * @return The NULL value in case of error, or a string containing the JSON file.
2877 * This string must be freed by OrthancPluginFreeString().
2878 * @ingroup DicomInstance
2879 **/
2880 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
2881 OrthancPluginContext* context,
2882 const OrthancPluginDicomInstance* instance)
2883 {
2884 char* result;
2885
2886 _OrthancPluginAccessDicomInstance params;
2887 memset(&params, 0, sizeof(params));
2888 params.resultStringToFree = &result;
2889 params.instance = instance;
2890
2891 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, &params) != OrthancPluginErrorCode_Success)
2892 {
2893 /* Error */
2894 return NULL;
2895 }
2896 else
2897 {
2898 return result;
2899 }
2900 }
2901
2902
2903 /**
2904 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
2905 *
2906 * This function returns a pointer to a newly created string
2907 * containing a JSON file. This JSON file encodes the tag hierarchy
2908 * of the given DICOM instance. In contrast with
2909 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in
2910 * its simplified version.
2911 *
2912 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2913 * @param instance The instance of interest.
2914 * @return The NULL value in case of error, or a string containing the JSON file.
2915 * This string must be freed by OrthancPluginFreeString().
2916 * @ingroup DicomInstance
2917 **/
2918 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
2919 OrthancPluginContext* context,
2920 const OrthancPluginDicomInstance* instance)
2921 {
2922 char* result;
2923
2924 _OrthancPluginAccessDicomInstance params;
2925 memset(&params, 0, sizeof(params));
2926 params.resultStringToFree = &result;
2927 params.instance = instance;
2928
2929 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, &params) != OrthancPluginErrorCode_Success)
2930 {
2931 /* Error */
2932 return NULL;
2933 }
2934 else
2935 {
2936 return result;
2937 }
2938 }
2939
2940
2941 /**
2942 * @brief Check whether a DICOM instance is associated with some metadata.
2943 *
2944 * This function checks whether the DICOM instance of interest is
2945 * associated with some metadata. As of Orthanc 0.8.1, in the
2946 * callbacks registered by
2947 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
2948 * possibly available metadata are "ReceptionDate", "RemoteAET" and
2949 * "IndexInSeries".
2950 *
2951 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2952 * @param instance The instance of interest.
2953 * @param metadata The metadata of interest.
2954 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
2955 * @ingroup DicomInstance
2956 **/
2957 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata(
2958 OrthancPluginContext* context,
2959 const OrthancPluginDicomInstance* instance,
2960 const char* metadata)
2961 {
2962 int64_t result;
2963
2964 _OrthancPluginAccessDicomInstance params;
2965 memset(&params, 0, sizeof(params));
2966 params.resultInt64 = &result;
2967 params.instance = instance;
2968 params.key = metadata;
2969
2970 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
2971 {
2972 /* Error */
2973 return -1;
2974 }
2975 else
2976 {
2977 return (result != 0);
2978 }
2979 }
2980
2981
2982 /**
2983 * @brief Get the value of some metadata associated with a given DICOM instance.
2984 *
2985 * This functions returns the value of some metadata that is associated with the DICOM instance of interest.
2986 * Before calling this function, the existence of the metadata must have been checked with
2987 * ::OrthancPluginHasInstanceMetadata().
2988 *
2989 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2990 * @param instance The instance of interest.
2991 * @param metadata The metadata of interest.
2992 * @return The metadata value if success, NULL if error. Please note that the
2993 * returned string belongs to the instance object and must NOT be
2994 * deallocated. Please make a copy of the string if you wish to access
2995 * it later.
2996 * @ingroup DicomInstance
2997 **/
2998 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
2999 OrthancPluginContext* context,
3000 const OrthancPluginDicomInstance* instance,
3001 const char* metadata)
3002 {
3003 const char* result;
3004
3005 _OrthancPluginAccessDicomInstance params;
3006 memset(&params, 0, sizeof(params));
3007 params.resultString = &result;
3008 params.instance = instance;
3009 params.key = metadata;
3010
3011 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
3012 {
3013 /* Error */
3014 return NULL;
3015 }
3016 else
3017 {
3018 return result;
3019 }
3020 }
3021
3022
3023
3024 typedef struct
3025 {
3026 OrthancPluginStorageCreate create;
3027 OrthancPluginStorageRead read;
3028 OrthancPluginStorageRemove remove;
3029 OrthancPluginFree free;
3030 } _OrthancPluginRegisterStorageArea;
3031
3032 /**
3033 * @brief Register a custom storage area.
3034 *
3035 * This function registers a custom storage area, to replace the
3036 * built-in way Orthanc stores its files on the filesystem. This
3037 * function must be called during the initialization of the plugin,
3038 * i.e. inside the OrthancPluginInitialize() public function.
3039 *
3040 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3041 * @param create The callback function to store a file on the custom storage area.
3042 * @param read The callback function to read a file from the custom storage area.
3043 * @param remove The callback function to remove a file from the custom storage area.
3044 * @ingroup Callbacks
3045 **/
3046 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
3047 OrthancPluginContext* context,
3048 OrthancPluginStorageCreate create,
3049 OrthancPluginStorageRead read,
3050 OrthancPluginStorageRemove remove)
3051 {
3052 _OrthancPluginRegisterStorageArea params;
3053 params.create = create;
3054 params.read = read;
3055 params.remove = remove;
3056
3057 #ifdef __cplusplus
3058 params.free = ::free;
3059 #else
3060 params.free = free;
3061 #endif
3062
3063 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, &params);
3064 }
3065
3066
3067
3068 /**
3069 * @brief Return the path to the Orthanc executable.
3070 *
3071 * This function returns the path to the Orthanc executable.
3072 *
3073 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3074 * @return NULL in the case of an error, or a newly allocated string
3075 * containing the path. This string must be freed by
3076 * OrthancPluginFreeString().
3077 **/
3078 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
3079 {
3080 char* result;
3081
3082 _OrthancPluginRetrieveDynamicString params;
3083 params.result = &result;
3084 params.argument = NULL;
3085
3086 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, &params) != OrthancPluginErrorCode_Success)
3087 {
3088 /* Error */
3089 return NULL;
3090 }
3091 else
3092 {
3093 return result;
3094 }
3095 }
3096
3097
3098 /**
3099 * @brief Return the directory containing the Orthanc.
3100 *
3101 * This function returns the path to the directory containing the Orthanc executable.
3102 *
3103 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3104 * @return NULL in the case of an error, or a newly allocated string
3105 * containing the path. This string must be freed by
3106 * OrthancPluginFreeString().
3107 **/
3108 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
3109 {
3110 char* result;
3111
3112 _OrthancPluginRetrieveDynamicString params;
3113 params.result = &result;
3114 params.argument = NULL;
3115
3116 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, &params) != OrthancPluginErrorCode_Success)
3117 {
3118 /* Error */
3119 return NULL;
3120 }
3121 else
3122 {
3123 return result;
3124 }
3125 }
3126
3127
3128 /**
3129 * @brief Return the path to the configuration file(s).
3130 *
3131 * This function returns the path to the configuration file(s) that
3132 * was specified when starting Orthanc. Since version 0.9.1, this
3133 * path can refer to a folder that stores a set of configuration
3134 * files. This function is deprecated in favor of
3135 * OrthancPluginGetConfiguration().
3136 *
3137 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3138 * @return NULL in the case of an error, or a newly allocated string
3139 * containing the path. This string must be freed by
3140 * OrthancPluginFreeString().
3141 * @see OrthancPluginGetConfiguration()
3142 **/
3143 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
3144 {
3145 char* result;
3146
3147 _OrthancPluginRetrieveDynamicString params;
3148 params.result = &result;
3149 params.argument = NULL;
3150
3151 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, &params) != OrthancPluginErrorCode_Success)
3152 {
3153 /* Error */
3154 return NULL;
3155 }
3156 else
3157 {
3158 return result;
3159 }
3160 }
3161
3162
3163
3164 typedef struct
3165 {
3166 OrthancPluginOnChangeCallback callback;
3167 } _OrthancPluginOnChangeCallback;
3168
3169 /**
3170 * @brief Register a callback to monitor changes.
3171 *
3172 * This function registers a callback function that is called
3173 * whenever a change happens to some DICOM resource.
3174 *
3175 * @warning If your change callback has to call the REST API of
3176 * Orthanc, you should make these calls in a separate thread (with
3177 * the events passing through a message queue). Otherwise, this
3178 * could result in deadlocks in the presence of other plugins or Lua
3179 * scripts.
3180 *
3181 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3182 * @param callback The callback function.
3183 * @ingroup Callbacks
3184 **/
3185 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback(
3186 OrthancPluginContext* context,
3187 OrthancPluginOnChangeCallback callback)
3188 {
3189 _OrthancPluginOnChangeCallback params;
3190 params.callback = callback;
3191
3192 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, &params);
3193 }
3194
3195
3196
3197 typedef struct
3198 {
3199 const char* plugin;
3200 _OrthancPluginProperty property;
3201 const char* value;
3202 } _OrthancPluginSetPluginProperty;
3203
3204
3205 /**
3206 * @brief Set the URI where the plugin provides its Web interface.
3207 *
3208 * For plugins that come with a Web interface, this function
3209 * declares the entry path where to find this interface. This
3210 * information is notably used in the "Plugins" page of Orthanc
3211 * Explorer.
3212 *
3213 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3214 * @param uri The root URI for this plugin.
3215 **/
3216 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri(
3217 OrthancPluginContext* context,
3218 const char* uri)
3219 {
3220 _OrthancPluginSetPluginProperty params;
3221 params.plugin = OrthancPluginGetName();
3222 params.property = _OrthancPluginProperty_RootUri;
3223 params.value = uri;
3224
3225 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3226 }
3227
3228
3229 /**
3230 * @brief Set a description for this plugin.
3231 *
3232 * Set a description for this plugin. It is displayed in the
3233 * "Plugins" page of Orthanc Explorer.
3234 *
3235 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3236 * @param description The description.
3237 **/
3238 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription(
3239 OrthancPluginContext* context,
3240 const char* description)
3241 {
3242 _OrthancPluginSetPluginProperty params;
3243 params.plugin = OrthancPluginGetName();
3244 params.property = _OrthancPluginProperty_Description;
3245 params.value = description;
3246
3247 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3248 }
3249
3250
3251 /**
3252 * @brief Extend the JavaScript code of Orthanc Explorer.
3253 *
3254 * Add JavaScript code to customize the default behavior of Orthanc
3255 * Explorer. This can for instance be used to add new buttons.
3256 *
3257 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3258 * @param javascript The custom JavaScript code.
3259 **/
3260 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer(
3261 OrthancPluginContext* context,
3262 const char* javascript)
3263 {
3264 _OrthancPluginSetPluginProperty params;
3265 params.plugin = OrthancPluginGetName();
3266 params.property = _OrthancPluginProperty_OrthancExplorer;
3267 params.value = javascript;
3268
3269 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3270 }
3271
3272
3273 typedef struct
3274 {
3275 char** result;
3276 int32_t property;
3277 const char* value;
3278 } _OrthancPluginGlobalProperty;
3279
3280
3281 /**
3282 * @brief Get the value of a global property.
3283 *
3284 * Get the value of a global property that is stored in the Orthanc database. Global
3285 * properties whose index is below 1024 are reserved by Orthanc.
3286 *
3287 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3288 * @param property The global property of interest.
3289 * @param defaultValue The value to return, if the global property is unset.
3290 * @return The value of the global property, or NULL in the case of an error. This
3291 * string must be freed by OrthancPluginFreeString().
3292 * @ingroup Orthanc
3293 **/
3294 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty(
3295 OrthancPluginContext* context,
3296 int32_t property,
3297 const char* defaultValue)
3298 {
3299 char* result;
3300
3301 _OrthancPluginGlobalProperty params;
3302 params.result = &result;
3303 params.property = property;
3304 params.value = defaultValue;
3305
3306 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, &params) != OrthancPluginErrorCode_Success)
3307 {
3308 /* Error */
3309 return NULL;
3310 }
3311 else
3312 {
3313 return result;
3314 }
3315 }
3316
3317
3318 /**
3319 * @brief Set the value of a global property.
3320 *
3321 * Set the value of a global property into the Orthanc
3322 * database. Setting a global property can be used by plugins to
3323 * save their internal parameters. Plugins are only allowed to set
3324 * properties whose index are above or equal to 1024 (properties
3325 * below 1024 are read-only and reserved by Orthanc).
3326 *
3327 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3328 * @param property The global property of interest.
3329 * @param value The value to be set in the global property.
3330 * @return 0 if success, or the error code if failure.
3331 * @ingroup Orthanc
3332 **/
3333 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty(
3334 OrthancPluginContext* context,
3335 int32_t property,
3336 const char* value)
3337 {
3338 _OrthancPluginGlobalProperty params;
3339 params.result = NULL;
3340 params.property = property;
3341 params.value = value;
3342
3343 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, &params);
3344 }
3345
3346
3347
3348 typedef struct
3349 {
3350 int32_t *resultInt32;
3351 uint32_t *resultUint32;
3352 int64_t *resultInt64;
3353 uint64_t *resultUint64;
3354 } _OrthancPluginReturnSingleValue;
3355
3356 /**
3357 * @brief Get the number of command-line arguments.
3358 *
3359 * Retrieve the number of command-line arguments that were used to launch Orthanc.
3360 *
3361 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3362 * @return The number of arguments.
3363 **/
3364 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount(
3365 OrthancPluginContext* context)
3366 {
3367 uint32_t count = 0;
3368
3369 _OrthancPluginReturnSingleValue params;
3370 memset(&params, 0, sizeof(params));
3371 params.resultUint32 = &count;
3372
3373 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, &params) != OrthancPluginErrorCode_Success)
3374 {
3375 /* Error */
3376 return 0;
3377 }
3378 else
3379 {
3380 return count;
3381 }
3382 }
3383
3384
3385
3386 /**
3387 * @brief Get the value of a command-line argument.
3388 *
3389 * Get the value of one of the command-line arguments that were used
3390 * to launch Orthanc. The number of available arguments can be
3391 * retrieved by OrthancPluginGetCommandLineArgumentsCount().
3392 *
3393 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3394 * @param argument The index of the argument.
3395 * @return The value of the argument, or NULL in the case of an error. This
3396 * string must be freed by OrthancPluginFreeString().
3397 **/
3398 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument(
3399 OrthancPluginContext* context,
3400 uint32_t argument)
3401 {
3402 char* result;
3403
3404 _OrthancPluginGlobalProperty params;
3405 params.result = &result;
3406 params.property = (int32_t) argument;
3407 params.value = NULL;
3408
3409 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, &params) != OrthancPluginErrorCode_Success)
3410 {
3411 /* Error */
3412 return NULL;
3413 }
3414 else
3415 {
3416 return result;
3417 }
3418 }
3419
3420
3421 /**
3422 * @brief Get the expected version of the database schema.
3423 *
3424 * Retrieve the expected version of the database schema.
3425 *
3426 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3427 * @return The version.
3428 * @ingroup Callbacks
3429 **/
3430 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
3431 OrthancPluginContext* context)
3432 {
3433 uint32_t count = 0;
3434
3435 _OrthancPluginReturnSingleValue params;
3436 memset(&params, 0, sizeof(params));
3437 params.resultUint32 = &count;
3438
3439 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params) != OrthancPluginErrorCode_Success)
3440 {
3441 /* Error */
3442 return 0;
3443 }
3444 else
3445 {
3446 return count;
3447 }
3448 }
3449
3450
3451
3452 /**
3453 * @brief Return the content of the configuration file(s).
3454 *
3455 * This function returns the content of the configuration that is
3456 * used by Orthanc, formatted as a JSON string.
3457 *
3458 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3459 * @return NULL in the case of an error, or a newly allocated string
3460 * containing the configuration. This string must be freed by
3461 * OrthancPluginFreeString().
3462 **/
3463 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context)
3464 {
3465 char* result;
3466
3467 _OrthancPluginRetrieveDynamicString params;
3468 params.result = &result;
3469 params.argument = NULL;
3470
3471 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, &params) != OrthancPluginErrorCode_Success)
3472 {
3473 /* Error */
3474 return NULL;
3475 }
3476 else
3477 {
3478 return result;
3479 }
3480 }
3481
3482
3483
3484 typedef struct
3485 {
3486 OrthancPluginRestOutput* output;
3487 const char* subType;
3488 const char* contentType;
3489 } _OrthancPluginStartMultipartAnswer;
3490
3491 /**
3492 * @brief Start an HTTP multipart answer.
3493 *
3494 * Initiates a HTTP multipart answer, as the result of a REST request.
3495 *
3496 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3497 * @param output The HTTP connection to the client application.
3498 * @param subType The sub-type of the multipart answer ("mixed" or "related").
3499 * @param contentType The MIME type of the items in the multipart answer.
3500 * @return 0 if success, or the error code if failure.
3501 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2()
3502 * @ingroup REST
3503 **/
3504 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer(
3505 OrthancPluginContext* context,
3506 OrthancPluginRestOutput* output,
3507 const char* subType,
3508 const char* contentType)
3509 {
3510 _OrthancPluginStartMultipartAnswer params;
3511 params.output = output;
3512 params.subType = subType;
3513 params.contentType = contentType;
3514 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, &params);
3515 }
3516
3517
3518 /**
3519 * @brief Send an item as a part of some HTTP multipart answer.
3520 *
3521 * This function sends an item as a part of some HTTP multipart
3522 * answer that was initiated by OrthancPluginStartMultipartAnswer().
3523 *
3524 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3525 * @param output The HTTP connection to the client application.
3526 * @param answer Pointer to the memory buffer containing the item.
3527 * @param answerSize Number of bytes of the item.
3528 * @return 0 if success, or the error code if failure (this notably happens
3529 * if the connection is closed by the client).
3530 * @see OrthancPluginSendMultipartItem2()
3531 * @ingroup REST
3532 **/
3533 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem(
3534 OrthancPluginContext* context,
3535 OrthancPluginRestOutput* output,
3536 const char* answer,
3537 uint32_t answerSize)
3538 {
3539 _OrthancPluginAnswerBuffer params;
3540 params.output = output;
3541 params.answer = answer;
3542 params.answerSize = answerSize;
3543 params.mimeType = NULL;
3544 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, &params);
3545 }
3546
3547
3548
3549 typedef struct
3550 {
3551 OrthancPluginMemoryBuffer* target;
3552 const void* source;
3553 uint32_t size;
3554 OrthancPluginCompressionType compression;
3555 uint8_t uncompress;
3556 } _OrthancPluginBufferCompression;
3557
3558
3559 /**
3560 * @brief Compress or decompress a buffer.
3561 *
3562 * This function compresses or decompresses a buffer, using the
3563 * version of the zlib library that is used by the Orthanc core.
3564 *
3565 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3566 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3567 * @param source The source buffer.
3568 * @param size The size in bytes of the source buffer.
3569 * @param compression The compression algorithm.
3570 * @param uncompress If set to "0", the buffer must be compressed.
3571 * If set to "1", the buffer must be uncompressed.
3572 * @return 0 if success, or the error code if failure.
3573 * @ingroup Images
3574 **/
3575 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression(
3576 OrthancPluginContext* context,
3577 OrthancPluginMemoryBuffer* target,
3578 const void* source,
3579 uint32_t size,
3580 OrthancPluginCompressionType compression,
3581 uint8_t uncompress)
3582 {
3583 _OrthancPluginBufferCompression params;
3584 params.target = target;
3585 params.source = source;
3586 params.size = size;
3587 params.compression = compression;
3588 params.uncompress = uncompress;
3589
3590 return context->InvokeService(context, _OrthancPluginService_BufferCompression, &params);
3591 }
3592
3593
3594
3595 typedef struct
3596 {
3597 OrthancPluginMemoryBuffer* target;
3598 const char* path;
3599 } _OrthancPluginReadFile;
3600
3601 /**
3602 * @brief Read a file.
3603 *
3604 * Read the content of a file on the filesystem, and returns it into
3605 * a newly allocated memory buffer.
3606 *
3607 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3608 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3609 * @param path The path of the file to be read.
3610 * @return 0 if success, or the error code if failure.
3611 **/
3612 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile(
3613 OrthancPluginContext* context,
3614 OrthancPluginMemoryBuffer* target,
3615 const char* path)
3616 {
3617 _OrthancPluginReadFile params;
3618 params.target = target;
3619 params.path = path;
3620 return context->InvokeService(context, _OrthancPluginService_ReadFile, &params);
3621 }
3622
3623
3624
3625 typedef struct
3626 {
3627 const char* path;
3628 const void* data;
3629 uint32_t size;
3630 } _OrthancPluginWriteFile;
3631
3632 /**
3633 * @brief Write a file.
3634 *
3635 * Write the content of a memory buffer to the filesystem.
3636 *
3637 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3638 * @param path The path of the file to be written.
3639 * @param data The content of the memory buffer.
3640 * @param size The size of the memory buffer.
3641 * @return 0 if success, or the error code if failure.
3642 **/
3643 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile(
3644 OrthancPluginContext* context,
3645 const char* path,
3646 const void* data,
3647 uint32_t size)
3648 {
3649 _OrthancPluginWriteFile params;
3650 params.path = path;
3651 params.data = data;
3652 params.size = size;
3653 return context->InvokeService(context, _OrthancPluginService_WriteFile, &params);
3654 }
3655
3656
3657
3658 typedef struct
3659 {
3660 const char** target;
3661 OrthancPluginErrorCode error;
3662 } _OrthancPluginGetErrorDescription;
3663
3664 /**
3665 * @brief Get the description of a given error code.
3666 *
3667 * This function returns the description of a given error code.
3668 *
3669 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3670 * @param error The error code of interest.
3671 * @return The error description. This is a statically-allocated
3672 * string, do not free it.
3673 **/
3674 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription(
3675 OrthancPluginContext* context,
3676 OrthancPluginErrorCode error)
3677 {
3678 const char* result = NULL;
3679
3680 _OrthancPluginGetErrorDescription params;
3681 params.target = &result;
3682 params.error = error;
3683
3684 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, &params) != OrthancPluginErrorCode_Success ||
3685 result == NULL)
3686 {
3687 return "Unknown error code";
3688 }
3689 else
3690 {
3691 return result;
3692 }
3693 }
3694
3695
3696
3697 typedef struct
3698 {
3699 OrthancPluginRestOutput* output;
3700 uint16_t status;
3701 const char* body;
3702 uint32_t bodySize;
3703 } _OrthancPluginSendHttpStatus;
3704
3705 /**
3706 * @brief Send a HTTP status, with a custom body.
3707 *
3708 * This function answers to a HTTP request by sending a HTTP status
3709 * code (such as "400 - Bad Request"), together with a body
3710 * describing the error. The body will only be returned if the
3711 * configuration option "HttpDescribeErrors" of Orthanc is set to "true".
3712 *
3713 * Note that:
3714 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
3715 * - Redirections (status 301) must use ::OrthancPluginRedirect().
3716 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
3717 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
3718 *
3719 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3720 * @param output The HTTP connection to the client application.
3721 * @param status The HTTP status code to be sent.
3722 * @param body The body of the answer.
3723 * @param bodySize The size of the body.
3724 * @see OrthancPluginSendHttpStatusCode()
3725 * @ingroup REST
3726 **/
3727 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus(
3728 OrthancPluginContext* context,
3729 OrthancPluginRestOutput* output,
3730 uint16_t status,
3731 const char* body,
3732 uint32_t bodySize)
3733 {
3734 _OrthancPluginSendHttpStatus params;
3735 params.output = output;
3736 params.status = status;
3737 params.body = body;
3738 params.bodySize = bodySize;
3739 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, &params);
3740 }
3741
3742
3743
3744 typedef struct
3745 {
3746 const OrthancPluginImage* image;
3747 uint32_t* resultUint32;
3748 OrthancPluginPixelFormat* resultPixelFormat;
3749 void** resultBuffer;
3750 } _OrthancPluginGetImageInfo;
3751
3752
3753 /**
3754 * @brief Return the pixel format of an image.
3755 *
3756 * This function returns the type of memory layout for the pixels of the given image.
3757 *
3758 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3759 * @param image The image of interest.
3760 * @return The pixel format.
3761 * @ingroup Images
3762 **/
3763 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat(
3764 OrthancPluginContext* context,
3765 const OrthancPluginImage* image)
3766 {
3767 OrthancPluginPixelFormat target;
3768
3769 _OrthancPluginGetImageInfo params;
3770 memset(&params, 0, sizeof(params));
3771 params.image = image;
3772 params.resultPixelFormat = &target;
3773
3774 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, &params) != OrthancPluginErrorCode_Success)
3775 {
3776 return OrthancPluginPixelFormat_Unknown;
3777 }
3778 else
3779 {
3780 return (OrthancPluginPixelFormat) target;
3781 }
3782 }
3783
3784
3785
3786 /**
3787 * @brief Return the width of an image.
3788 *
3789 * This function returns the width of the given image.
3790 *
3791 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3792 * @param image The image of interest.
3793 * @return The width.
3794 * @ingroup Images
3795 **/
3796 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth(
3797 OrthancPluginContext* context,
3798 const OrthancPluginImage* image)
3799 {
3800 uint32_t width;
3801
3802 _OrthancPluginGetImageInfo params;
3803 memset(&params, 0, sizeof(params));
3804 params.image = image;
3805 params.resultUint32 = &width;
3806
3807 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, &params) != OrthancPluginErrorCode_Success)
3808 {
3809 return 0;
3810 }
3811 else
3812 {
3813 return width;
3814 }
3815 }
3816
3817
3818
3819 /**
3820 * @brief Return the height of an image.
3821 *
3822 * This function returns the height of the given image.
3823 *
3824 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3825 * @param image The image of interest.
3826 * @return The height.
3827 * @ingroup Images
3828 **/
3829 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight(
3830 OrthancPluginContext* context,
3831 const OrthancPluginImage* image)
3832 {
3833 uint32_t height;
3834
3835 _OrthancPluginGetImageInfo params;
3836 memset(&params, 0, sizeof(params));
3837 params.image = image;
3838 params.resultUint32 = &height;
3839
3840 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, &params) != OrthancPluginErrorCode_Success)
3841 {
3842 return 0;
3843 }
3844 else
3845 {
3846 return height;
3847 }
3848 }
3849
3850
3851
3852 /**
3853 * @brief Return the pitch of an image.
3854 *
3855 * This function returns the pitch of the given image. The pitch is
3856 * defined as the number of bytes between 2 successive lines of the
3857 * image in the memory buffer.
3858 *
3859 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3860 * @param image The image of interest.
3861 * @return The pitch.
3862 * @ingroup Images
3863 **/
3864 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch(
3865 OrthancPluginContext* context,
3866 const OrthancPluginImage* image)
3867 {
3868 uint32_t pitch;
3869
3870 _OrthancPluginGetImageInfo params;
3871 memset(&params, 0, sizeof(params));
3872 params.image = image;
3873 params.resultUint32 = &pitch;
3874
3875 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, &params) != OrthancPluginErrorCode_Success)
3876 {
3877 return 0;
3878 }
3879 else
3880 {
3881 return pitch;
3882 }
3883 }
3884
3885
3886
3887 /**
3888 * @brief Return a pointer to the content of an image.
3889 *
3890 * This function returns a pointer to the memory buffer that
3891 * contains the pixels of the image.
3892 *
3893 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3894 * @param image The image of interest.
3895 * @return The pointer.
3896 * @ingroup Images
3897 **/
3898 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer(
3899 OrthancPluginContext* context,
3900 const OrthancPluginImage* image)
3901 {
3902 void* target = NULL;
3903
3904 _OrthancPluginGetImageInfo params;
3905 memset(&params, 0, sizeof(params));
3906 params.resultBuffer = &target;
3907 params.image = image;
3908
3909 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, &params) != OrthancPluginErrorCode_Success)
3910 {
3911 return NULL;
3912 }
3913 else
3914 {
3915 return target;
3916 }
3917 }
3918
3919
3920 typedef struct
3921 {
3922 OrthancPluginImage** target;
3923 const void* data;
3924 uint32_t size;
3925 OrthancPluginImageFormat format;
3926 } _OrthancPluginUncompressImage;
3927
3928
3929 /**
3930 * @brief Decode a compressed image.
3931 *
3932 * This function decodes a compressed image from a memory buffer.
3933 *
3934 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3935 * @param data Pointer to a memory buffer containing the compressed image.
3936 * @param size Size of the memory buffer containing the compressed image.
3937 * @param format The file format of the compressed image.
3938 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
3939 * @ingroup Images
3940 **/
3941 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage(
3942 OrthancPluginContext* context,
3943 const void* data,
3944 uint32_t size,
3945 OrthancPluginImageFormat format)
3946 {
3947 OrthancPluginImage* target = NULL;
3948
3949 _OrthancPluginUncompressImage params;
3950 memset(&params, 0, sizeof(params));
3951 params.target = &target;
3952 params.data = data;
3953 params.size = size;
3954 params.format = format;
3955
3956 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, &params) != OrthancPluginErrorCode_Success)
3957 {
3958 return NULL;
3959 }
3960 else
3961 {
3962 return target;
3963 }
3964 }
3965
3966
3967
3968
3969 typedef struct
3970 {
3971 OrthancPluginImage* image;
3972 } _OrthancPluginFreeImage;
3973
3974 /**
3975 * @brief Free an image.
3976 *
3977 * This function frees an image that was decoded with OrthancPluginUncompressImage().
3978 *
3979 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3980 * @param image The image.
3981 * @ingroup Images
3982 **/
3983 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage(
3984 OrthancPluginContext* context,
3985 OrthancPluginImage* image)
3986 {
3987 _OrthancPluginFreeImage params;
3988 params.image = image;
3989
3990 context->InvokeService(context, _OrthancPluginService_FreeImage, &params);
3991 }
3992
3993
3994
3995
3996 typedef struct
3997 {
3998 OrthancPluginMemoryBuffer* target;
3999 OrthancPluginImageFormat imageFormat;
4000 OrthancPluginPixelFormat pixelFormat;
4001 uint32_t width;
4002 uint32_t height;
4003 uint32_t pitch;
4004 const void* buffer;
4005 uint8_t quality;
4006 } _OrthancPluginCompressImage;
4007
4008
4009 /**
4010 * @brief Encode a PNG image.
4011 *
4012 * This function compresses the given memory buffer containing an
4013 * image using the PNG specification, and stores the result of the
4014 * compression into a newly allocated memory buffer.
4015 *
4016 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4017 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4018 * @param format The memory layout of the uncompressed image.
4019 * @param width The width of the image.
4020 * @param height The height of the image.
4021 * @param pitch The pitch of the image (i.e. the number of bytes
4022 * between 2 successive lines of the image in the memory buffer).
4023 * @param buffer The memory buffer containing the uncompressed image.
4024 * @return 0 if success, or the error code if failure.
4025 * @see OrthancPluginCompressAndAnswerPngImage()
4026 * @ingroup Images
4027 **/
4028 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage(
4029 OrthancPluginContext* context,
4030 OrthancPluginMemoryBuffer* target,
4031 OrthancPluginPixelFormat format,
4032 uint32_t width,
4033 uint32_t height,
4034 uint32_t pitch,
4035 const void* buffer)
4036 {
4037 _OrthancPluginCompressImage params;
4038 memset(&params, 0, sizeof(params));
4039 params.target = target;
4040 params.imageFormat = OrthancPluginImageFormat_Png;
4041 params.pixelFormat = format;
4042 params.width = width;
4043 params.height = height;
4044 params.pitch = pitch;
4045 params.buffer = buffer;
4046 params.quality = 0; /* Unused for PNG */
4047
4048 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
4049 }
4050
4051
4052 /**
4053 * @brief Encode a JPEG image.
4054 *
4055 * This function compresses the given memory buffer containing an
4056 * image using the JPEG specification, and stores the result of the
4057 * compression into a newly allocated memory buffer.
4058 *
4059 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4060 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4061 * @param format The memory layout of the uncompressed image.
4062 * @param width The width of the image.
4063 * @param height The height of the image.
4064 * @param pitch The pitch of the image (i.e. the number of bytes
4065 * between 2 successive lines of the image in the memory buffer).
4066 * @param buffer The memory buffer containing the uncompressed image.
4067 * @param quality The quality of the JPEG encoding, between 1 (worst
4068 * quality, best compression) and 100 (best quality, worst
4069 * compression).
4070 * @return 0 if success, or the error code if failure.
4071 * @ingroup Images
4072 **/
4073 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage(
4074 OrthancPluginContext* context,
4075 OrthancPluginMemoryBuffer* target,
4076 OrthancPluginPixelFormat format,
4077 uint32_t width,
4078 uint32_t height,
4079 uint32_t pitch,
4080 const void* buffer,
4081 uint8_t quality)
4082 {
4083 _OrthancPluginCompressImage params;
4084 memset(&params, 0, sizeof(params));
4085 params.target = target;
4086 params.imageFormat = OrthancPluginImageFormat_Jpeg;
4087 params.pixelFormat = format;
4088 params.width = width;
4089 params.height = height;
4090 params.pitch = pitch;
4091 params.buffer = buffer;
4092 params.quality = quality;
4093
4094 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
4095 }
4096
4097
4098
4099 /**
4100 * @brief Answer to a REST request with a JPEG image.
4101 *
4102 * This function answers to a REST request with a JPEG image. The
4103 * parameters of this function describe a memory buffer that
4104 * contains an uncompressed image. The image will be automatically compressed
4105 * as a JPEG image by the core system of Orthanc.
4106 *
4107 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4108 * @param output The HTTP connection to the client application.
4109 * @param format The memory layout of the uncompressed image.
4110 * @param width The width of the image.
4111 * @param height The height of the image.
4112 * @param pitch The pitch of the image (i.e. the number of bytes
4113 * between 2 successive lines of the image in the memory buffer).
4114 * @param buffer The memory buffer containing the uncompressed image.
4115 * @param quality The quality of the JPEG encoding, between 1 (worst
4116 * quality, best compression) and 100 (best quality, worst
4117 * compression).
4118 * @ingroup REST
4119 **/
4120 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage(
4121 OrthancPluginContext* context,
4122 OrthancPluginRestOutput* output,
4123 OrthancPluginPixelFormat format,
4124 uint32_t width,
4125 uint32_t height,
4126 uint32_t pitch,
4127 const void* buffer,
4128 uint8_t quality)
4129 {
4130 _OrthancPluginCompressAndAnswerImage params;
4131 params.output = output;
4132 params.imageFormat = OrthancPluginImageFormat_Jpeg;
4133 params.pixelFormat = format;
4134 params.width = width;
4135 params.height = height;
4136 params.pitch = pitch;
4137 params.buffer = buffer;
4138 params.quality = quality;
4139 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
4140 }
4141
4142
4143
4144
4145 typedef struct
4146 {
4147 OrthancPluginMemoryBuffer* target;
4148 OrthancPluginHttpMethod method;
4149 const char* url;
4150 const char* username;
4151 const char* password;
4152 const void* body;
4153 uint32_t bodySize;
4154 } _OrthancPluginCallHttpClient;
4155
4156
4157 /**
4158 * @brief Issue a HTTP GET call.
4159 *
4160 * Make a HTTP GET call to the given URL. The result to the query is
4161 * stored into a newly allocated memory buffer. Favor
4162 * OrthancPluginRestApiGet() if calling the built-in REST API of the
4163 * Orthanc instance that hosts this plugin.
4164 *
4165 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4166 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4167 * @param url The URL of interest.
4168 * @param username The username (can be <tt>NULL</tt> if no password protection).
4169 * @param password The password (can be <tt>NULL</tt> if no password protection).
4170 * @return 0 if success, or the error code if failure.
4171 * @ingroup Toolbox
4172 **/
4173 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet(
4174 OrthancPluginContext* context,
4175 OrthancPluginMemoryBuffer* target,
4176 const char* url,
4177 const char* username,
4178 const char* password)
4179 {
4180 _OrthancPluginCallHttpClient params;
4181 memset(&params, 0, sizeof(params));
4182
4183 params.target = target;
4184 params.method = OrthancPluginHttpMethod_Get;
4185 params.url = url;
4186 params.username = username;
4187 params.password = password;
4188
4189 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4190 }
4191
4192
4193 /**
4194 * @brief Issue a HTTP POST call.
4195 *
4196 * Make a HTTP POST call to the given URL. The result to the query
4197 * is stored into a newly allocated memory buffer. Favor
4198 * OrthancPluginRestApiPost() if calling the built-in REST API of
4199 * the Orthanc instance that hosts this plugin.
4200 *
4201 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4202 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4203 * @param url The URL of interest.
4204 * @param body The content of the body of the request.
4205 * @param bodySize The size of the body of the request.
4206 * @param username The username (can be <tt>NULL</tt> if no password protection).
4207 * @param password The password (can be <tt>NULL</tt> if no password protection).
4208 * @return 0 if success, or the error code if failure.
4209 * @ingroup Toolbox
4210 **/
4211 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost(
4212 OrthancPluginContext* context,
4213 OrthancPluginMemoryBuffer* target,
4214 const char* url,
4215 const void* body,
4216 uint32_t bodySize,
4217 const char* username,
4218 const char* password)
4219 {
4220 _OrthancPluginCallHttpClient params;
4221 memset(&params, 0, sizeof(params));
4222
4223 params.target = target;
4224 params.method = OrthancPluginHttpMethod_Post;
4225 params.url = url;
4226 params.body = body;
4227 params.bodySize = bodySize;
4228 params.username = username;
4229 params.password = password;
4230
4231 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4232 }
4233
4234
4235 /**
4236 * @brief Issue a HTTP PUT call.
4237 *
4238 * Make a HTTP PUT call to the given URL. The result to the query is
4239 * stored into a newly allocated memory buffer. Favor
4240 * OrthancPluginRestApiPut() if calling the built-in REST API of the
4241 * Orthanc instance that hosts this plugin.
4242 *
4243 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4244 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4245 * @param url The URL of interest.
4246 * @param body The content of the body of the request.
4247 * @param bodySize The size of the body of the request.
4248 * @param username The username (can be <tt>NULL</tt> if no password protection).
4249 * @param password The password (can be <tt>NULL</tt> if no password protection).
4250 * @return 0 if success, or the error code if failure.
4251 * @ingroup Toolbox
4252 **/
4253 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut(
4254 OrthancPluginContext* context,
4255 OrthancPluginMemoryBuffer* target,
4256 const char* url,
4257 const void* body,
4258 uint32_t bodySize,
4259 const char* username,
4260 const char* password)
4261 {
4262 _OrthancPluginCallHttpClient params;
4263 memset(&params, 0, sizeof(params));
4264
4265 params.target = target;
4266 params.method = OrthancPluginHttpMethod_Put;
4267 params.url = url;
4268 params.body = body;
4269 params.bodySize = bodySize;
4270 params.username = username;
4271 params.password = password;
4272
4273 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4274 }
4275
4276
4277 /**
4278 * @brief Issue a HTTP DELETE call.
4279 *
4280 * Make a HTTP DELETE call to the given URL. Favor
4281 * OrthancPluginRestApiDelete() if calling the built-in REST API of
4282 * the Orthanc instance that hosts this plugin.
4283 *
4284 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4285 * @param url The URL of interest.
4286 * @param username The username (can be <tt>NULL</tt> if no password protection).
4287 * @param password The password (can be <tt>NULL</tt> if no password protection).
4288 * @return 0 if success, or the error code if failure.
4289 * @ingroup Toolbox
4290 **/
4291 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete(
4292 OrthancPluginContext* context,
4293 const char* url,
4294 const char* username,
4295 const char* password)
4296 {
4297 _OrthancPluginCallHttpClient params;
4298 memset(&params, 0, sizeof(params));
4299
4300 params.method = OrthancPluginHttpMethod_Delete;
4301 params.url = url;
4302 params.username = username;
4303 params.password = password;
4304
4305 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4306 }
4307
4308
4309
4310 typedef struct
4311 {
4312 OrthancPluginImage** target;
4313 const OrthancPluginImage* source;
4314 OrthancPluginPixelFormat targetFormat;
4315 } _OrthancPluginConvertPixelFormat;
4316
4317
4318 /**
4319 * @brief Change the pixel format of an image.
4320 *
4321 * This function creates a new image, changing the memory layout of the pixels.
4322 *
4323 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4324 * @param source The source image.
4325 * @param targetFormat The target pixel format.
4326 * @return The resulting image. It must be freed with OrthancPluginFreeImage().
4327 * @ingroup Images
4328 **/
4329 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat(
4330 OrthancPluginContext* context,
4331 const OrthancPluginImage* source,
4332 OrthancPluginPixelFormat targetFormat)
4333 {
4334 OrthancPluginImage* target = NULL;
4335
4336 _OrthancPluginConvertPixelFormat params;
4337 params.target = &target;
4338 params.source = source;
4339 params.targetFormat = targetFormat;
4340
4341 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, &params) != OrthancPluginErrorCode_Success)
4342 {
4343 return NULL;
4344 }
4345 else
4346 {
4347 return target;
4348 }
4349 }
4350
4351
4352
4353 /**
4354 * @brief Return the number of available fonts.
4355 *
4356 * This function returns the number of fonts that are built in the
4357 * Orthanc core. These fonts can be used to draw texts on images
4358 * through OrthancPluginDrawText().
4359 *
4360 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4361 * @return The number of fonts.
4362 * @ingroup Images
4363 **/
4364 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount(
4365 OrthancPluginContext* context)
4366 {
4367 uint32_t count = 0;
4368
4369 _OrthancPluginReturnSingleValue params;
4370 memset(&params, 0, sizeof(params));
4371 params.resultUint32 = &count;
4372
4373 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, &params) != OrthancPluginErrorCode_Success)
4374 {
4375 /* Error */
4376 return 0;
4377 }
4378 else
4379 {
4380 return count;
4381 }
4382 }
4383
4384
4385
4386
4387 typedef struct
4388 {
4389 uint32_t fontIndex; /* in */
4390 const char** name; /* out */
4391 uint32_t* size; /* out */
4392 } _OrthancPluginGetFontInfo;
4393
4394 /**
4395 * @brief Return the name of a font.
4396 *
4397 * This function returns the name of a font that is built in the Orthanc core.
4398 *
4399 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4400 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4401 * @return The font name. This is a statically-allocated string, do not free it.
4402 * @ingroup Images
4403 **/
4404 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName(
4405 OrthancPluginContext* context,
4406 uint32_t fontIndex)
4407 {
4408 const char* result = NULL;
4409
4410 _OrthancPluginGetFontInfo params;
4411 memset(&params, 0, sizeof(params));
4412 params.name = &result;
4413 params.fontIndex = fontIndex;
4414
4415 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4416 {
4417 return NULL;
4418 }
4419 else
4420 {
4421 return result;
4422 }
4423 }
4424
4425
4426 /**
4427 * @brief Return the size of a font.
4428 *
4429 * This function returns the size of a font that is built in the Orthanc core.
4430 *
4431 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4432 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4433 * @return The font size.
4434 * @ingroup Images
4435 **/
4436 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize(
4437 OrthancPluginContext* context,
4438 uint32_t fontIndex)
4439 {
4440 uint32_t result;
4441
4442 _OrthancPluginGetFontInfo params;
4443 memset(&params, 0, sizeof(params));
4444 params.size = &result;
4445 params.fontIndex = fontIndex;
4446
4447 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4448 {
4449 return 0;
4450 }
4451 else
4452 {
4453 return result;
4454 }
4455 }
4456
4457
4458
4459 typedef struct
4460 {
4461 OrthancPluginImage* image;
4462 uint32_t fontIndex;
4463 const char* utf8Text;
4464 int32_t x;
4465 int32_t y;
4466 uint8_t r;
4467 uint8_t g;
4468 uint8_t b;
4469 } _OrthancPluginDrawText;
4470
4471
4472 /**
4473 * @brief Draw text on an image.
4474 *
4475 * This function draws some text on some image.
4476 *
4477 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4478 * @param image The image upon which to draw the text.
4479 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4480 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string.
4481 * @param x The X position of the text over the image.
4482 * @param y The Y position of the text over the image.
4483 * @param r The value of the red color channel of the text.
4484 * @param g The value of the green color channel of the text.
4485 * @param b The value of the blue color channel of the text.
4486 * @return 0 if success, other value if error.
4487 * @ingroup Images
4488 **/
4489 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText(
4490 OrthancPluginContext* context,
4491 OrthancPluginImage* image,
4492 uint32_t fontIndex,
4493 const char* utf8Text,
4494 int32_t x,
4495 int32_t y,
4496 uint8_t r,
4497 uint8_t g,
4498 uint8_t b)
4499 {
4500 _OrthancPluginDrawText params;
4501 memset(&params, 0, sizeof(params));
4502 params.image = image;
4503 params.fontIndex = fontIndex;
4504 params.utf8Text = utf8Text;
4505 params.x = x;
4506 params.y = y;
4507 params.r = r;
4508 params.g = g;
4509 params.b = b;
4510
4511 return context->InvokeService(context, _OrthancPluginService_DrawText, &params);
4512 }
4513
4514
4515
4516 typedef struct
4517 {
4518 OrthancPluginStorageArea* storageArea;
4519 const char* uuid;
4520 const void* content;
4521 uint64_t size;
4522 OrthancPluginContentType type;
4523 } _OrthancPluginStorageAreaCreate;
4524
4525
4526 /**
4527 * @brief Create a file inside the storage area.
4528 *
4529 * This function creates a new file inside the storage area that is
4530 * currently used by Orthanc.
4531 *
4532 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4533 * @param storageArea The storage area.
4534 * @param uuid The identifier of the file to be created.
4535 * @param content The content to store in the newly created file.
4536 * @param size The size of the content.
4537 * @param type The type of the file content.
4538 * @return 0 if success, other value if error.
4539 * @ingroup Callbacks
4540 **/
4541 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate(
4542 OrthancPluginContext* context,
4543 OrthancPluginStorageArea* storageArea,
4544 const char* uuid,
4545 const void* content,
4546 uint64_t size,
4547 OrthancPluginContentType type)
4548 {
4549 _OrthancPluginStorageAreaCreate params;
4550 params.storageArea = storageArea;
4551 params.uuid = uuid;
4552 params.content = content;
4553 params.size = size;
4554 params.type = type;
4555
4556 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, &params);
4557 }
4558
4559
4560 typedef struct
4561 {
4562 OrthancPluginMemoryBuffer* target;
4563 OrthancPluginStorageArea* storageArea;
4564 const char* uuid;
4565 OrthancPluginContentType type;
4566 } _OrthancPluginStorageAreaRead;
4567
4568
4569 /**
4570 * @brief Read a file from the storage area.
4571 *
4572 * This function reads the content of a given file from the storage
4573 * area that is currently used by Orthanc.
4574 *
4575 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4576 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4577 * @param storageArea The storage area.
4578 * @param uuid The identifier of the file to be read.
4579 * @param type The type of the file content.
4580 * @return 0 if success, other value if error.
4581 * @ingroup Callbacks
4582 **/
4583 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead(
4584 OrthancPluginContext* context,
4585 OrthancPluginMemoryBuffer* target,
4586 OrthancPluginStorageArea* storageArea,
4587 const char* uuid,
4588 OrthancPluginContentType type)
4589 {
4590 _OrthancPluginStorageAreaRead params;
4591 params.target = target;
4592 params.storageArea = storageArea;
4593 params.uuid = uuid;
4594 params.type = type;
4595
4596 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, &params);
4597 }
4598
4599
4600 typedef struct
4601 {
4602 OrthancPluginStorageArea* storageArea;
4603 const char* uuid;
4604 OrthancPluginContentType type;
4605 } _OrthancPluginStorageAreaRemove;
4606
4607 /**
4608 * @brief Remove a file from the storage area.
4609 *
4610 * This function removes a given file from the storage area that is
4611 * currently used by Orthanc.
4612 *
4613 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4614 * @param storageArea The storage area.
4615 * @param uuid The identifier of the file to be removed.
4616 * @param type The type of the file content.
4617 * @return 0 if success, other value if error.
4618 * @ingroup Callbacks
4619 **/
4620 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove(
4621 OrthancPluginContext* context,
4622 OrthancPluginStorageArea* storageArea,
4623 const char* uuid,
4624 OrthancPluginContentType type)
4625 {
4626 _OrthancPluginStorageAreaRemove params;
4627 params.storageArea = storageArea;
4628 params.uuid = uuid;
4629 params.type = type;
4630
4631 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, &params);
4632 }
4633
4634
4635
4636 typedef struct
4637 {
4638 OrthancPluginErrorCode* target;
4639 int32_t code;
4640 uint16_t httpStatus;
4641 const char* message;
4642 } _OrthancPluginRegisterErrorCode;
4643
4644 /**
4645 * @brief Declare a custom error code for this plugin.
4646 *
4647 * This function declares a custom error code that can be generated
4648 * by this plugin. This declaration is used to enrich the body of
4649 * the HTTP answer in the case of an error, and to set the proper
4650 * HTTP status code.
4651 *
4652 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4653 * @param code The error code that is internal to this plugin.
4654 * @param httpStatus The HTTP status corresponding to this error.
4655 * @param message The description of the error.
4656 * @return The error code that has been assigned inside the Orthanc core.
4657 * @ingroup Toolbox
4658 **/
4659 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode(
4660 OrthancPluginContext* context,
4661 int32_t code,
4662 uint16_t httpStatus,
4663 const char* message)
4664 {
4665 OrthancPluginErrorCode target;
4666
4667 _OrthancPluginRegisterErrorCode params;
4668 params.target = &target;
4669 params.code = code;
4670 params.httpStatus = httpStatus;
4671 params.message = message;
4672
4673 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, &params) == OrthancPluginErrorCode_Success)
4674 {
4675 return target;
4676 }
4677 else
4678 {
4679 /* There was an error while assigned the error. Use a generic code. */
4680 return OrthancPluginErrorCode_Plugin;
4681 }
4682 }
4683
4684
4685
4686 typedef struct
4687 {
4688 uint16_t group;
4689 uint16_t element;
4690 OrthancPluginValueRepresentation vr;
4691 const char* name;
4692 uint32_t minMultiplicity;
4693 uint32_t maxMultiplicity;
4694 } _OrthancPluginRegisterDictionaryTag;
4695
4696 /**
4697 * @brief Register a new tag into the DICOM dictionary.
4698 *
4699 * This function declares a new public tag in the dictionary of
4700 * DICOM tags that are known to Orthanc. This function should be
4701 * used in the OrthancPluginInitialize() callback.
4702 *
4703 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4704 * @param group The group of the tag.
4705 * @param element The element of the tag.
4706 * @param vr The value representation of the tag.
4707 * @param name The nickname of the tag.
4708 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4709 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4710 * an arbitrary multiplicity ("<tt>n</tt>").
4711 * @return 0 if success, other value if error.
4712 * @see OrthancPluginRegisterPrivateDictionaryTag()
4713 * @ingroup Toolbox
4714 **/
4715 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag(
4716 OrthancPluginContext* context,
4717 uint16_t group,
4718 uint16_t element,
4719 OrthancPluginValueRepresentation vr,
4720 const char* name,
4721 uint32_t minMultiplicity,
4722 uint32_t maxMultiplicity)
4723 {
4724 _OrthancPluginRegisterDictionaryTag params;
4725 params.group = group;
4726 params.element = element;
4727 params.vr = vr;
4728 params.name = name;
4729 params.minMultiplicity = minMultiplicity;
4730 params.maxMultiplicity = maxMultiplicity;
4731
4732 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, &params);
4733 }
4734
4735
4736
4737 typedef struct
4738 {
4739 uint16_t group;
4740 uint16_t element;
4741 OrthancPluginValueRepresentation vr;
4742 const char* name;
4743 uint32_t minMultiplicity;
4744 uint32_t maxMultiplicity;
4745 const char* privateCreator;
4746 } _OrthancPluginRegisterPrivateDictionaryTag;
4747
4748 /**
4749 * @brief Register a new private tag into the DICOM dictionary.
4750 *
4751 * This function declares a new private tag in the dictionary of
4752 * DICOM tags that are known to Orthanc. This function should be
4753 * used in the OrthancPluginInitialize() callback.
4754 *
4755 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4756 * @param group The group of the tag.
4757 * @param element The element of the tag.
4758 * @param vr The value representation of the tag.
4759 * @param name The nickname of the tag.
4760 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4761 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4762 * an arbitrary multiplicity ("<tt>n</tt>").
4763 * @param privateCreator The private creator of this private tag.
4764 * @return 0 if success, other value if error.
4765 * @see OrthancPluginRegisterDictionaryTag()
4766 * @ingroup Toolbox
4767 **/
4768 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag(
4769 OrthancPluginContext* context,
4770 uint16_t group,
4771 uint16_t element,
4772 OrthancPluginValueRepresentation vr,
4773 const char* name,
4774 uint32_t minMultiplicity,
4775 uint32_t maxMultiplicity,
4776 const char* privateCreator)
4777 {
4778 _OrthancPluginRegisterPrivateDictionaryTag params;
4779 params.group = group;
4780 params.element = element;
4781 params.vr = vr;
4782 params.name = name;
4783 params.minMultiplicity = minMultiplicity;
4784 params.maxMultiplicity = maxMultiplicity;
4785 params.privateCreator = privateCreator;
4786
4787 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, &params);
4788 }
4789
4790
4791
4792 typedef struct
4793 {
4794 OrthancPluginStorageArea* storageArea;
4795 OrthancPluginResourceType level;
4796 } _OrthancPluginReconstructMainDicomTags;
4797
4798 /**
4799 * @brief Reconstruct the main DICOM tags.
4800 *
4801 * This function requests the Orthanc core to reconstruct the main
4802 * DICOM tags of all the resources of the given type. This function
4803 * can only be used as a part of the upgrade of a custom database
4804 * back-end. A database transaction will be automatically setup.
4805 *
4806 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4807 * @param storageArea The storage area.
4808 * @param level The type of the resources of interest.
4809 * @return 0 if success, other value if error.
4810 * @ingroup Callbacks
4811 **/
4812 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags(
4813 OrthancPluginContext* context,
4814 OrthancPluginStorageArea* storageArea,
4815 OrthancPluginResourceType level)
4816 {
4817 _OrthancPluginReconstructMainDicomTags params;
4818 params.level = level;
4819 params.storageArea = storageArea;
4820
4821 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, &params);
4822 }
4823
4824
4825 typedef struct
4826 {
4827 char** result;
4828 const char* instanceId;
4829 const void* buffer;
4830 uint32_t size;
4831 OrthancPluginDicomToJsonFormat format;
4832 OrthancPluginDicomToJsonFlags flags;
4833 uint32_t maxStringLength;
4834 } _OrthancPluginDicomToJson;
4835
4836
4837 /**
4838 * @brief Format a DICOM memory buffer as a JSON string.
4839 *
4840 * This function takes as input a memory buffer containing a DICOM
4841 * file, and outputs a JSON string representing the tags of this
4842 * DICOM file.
4843 *
4844 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4845 * @param buffer The memory buffer containing the DICOM file.
4846 * @param size The size of the memory buffer.
4847 * @param format The output format.
4848 * @param flags Flags governing the output.
4849 * @param maxStringLength The maximum length of a field. Too long fields will
4850 * be output as "null". The 0 value means no maximum length.
4851 * @return The NULL value if the case of an error, or the JSON
4852 * string. This string must be freed by OrthancPluginFreeString().
4853 * @ingroup Toolbox
4854 * @see OrthancPluginDicomInstanceToJson
4855 **/
4856 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson(
4857 OrthancPluginContext* context,
4858 const void* buffer,
4859 uint32_t size,
4860 OrthancPluginDicomToJsonFormat format,
4861 OrthancPluginDicomToJsonFlags flags,
4862 uint32_t maxStringLength)
4863 {
4864 char* result;
4865
4866 _OrthancPluginDicomToJson params;
4867 memset(&params, 0, sizeof(params));
4868 params.result = &result;
4869 params.buffer = buffer;
4870 params.size = size;
4871 params.format = format;
4872 params.flags = flags;
4873 params.maxStringLength = maxStringLength;
4874
4875 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, &params) != OrthancPluginErrorCode_Success)
4876 {
4877 /* Error */
4878 return NULL;
4879 }
4880 else
4881 {
4882 return result;
4883 }
4884 }
4885
4886
4887 /**
4888 * @brief Format a DICOM instance as a JSON string.
4889 *
4890 * This function formats a DICOM instance that is stored in Orthanc,
4891 * and outputs a JSON string representing the tags of this DICOM
4892 * instance.
4893 *
4894 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4895 * @param instanceId The Orthanc identifier of the instance.
4896 * @param format The output format.
4897 * @param flags Flags governing the output.
4898 * @param maxStringLength The maximum length of a field. Too long fields will
4899 * be output as "null". The 0 value means no maximum length.
4900 * @return The NULL value if the case of an error, or the JSON
4901 * string. This string must be freed by OrthancPluginFreeString().
4902 * @ingroup Toolbox
4903 * @see OrthancPluginDicomInstanceToJson
4904 **/
4905 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson(
4906 OrthancPluginContext* context,
4907 const char* instanceId,
4908 OrthancPluginDicomToJsonFormat format,
4909 OrthancPluginDicomToJsonFlags flags,
4910 uint32_t maxStringLength)
4911 {
4912 char* result;
4913
4914 _OrthancPluginDicomToJson params;
4915 memset(&params, 0, sizeof(params));
4916 params.result = &result;
4917 params.instanceId = instanceId;
4918 params.format = format;
4919 params.flags = flags;
4920 params.maxStringLength = maxStringLength;
4921
4922 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, &params) != OrthancPluginErrorCode_Success)
4923 {
4924 /* Error */
4925 return NULL;
4926 }
4927 else
4928 {
4929 return result;
4930 }
4931 }
4932
4933
4934 typedef struct
4935 {
4936 OrthancPluginMemoryBuffer* target;
4937 const char* uri;
4938 uint32_t headersCount;
4939 const char* const* headersKeys;
4940 const char* const* headersValues;
4941 int32_t afterPlugins;
4942 } _OrthancPluginRestApiGet2;
4943
4944 /**
4945 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers.
4946 *
4947 * Make a GET call to the Orthanc REST API with extended
4948 * parameters. The result to the query is stored into a newly
4949 * allocated memory buffer.
4950 *
4951 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4952 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4953 * @param uri The URI in the built-in Orthanc API.
4954 * @param headersCount The number of HTTP headers.
4955 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
4956 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
4957 * @param afterPlugins If 0, the built-in API of Orthanc is used.
4958 * If 1, the API is tainted by the plugins.
4959 * @return 0 if success, or the error code if failure.
4960 * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins
4961 * @ingroup Orthanc
4962 **/
4963 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2(
4964 OrthancPluginContext* context,
4965 OrthancPluginMemoryBuffer* target,
4966 const char* uri,
4967 uint32_t headersCount,
4968 const char* const* headersKeys,
4969 const char* const* headersValues,
4970 int32_t afterPlugins)
4971 {
4972 _OrthancPluginRestApiGet2 params;
4973 params.target = target;
4974 params.uri = uri;
4975 params.headersCount = headersCount;
4976 params.headersKeys = headersKeys;
4977 params.headersValues = headersValues;
4978 params.afterPlugins = afterPlugins;
4979
4980 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, &params);
4981 }
4982
4983
4984
4985 typedef struct
4986 {
4987 OrthancPluginWorklistCallback callback;
4988 } _OrthancPluginWorklistCallback;
4989
4990 /**
4991 * @brief Register a callback to handle modality worklists requests.
4992 *
4993 * This function registers a callback to handle C-Find SCP requests
4994 * on modality worklists.
4995 *
4996 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4997 * @param callback The callback.
4998 * @return 0 if success, other value if error.
4999 * @ingroup DicomCallbacks
5000 **/
5001 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback(
5002 OrthancPluginContext* context,
5003 OrthancPluginWorklistCallback callback)
5004 {
5005 _OrthancPluginWorklistCallback params;
5006 params.callback = callback;
5007
5008 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, &params);
5009 }
5010
5011
5012
5013 typedef struct
5014 {
5015 OrthancPluginWorklistAnswers* answers;
5016 const OrthancPluginWorklistQuery* query;
5017 const void* dicom;
5018 uint32_t size;
5019 } _OrthancPluginWorklistAnswersOperation;
5020
5021 /**
5022 * @brief Add one answer to some modality worklist request.
5023 *
5024 * This function adds one worklist (encoded as a DICOM file) to the
5025 * set of answers corresponding to some C-Find SCP request against
5026 * modality worklists.
5027 *
5028 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5029 * @param answers The set of answers.
5030 * @param query The worklist query, as received by the callback.
5031 * @param dicom The worklist to answer, encoded as a DICOM file.
5032 * @param size The size of the DICOM file.
5033 * @return 0 if success, other value if error.
5034 * @ingroup DicomCallbacks
5035 * @see OrthancPluginCreateDicom()
5036 **/
5037 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer(
5038 OrthancPluginContext* context,
5039 OrthancPluginWorklistAnswers* answers,
5040 const OrthancPluginWorklistQuery* query,
5041 const void* dicom,
5042 uint32_t size)
5043 {
5044 _OrthancPluginWorklistAnswersOperation params;
5045 params.answers = answers;
5046 params.query = query;
5047 params.dicom = dicom;
5048 params.size = size;
5049
5050 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, &params);
5051 }
5052
5053
5054 /**
5055 * @brief Mark the set of worklist answers as incomplete.
5056 *
5057 * This function marks as incomplete the set of answers
5058 * corresponding to some C-Find SCP request against modality
5059 * worklists. This must be used if canceling the handling of a
5060 * request when too many answers are to be returned.
5061 *
5062 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5063 * @param answers The set of answers.
5064 * @return 0 if success, other value if error.
5065 * @ingroup DicomCallbacks
5066 **/
5067 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete(
5068 OrthancPluginContext* context,
5069 OrthancPluginWorklistAnswers* answers)
5070 {
5071 _OrthancPluginWorklistAnswersOperation params;
5072 params.answers = answers;
5073 params.query = NULL;
5074 params.dicom = NULL;
5075 params.size = 0;
5076
5077 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, &params);
5078 }
5079
5080
5081 typedef struct
5082 {
5083 const OrthancPluginWorklistQuery* query;
5084 const void* dicom;
5085 uint32_t size;
5086 int32_t* isMatch;
5087 OrthancPluginMemoryBuffer* target;
5088 } _OrthancPluginWorklistQueryOperation;
5089
5090 /**
5091 * @brief Test whether a worklist matches the query.
5092 *
5093 * This function checks whether one worklist (encoded as a DICOM
5094 * file) matches the C-Find SCP query against modality
5095 * worklists. This function must be called before adding the
5096 * worklist as an answer through OrthancPluginWorklistAddAnswer().
5097 *
5098 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5099 * @param query The worklist query, as received by the callback.
5100 * @param dicom The worklist to answer, encoded as a DICOM file.
5101 * @param size The size of the DICOM file.
5102 * @return 1 if the worklist matches the query, 0 otherwise.
5103 * @ingroup DicomCallbacks
5104 **/
5105 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch(
5106 OrthancPluginContext* context,
5107 const OrthancPluginWorklistQuery* query,
5108 const void* dicom,
5109 uint32_t size)
5110 {
5111 int32_t isMatch = 0;
5112
5113 _OrthancPluginWorklistQueryOperation params;
5114 params.query = query;
5115 params.dicom = dicom;
5116 params.size = size;
5117 params.isMatch = &isMatch;
5118 params.target = NULL;
5119
5120 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, &params) == OrthancPluginErrorCode_Success)
5121 {
5122 return isMatch;
5123 }
5124 else
5125 {
5126 /* Error: Assume non-match */
5127 return 0;
5128 }
5129 }
5130
5131
5132 /**
5133 * @brief Retrieve the worklist query as a DICOM file.
5134 *
5135 * This function retrieves the DICOM file that underlies a C-Find
5136 * SCP query against modality worklists.
5137 *
5138 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5139 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer().
5140 * @param query The worklist query, as received by the callback.
5141 * @return 0 if success, other value if error.
5142 * @ingroup DicomCallbacks
5143 **/
5144 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery(
5145 OrthancPluginContext* context,
5146 OrthancPluginMemoryBuffer* target,
5147 const OrthancPluginWorklistQuery* query)
5148 {
5149 _OrthancPluginWorklistQueryOperation params;
5150 params.query = query;
5151 params.dicom = NULL;
5152 params.size = 0;
5153 params.isMatch = NULL;
5154 params.target = target;
5155
5156 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, &params);
5157 }
5158
5159
5160 /**
5161 * @brief Get the origin of a DICOM file.
5162 *
5163 * This function returns the origin of a DICOM instance that has been received by Orthanc.
5164 *
5165 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5166 * @param instance The instance of interest.
5167 * @return The origin of the instance.
5168 * @ingroup DicomInstance
5169 **/
5170 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin(
5171 OrthancPluginContext* context,
5172 const OrthancPluginDicomInstance* instance)
5173 {
5174 OrthancPluginInstanceOrigin origin;
5175
5176 _OrthancPluginAccessDicomInstance params;
5177 memset(&params, 0, sizeof(params));
5178 params.resultOrigin = &origin;
5179 params.instance = instance;
5180
5181 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, &params) != OrthancPluginErrorCode_Success)
5182 {
5183 /* Error */
5184 return OrthancPluginInstanceOrigin_Unknown;
5185 }
5186 else
5187 {
5188 return origin;
5189 }
5190 }
5191
5192
5193 typedef struct
5194 {
5195 OrthancPluginMemoryBuffer* target;
5196 const char* json;
5197 const OrthancPluginImage* pixelData;
5198 OrthancPluginCreateDicomFlags flags;
5199 } _OrthancPluginCreateDicom;
5200
5201 /**
5202 * @brief Create a DICOM instance from a JSON string and an image.
5203 *
5204 * This function takes as input a string containing a JSON file
5205 * describing the content of a DICOM instance. As an output, it
5206 * writes the corresponding DICOM instance to a newly allocated
5207 * memory buffer. Additionally, an image to be encoded within the
5208 * DICOM instance can also be provided.
5209 *
5210 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5211 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
5212 * @param json The input JSON file.
5213 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.
5214 * @param flags Flags governing the output.
5215 * @return 0 if success, other value if error.
5216 * @ingroup Toolbox
5217 * @see OrthancPluginDicomBufferToJson
5218 **/
5219 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom(
5220 OrthancPluginContext* context,
5221 OrthancPluginMemoryBuffer* target,
5222 const char* json,
5223 const OrthancPluginImage* pixelData,
5224 OrthancPluginCreateDicomFlags flags)
5225 {
5226 _OrthancPluginCreateDicom params;
5227 params.target = target;
5228 params.json = json;
5229 params.pixelData = pixelData;
5230 params.flags = flags;
5231
5232 return context->InvokeService(context, _OrthancPluginService_CreateDicom, &params);
5233 }
5234
5235
5236 typedef struct
5237 {
5238 OrthancPluginDecodeImageCallback callback;
5239 } _OrthancPluginDecodeImageCallback;
5240
5241 /**
5242 * @brief Register a callback to handle the decoding of DICOM images.
5243 *
5244 * This function registers a custom callback to decode DICOM images,
5245 * extending the built-in decoder of Orthanc that uses
5246 * DCMTK. Starting with Orthanc 1.7.0, the exact behavior is
5247 * affected by the configuration option
5248 * "BuiltinDecoderTranscoderOrder" of Orthanc.
5249 *
5250 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5251 * @param callback The callback.
5252 * @return 0 if success, other value if error.
5253 * @ingroup Callbacks
5254 **/
5255 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback(
5256 OrthancPluginContext* context,
5257 OrthancPluginDecodeImageCallback callback)
5258 {
5259 _OrthancPluginDecodeImageCallback params;
5260 params.callback = callback;
5261
5262 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, &params);
5263 }
5264
5265
5266
5267 typedef struct
5268 {
5269 OrthancPluginImage** target;
5270 OrthancPluginPixelFormat format;
5271 uint32_t width;
5272 uint32_t height;
5273 uint32_t pitch;
5274 void* buffer;
5275 const void* constBuffer;
5276 uint32_t bufferSize;
5277 uint32_t frameIndex;
5278 } _OrthancPluginCreateImage;
5279
5280
5281 /**
5282 * @brief Create an image.
5283 *
5284 * This function creates an image of given size and format.
5285 *
5286 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5287 * @param format The format of the pixels.
5288 * @param width The width of the image.
5289 * @param height The height of the image.
5290 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5291 * @ingroup Images
5292 **/
5293 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage(
5294 OrthancPluginContext* context,
5295 OrthancPluginPixelFormat format,
5296 uint32_t width,
5297 uint32_t height)
5298 {
5299 OrthancPluginImage* target = NULL;
5300
5301 _OrthancPluginCreateImage params;
5302 memset(&params, 0, sizeof(params));
5303 params.target = &target;
5304 params.format = format;
5305 params.width = width;
5306 params.height = height;
5307
5308 if (context->InvokeService(context, _OrthancPluginService_CreateImage, &params) != OrthancPluginErrorCode_Success)
5309 {
5310 return NULL;
5311 }
5312 else
5313 {
5314 return target;
5315 }
5316 }
5317
5318
5319 /**
5320 * @brief Create an image pointing to a memory buffer.
5321 *
5322 * This function creates an image whose content points to a memory
5323 * buffer managed by the plugin. Note that the buffer is directly
5324 * accessed, no memory is allocated and no data is copied.
5325 *
5326 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5327 * @param format The format of the pixels.
5328 * @param width The width of the image.
5329 * @param height The height of the image.
5330 * @param pitch The pitch of the image (i.e. the number of bytes
5331 * between 2 successive lines of the image in the memory buffer).
5332 * @param buffer The memory buffer.
5333 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5334 * @ingroup Images
5335 **/
5336 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor(
5337 OrthancPluginContext* context,
5338 OrthancPluginPixelFormat format,
5339 uint32_t width,
5340 uint32_t height,
5341 uint32_t pitch,
5342 void* buffer)
5343 {
5344 OrthancPluginImage* target = NULL;
5345
5346 _OrthancPluginCreateImage params;
5347 memset(&params, 0, sizeof(params));
5348 params.target = &target;
5349 params.format = format;
5350 params.width = width;
5351 params.height = height;
5352 params.pitch = pitch;
5353 params.buffer = buffer;
5354
5355 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, &params) != OrthancPluginErrorCode_Success)
5356 {
5357 return NULL;
5358 }
5359 else
5360 {
5361 return target;
5362 }
5363 }
5364
5365
5366
5367 /**
5368 * @brief Decode one frame from a DICOM instance.
5369 *
5370 * This function decodes one frame of a DICOM image that is stored
5371 * in a memory buffer. This function will give the same result as
5372 * OrthancPluginUncompressImage() for single-frame DICOM images.
5373 *
5374 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5375 * @param buffer Pointer to a memory buffer containing the DICOM image.
5376 * @param bufferSize Size of the memory buffer containing the DICOM image.
5377 * @param frameIndex The index of the frame of interest in a multi-frame image.
5378 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
5379 * @ingroup Images
5380 * @see OrthancPluginGetInstanceDecodedFrame()
5381 **/
5382 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage(
5383 OrthancPluginContext* context,
5384 const void* buffer,
5385 uint32_t bufferSize,
5386 uint32_t frameIndex)
5387 {
5388 OrthancPluginImage* target = NULL;
5389
5390 _OrthancPluginCreateImage params;
5391 memset(&params, 0, sizeof(params));
5392 params.target = &target;
5393 params.constBuffer = buffer;
5394 params.bufferSize = bufferSize;
5395 params.frameIndex = frameIndex;
5396
5397 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, &params) != OrthancPluginErrorCode_Success)
5398 {
5399 return NULL;
5400 }
5401 else
5402 {
5403 return target;
5404 }
5405 }
5406
5407
5408
5409 typedef struct
5410 {
5411 char** result;
5412 const void* buffer;
5413 uint32_t size;
5414 } _OrthancPluginComputeHash;
5415
5416 /**
5417 * @brief Compute an MD5 hash.
5418 *
5419 * This functions computes the MD5 cryptographic hash of the given memory buffer.
5420 *
5421 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5422 * @param buffer The source memory buffer.
5423 * @param size The size in bytes of the source buffer.
5424 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5425 * This string must be freed by OrthancPluginFreeString().
5426 * @ingroup Toolbox
5427 **/
5428 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5(
5429 OrthancPluginContext* context,
5430 const void* buffer,
5431 uint32_t size)
5432 {
5433 char* result;
5434
5435 _OrthancPluginComputeHash params;
5436 params.result = &result;
5437 params.buffer = buffer;
5438 params.size = size;
5439
5440 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, &params) != OrthancPluginErrorCode_Success)
5441 {
5442 /* Error */
5443 return NULL;
5444 }
5445 else
5446 {
5447 return result;
5448 }
5449 }
5450
5451
5452 /**
5453 * @brief Compute a SHA-1 hash.
5454 *
5455 * This functions computes the SHA-1 cryptographic hash of the given memory buffer.
5456 *
5457 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5458 * @param buffer The source memory buffer.
5459 * @param size The size in bytes of the source buffer.
5460 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5461 * This string must be freed by OrthancPluginFreeString().
5462 * @ingroup Toolbox
5463 **/
5464 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1(
5465 OrthancPluginContext* context,
5466 const void* buffer,
5467 uint32_t size)
5468 {
5469 char* result;
5470
5471 _OrthancPluginComputeHash params;
5472 params.result = &result;
5473 params.buffer = buffer;
5474 params.size = size;
5475
5476 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, &params) != OrthancPluginErrorCode_Success)
5477 {
5478 /* Error */
5479 return NULL;
5480 }
5481 else
5482 {
5483 return result;
5484 }
5485 }
5486
5487
5488
5489 typedef struct
5490 {
5491 OrthancPluginDictionaryEntry* target;
5492 const char* name;
5493 } _OrthancPluginLookupDictionary;
5494
5495 /**
5496 * @brief Get information about the given DICOM tag.
5497 *
5498 * This functions makes a lookup in the dictionary of DICOM tags
5499 * that are known to Orthanc, and returns information about this
5500 * tag. The tag can be specified using its human-readable name
5501 * (e.g. "PatientName") or a set of two hexadecimal numbers
5502 * (e.g. "0010-0020").
5503 *
5504 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5505 * @param target Where to store the information about the tag.
5506 * @param name The name of the DICOM tag.
5507 * @return 0 if success, other value if error.
5508 * @ingroup Toolbox
5509 **/
5510 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary(
5511 OrthancPluginContext* context,
5512 OrthancPluginDictionaryEntry* target,
5513 const char* name)
5514 {
5515 _OrthancPluginLookupDictionary params;
5516 params.target = target;
5517 params.name = name;
5518 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, &params);
5519 }
5520
5521
5522
5523 typedef struct
5524 {
5525 OrthancPluginRestOutput* output;
5526 const char* answer;
5527 uint32_t answerSize;
5528 uint32_t headersCount;
5529 const char* const* headersKeys;
5530 const char* const* headersValues;
5531 } _OrthancPluginSendMultipartItem2;
5532
5533 /**
5534 * @brief Send an item as a part of some HTTP multipart answer, with custom headers.
5535 *
5536 * This function sends an item as a part of some HTTP multipart
5537 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to
5538 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated
5539 * with the item.
5540 *
5541 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5542 * @param output The HTTP connection to the client application.
5543 * @param answer Pointer to the memory buffer containing the item.
5544 * @param answerSize Number of bytes of the item.
5545 * @param headersCount The number of HTTP headers.
5546 * @param headersKeys Array containing the keys of the HTTP headers.
5547 * @param headersValues Array containing the values of the HTTP headers.
5548 * @return 0 if success, or the error code if failure (this notably happens
5549 * if the connection is closed by the client).
5550 * @see OrthancPluginSendMultipartItem()
5551 * @ingroup REST
5552 **/
5553 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2(
5554 OrthancPluginContext* context,
5555 OrthancPluginRestOutput* output,
5556 const char* answer,
5557 uint32_t answerSize,
5558 uint32_t headersCount,
5559 const char* const* headersKeys,
5560 const char* const* headersValues)
5561 {
5562 _OrthancPluginSendMultipartItem2 params;
5563 params.output = output;
5564 params.answer = answer;
5565 params.answerSize = answerSize;
5566 params.headersCount = headersCount;
5567 params.headersKeys = headersKeys;
5568 params.headersValues = headersValues;
5569
5570 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, &params);
5571 }
5572
5573
5574 typedef struct
5575 {
5576 OrthancPluginIncomingHttpRequestFilter callback;
5577 } _OrthancPluginIncomingHttpRequestFilter;
5578
5579 /**
5580 * @brief Register a callback to filter incoming HTTP requests.
5581 *
5582 * This function registers a custom callback to filter incoming HTTP/REST
5583 * requests received by the HTTP server of Orthanc.
5584 *
5585 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5586 * @param callback The callback.
5587 * @return 0 if success, other value if error.
5588 * @ingroup Callbacks
5589 * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2()
5590 **/
5591 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter(
5592 OrthancPluginContext* context,
5593 OrthancPluginIncomingHttpRequestFilter callback)
5594 {
5595 _OrthancPluginIncomingHttpRequestFilter params;
5596 params.callback = callback;
5597
5598 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, &params);
5599 }
5600
5601
5602
5603 typedef struct
5604 {
5605 OrthancPluginMemoryBuffer* answerBody;
5606 OrthancPluginMemoryBuffer* answerHeaders;
5607 uint16_t* httpStatus;
5608 OrthancPluginHttpMethod method;
5609 const char* url;
5610 uint32_t headersCount;
5611 const char* const* headersKeys;
5612 const char* const* headersValues;
5613 const void* body;
5614 uint32_t bodySize;
5615 const char* username;
5616 const char* password;
5617 uint32_t timeout;
5618 const char* certificateFile;
5619 const char* certificateKeyFile;
5620 const char* certificateKeyPassword;
5621 uint8_t pkcs11;
5622 } _OrthancPluginCallHttpClient2;
5623
5624
5625
5626 /**
5627 * @brief Issue a HTTP call with full flexibility.
5628 *
5629 * Make a HTTP call to the given URL. The result to the query is
5630 * stored into a newly allocated memory buffer. The HTTP request
5631 * will be done accordingly to the global configuration of Orthanc
5632 * (in particular, the options "HttpProxy", "HttpTimeout",
5633 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be
5634 * taken into account).
5635 *
5636 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5637 * @param answerBody The target memory buffer (out argument).
5638 * It must be freed with OrthancPluginFreeMemoryBuffer().
5639 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
5640 * The answer headers are formatted as a JSON object (associative array).
5641 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
5642 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
5643 * @param httpStatus The HTTP status after the execution of the request (out argument).
5644 * @param method HTTP method to be used.
5645 * @param url The URL of interest.
5646 * @param headersCount The number of HTTP headers.
5647 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
5648 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
5649 * @param username The username (can be <tt>NULL</tt> if no password protection).
5650 * @param password The password (can be <tt>NULL</tt> if no password protection).
5651 * @param body The HTTP body for a POST or PUT request.
5652 * @param bodySize The size of the body.
5653 * @param timeout Timeout in seconds (0 for default timeout).
5654 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
5655 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5656 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
5657 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5658 * @param certificateKeyPassword Password to unlock the key of the client certificate
5659 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5660 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
5661 * @return 0 if success, or the error code if failure.
5662 * @see OrthancPluginCallPeerApi()
5663 * @ingroup Toolbox
5664 **/
5665 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient(
5666 OrthancPluginContext* context,
5667 OrthancPluginMemoryBuffer* answerBody,
5668 OrthancPluginMemoryBuffer* answerHeaders,
5669 uint16_t* httpStatus,
5670 OrthancPluginHttpMethod method,
5671 const char* url,
5672 uint32_t headersCount,
5673 const char* const* headersKeys,
5674 const char* const* headersValues,
5675 const void* body,
5676 uint32_t bodySize,
5677 const char* username,
5678 const char* password,
5679 uint32_t timeout,
5680 const char* certificateFile,
5681 const char* certificateKeyFile,
5682 const char* certificateKeyPassword,
5683 uint8_t pkcs11)
5684 {
5685 _OrthancPluginCallHttpClient2 params;
5686 memset(&params, 0, sizeof(params));
5687
5688 params.answerBody = answerBody;
5689 params.answerHeaders = answerHeaders;
5690 params.httpStatus = httpStatus;
5691 params.method = method;
5692 params.url = url;
5693 params.headersCount = headersCount;
5694 params.headersKeys = headersKeys;
5695 params.headersValues = headersValues;
5696 params.body = body;
5697 params.bodySize = bodySize;
5698 params.username = username;
5699 params.password = password;
5700 params.timeout = timeout;
5701 params.certificateFile = certificateFile;
5702 params.certificateKeyFile = certificateKeyFile;
5703 params.certificateKeyPassword = certificateKeyPassword;
5704 params.pkcs11 = pkcs11;
5705
5706 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, &params);
5707 }
5708
5709
5710 /**
5711 * @brief Generate an UUID.
5712 *
5713 * Generate a random GUID/UUID (globally unique identifier).
5714 *
5715 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5716 * @return NULL in the case of an error, or a newly allocated string
5717 * containing the UUID. This string must be freed by OrthancPluginFreeString().
5718 * @ingroup Toolbox
5719 **/
5720 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid(
5721 OrthancPluginContext* context)
5722 {
5723 char* result;
5724
5725 _OrthancPluginRetrieveDynamicString params;
5726 params.result = &result;
5727 params.argument = NULL;
5728
5729 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, &params) != OrthancPluginErrorCode_Success)
5730 {
5731 /* Error */
5732 return NULL;
5733 }
5734 else
5735 {
5736 return result;
5737 }
5738 }
5739
5740
5741
5742
5743 typedef struct
5744 {
5745 OrthancPluginFindCallback callback;
5746 } _OrthancPluginFindCallback;
5747
5748 /**
5749 * @brief Register a callback to handle C-Find requests.
5750 *
5751 * This function registers a callback to handle C-Find SCP requests
5752 * that are not related to modality worklists.
5753 *
5754 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5755 * @param callback The callback.
5756 * @return 0 if success, other value if error.
5757 * @ingroup DicomCallbacks
5758 **/
5759 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback(
5760 OrthancPluginContext* context,
5761 OrthancPluginFindCallback callback)
5762 {
5763 _OrthancPluginFindCallback params;
5764 params.callback = callback;
5765
5766 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, &params);
5767 }
5768
5769
5770 typedef struct
5771 {
5772 OrthancPluginFindAnswers *answers;
5773 const OrthancPluginFindQuery *query;
5774 const void *dicom;
5775 uint32_t size;
5776 uint32_t index;
5777 uint32_t *resultUint32;
5778 uint16_t *resultGroup;
5779 uint16_t *resultElement;
5780 char **resultString;
5781 } _OrthancPluginFindOperation;
5782
5783 /**
5784 * @brief Add one answer to some C-Find request.
5785 *
5786 * This function adds one answer (encoded as a DICOM file) to the
5787 * set of answers corresponding to some C-Find SCP request that is
5788 * not related to modality worklists.
5789 *
5790 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5791 * @param answers The set of answers.
5792 * @param dicom The answer to be added, encoded as a DICOM file.
5793 * @param size The size of the DICOM file.
5794 * @return 0 if success, other value if error.
5795 * @ingroup DicomCallbacks
5796 * @see OrthancPluginCreateDicom()
5797 **/
5798 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer(
5799 OrthancPluginContext* context,
5800 OrthancPluginFindAnswers* answers,
5801 const void* dicom,
5802 uint32_t size)
5803 {
5804 _OrthancPluginFindOperation params;
5805 memset(&params, 0, sizeof(params));
5806 params.answers = answers;
5807 params.dicom = dicom;
5808 params.size = size;
5809
5810 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, &params);
5811 }
5812
5813
5814 /**
5815 * @brief Mark the set of C-Find answers as incomplete.
5816 *
5817 * This function marks as incomplete the set of answers
5818 * corresponding to some C-Find SCP request that is not related to
5819 * modality worklists. This must be used if canceling the handling
5820 * of a request when too many answers are to be returned.
5821 *
5822 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5823 * @param answers The set of answers.
5824 * @return 0 if success, other value if error.
5825 * @ingroup DicomCallbacks
5826 **/
5827 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete(
5828 OrthancPluginContext* context,
5829 OrthancPluginFindAnswers* answers)
5830 {
5831 _OrthancPluginFindOperation params;
5832 memset(&params, 0, sizeof(params));
5833 params.answers = answers;
5834
5835 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, &params);
5836 }
5837
5838
5839
5840 /**
5841 * @brief Get the number of tags in a C-Find query.
5842 *
5843 * This function returns the number of tags that are contained in
5844 * the given C-Find query.
5845 *
5846 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5847 * @param query The C-Find query.
5848 * @return The number of tags.
5849 * @ingroup DicomCallbacks
5850 **/
5851 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize(
5852 OrthancPluginContext* context,
5853 const OrthancPluginFindQuery* query)
5854 {
5855 uint32_t count = 0;
5856
5857 _OrthancPluginFindOperation params;
5858 memset(&params, 0, sizeof(params));
5859 params.query = query;
5860 params.resultUint32 = &count;
5861
5862 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, &params) != OrthancPluginErrorCode_Success)
5863 {
5864 /* Error */
5865 return 0;
5866 }
5867 else
5868 {
5869 return count;
5870 }
5871 }
5872
5873
5874 /**
5875 * @brief Get one tag in a C-Find query.
5876 *
5877 * This function returns the group and the element of one DICOM tag
5878 * in the given C-Find query.
5879 *
5880 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5881 * @param group The group of the tag (output).
5882 * @param element The element of the tag (output).
5883 * @param query The C-Find query.
5884 * @param index The index of the tag of interest.
5885 * @return 0 if success, other value if error.
5886 * @ingroup DicomCallbacks
5887 **/
5888 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag(
5889 OrthancPluginContext* context,
5890 uint16_t* group,
5891 uint16_t* element,
5892 const OrthancPluginFindQuery* query,
5893 uint32_t index)
5894 {
5895 _OrthancPluginFindOperation params;
5896 memset(&params, 0, sizeof(params));
5897 params.query = query;
5898 params.index = index;
5899 params.resultGroup = group;
5900 params.resultElement = element;
5901
5902 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, &params);
5903 }
5904
5905
5906 /**
5907 * @brief Get the symbolic name of one tag in a C-Find query.
5908 *
5909 * This function returns the symbolic name of one DICOM tag in the
5910 * given C-Find query.
5911 *
5912 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5913 * @param query The C-Find query.
5914 * @param index The index of the tag of interest.
5915 * @return The NULL value in case of error, or a string containing the name of the tag.
5916 * @return 0 if success, other value if error.
5917 * @ingroup DicomCallbacks
5918 **/
5919 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName(
5920 OrthancPluginContext* context,
5921 const OrthancPluginFindQuery* query,
5922 uint32_t index)
5923 {
5924 char* result;
5925
5926 _OrthancPluginFindOperation params;
5927 memset(&params, 0, sizeof(params));
5928 params.query = query;
5929 params.index = index;
5930 params.resultString = &result;
5931
5932 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, &params) != OrthancPluginErrorCode_Success)
5933 {
5934 /* Error */
5935 return NULL;
5936 }
5937 else
5938 {
5939 return result;
5940 }
5941 }
5942
5943
5944 /**
5945 * @brief Get the value associated with one tag in a C-Find query.
5946 *
5947 * This function returns the value associated with one tag in the
5948 * given C-Find query.
5949 *
5950 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5951 * @param query The C-Find query.
5952 * @param index The index of the tag of interest.
5953 * @return The NULL value in case of error, or a string containing the value of the tag.
5954 * @return 0 if success, other value if error.
5955 * @ingroup DicomCallbacks
5956 **/
5957 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue(
5958 OrthancPluginContext* context,
5959 const OrthancPluginFindQuery* query,
5960 uint32_t index)
5961 {
5962 char* result;
5963
5964 _OrthancPluginFindOperation params;
5965 memset(&params, 0, sizeof(params));
5966 params.query = query;
5967 params.index = index;
5968 params.resultString = &result;
5969
5970 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, &params) != OrthancPluginErrorCode_Success)
5971 {
5972 /* Error */
5973 return NULL;
5974 }
5975 else
5976 {
5977 return result;
5978 }
5979 }
5980
5981
5982
5983
5984 typedef struct
5985 {
5986 OrthancPluginMoveCallback callback;
5987 OrthancPluginGetMoveSize getMoveSize;
5988 OrthancPluginApplyMove applyMove;
5989 OrthancPluginFreeMove freeMove;
5990 } _OrthancPluginMoveCallback;
5991
5992 /**
5993 * @brief Register a callback to handle C-Move requests.
5994 *
5995 * This function registers a callback to handle C-Move SCP requests.
5996 *
5997 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5998 * @param callback The main callback.
5999 * @param getMoveSize Callback to read the number of C-Move suboperations.
6000 * @param applyMove Callback to apply one C-Move suboperation.
6001 * @param freeMove Callback to free the C-Move driver.
6002 * @return 0 if success, other value if error.
6003 * @ingroup DicomCallbacks
6004 **/
6005 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback(
6006 OrthancPluginContext* context,
6007 OrthancPluginMoveCallback callback,
6008 OrthancPluginGetMoveSize getMoveSize,
6009 OrthancPluginApplyMove applyMove,
6010 OrthancPluginFreeMove freeMove)
6011 {
6012 _OrthancPluginMoveCallback params;
6013 params.callback = callback;
6014 params.getMoveSize = getMoveSize;
6015 params.applyMove = applyMove;
6016 params.freeMove = freeMove;
6017
6018 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, &params);
6019 }
6020
6021
6022
6023 typedef struct
6024 {
6025 OrthancPluginFindMatcher** target;
6026 const void* query;
6027 uint32_t size;
6028 } _OrthancPluginCreateFindMatcher;
6029
6030
6031 /**
6032 * @brief Create a C-Find matcher.
6033 *
6034 * This function creates a "matcher" object that can be used to
6035 * check whether a DICOM instance matches a C-Find query. The C-Find
6036 * query must be expressed as a DICOM buffer.
6037 *
6038 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6039 * @param query The C-Find DICOM query.
6040 * @param size The size of the DICOM query.
6041 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher().
6042 * @ingroup Toolbox
6043 **/
6044 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher(
6045 OrthancPluginContext* context,
6046 const void* query,
6047 uint32_t size)
6048 {
6049 OrthancPluginFindMatcher* target = NULL;
6050
6051 _OrthancPluginCreateFindMatcher params;
6052 memset(&params, 0, sizeof(params));
6053 params.target = &target;
6054 params.query = query;
6055 params.size = size;
6056
6057 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, &params) != OrthancPluginErrorCode_Success)
6058 {
6059 return NULL;
6060 }
6061 else
6062 {
6063 return target;
6064 }
6065 }
6066
6067
6068 typedef struct
6069 {
6070 OrthancPluginFindMatcher* matcher;
6071 } _OrthancPluginFreeFindMatcher;
6072
6073 /**
6074 * @brief Free a C-Find matcher.
6075 *
6076 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher().
6077 *
6078 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6079 * @param matcher The matcher of interest.
6080 * @ingroup Toolbox
6081 **/
6082 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher(
6083 OrthancPluginContext* context,
6084 OrthancPluginFindMatcher* matcher)
6085 {
6086 _OrthancPluginFreeFindMatcher params;
6087 params.matcher = matcher;
6088
6089 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, &params);
6090 }
6091
6092
6093 typedef struct
6094 {
6095 const OrthancPluginFindMatcher* matcher;
6096 const void* dicom;
6097 uint32_t size;
6098 int32_t* isMatch;
6099 } _OrthancPluginFindMatcherIsMatch;
6100
6101 /**
6102 * @brief Test whether a DICOM instance matches a C-Find query.
6103 *
6104 * This function checks whether one DICOM instance matches C-Find
6105 * matcher that was previously allocated using
6106 * OrthancPluginCreateFindMatcher().
6107 *
6108 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6109 * @param matcher The matcher of interest.
6110 * @param dicom The DICOM instance to be matched.
6111 * @param size The size of the DICOM instance.
6112 * @return 1 if the DICOM instance matches the query, 0 otherwise.
6113 * @ingroup Toolbox
6114 **/
6115 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch(
6116 OrthancPluginContext* context,
6117 const OrthancPluginFindMatcher* matcher,
6118 const void* dicom,
6119 uint32_t size)
6120 {
6121 int32_t isMatch = 0;
6122
6123 _OrthancPluginFindMatcherIsMatch params;
6124 params.matcher = matcher;
6125 params.dicom = dicom;
6126 params.size = size;
6127 params.isMatch = &isMatch;
6128
6129 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, &params) == OrthancPluginErrorCode_Success)
6130 {
6131 return isMatch;
6132 }
6133 else
6134 {
6135 /* Error: Assume non-match */
6136 return 0;
6137 }
6138 }
6139
6140
6141 typedef struct
6142 {
6143 OrthancPluginIncomingHttpRequestFilter2 callback;
6144 } _OrthancPluginIncomingHttpRequestFilter2;
6145
6146 /**
6147 * @brief Register a callback to filter incoming HTTP requests.
6148 *
6149 * This function registers a custom callback to filter incoming HTTP/REST
6150 * requests received by the HTTP server of Orthanc.
6151 *
6152 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6153 * @param callback The callback.
6154 * @return 0 if success, other value if error.
6155 * @ingroup Callbacks
6156 **/
6157 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter2(
6158 OrthancPluginContext* context,
6159 OrthancPluginIncomingHttpRequestFilter2 callback)
6160 {
6161 _OrthancPluginIncomingHttpRequestFilter2 params;
6162 params.callback = callback;
6163
6164 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, &params);
6165 }
6166
6167
6168
6169 typedef struct
6170 {
6171 OrthancPluginPeers** peers;
6172 } _OrthancPluginGetPeers;
6173
6174 /**
6175 * @brief Return the list of available Orthanc peers.
6176 *
6177 * This function returns the parameters of the Orthanc peers that are known to
6178 * the Orthanc server hosting the plugin.
6179 *
6180 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6181 * @return NULL if error, or a newly allocated opaque data structure containing the peers.
6182 * This structure must be freed with OrthancPluginFreePeers().
6183 * @ingroup Toolbox
6184 **/
6185 ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers(
6186 OrthancPluginContext* context)
6187 {
6188 OrthancPluginPeers* peers = NULL;
6189
6190 _OrthancPluginGetPeers params;
6191 memset(&params, 0, sizeof(params));
6192 params.peers = &peers;
6193
6194 if (context->InvokeService(context, _OrthancPluginService_GetPeers, &params) != OrthancPluginErrorCode_Success)
6195 {
6196 return NULL;
6197 }
6198 else
6199 {
6200 return peers;
6201 }
6202 }
6203
6204
6205 typedef struct
6206 {
6207 OrthancPluginPeers* peers;
6208 } _OrthancPluginFreePeers;
6209
6210 /**
6211 * @brief Free the list of available Orthanc peers.
6212 *
6213 * This function frees the data structure returned by OrthancPluginGetPeers().
6214 *
6215 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6216 * @param peers The data structure describing the Orthanc peers.
6217 * @ingroup Toolbox
6218 **/
6219 ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers(
6220 OrthancPluginContext* context,
6221 OrthancPluginPeers* peers)
6222 {
6223 _OrthancPluginFreePeers params;
6224 params.peers = peers;
6225
6226 context->InvokeService(context, _OrthancPluginService_FreePeers, &params);
6227 }
6228
6229
6230 typedef struct
6231 {
6232 uint32_t* target;
6233 const OrthancPluginPeers* peers;
6234 } _OrthancPluginGetPeersCount;
6235
6236 /**
6237 * @brief Get the number of Orthanc peers.
6238 *
6239 * This function returns the number of Orthanc peers.
6240 *
6241 * This function is thread-safe: Several threads sharing the same
6242 * OrthancPluginPeers object can simultaneously call this function.
6243 *
6244 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6245 * @param peers The data structure describing the Orthanc peers.
6246 * @result The number of peers.
6247 * @ingroup Toolbox
6248 **/
6249 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount(
6250 OrthancPluginContext* context,
6251 const OrthancPluginPeers* peers)
6252 {
6253 uint32_t target = 0;
6254
6255 _OrthancPluginGetPeersCount params;
6256 memset(&params, 0, sizeof(params));
6257 params.target = &target;
6258 params.peers = peers;
6259
6260 if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, &params) != OrthancPluginErrorCode_Success)
6261 {
6262 /* Error */
6263 return 0;
6264 }
6265 else
6266 {
6267 return target;
6268 }
6269 }
6270
6271
6272 typedef struct
6273 {
6274 const char** target;
6275 const OrthancPluginPeers* peers;
6276 uint32_t peerIndex;
6277 const char* userProperty;
6278 } _OrthancPluginGetPeerProperty;
6279
6280 /**
6281 * @brief Get the symbolic name of an Orthanc peer.
6282 *
6283 * This function returns the symbolic name of the Orthanc peer,
6284 * which corresponds to the key of the "OrthancPeers" configuration
6285 * option of Orthanc.
6286 *
6287 * This function is thread-safe: Several threads sharing the same
6288 * OrthancPluginPeers object can simultaneously call this function.
6289 *
6290 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6291 * @param peers The data structure describing the Orthanc peers.
6292 * @param peerIndex The index of the peer of interest.
6293 * This value must be lower than OrthancPluginGetPeersCount().
6294 * @result The symbolic name, or NULL in the case of an error.
6295 * @ingroup Toolbox
6296 **/
6297 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName(
6298 OrthancPluginContext* context,
6299 const OrthancPluginPeers* peers,
6300 uint32_t peerIndex)
6301 {
6302 const char* target = NULL;
6303
6304 _OrthancPluginGetPeerProperty params;
6305 memset(&params, 0, sizeof(params));
6306 params.target = &target;
6307 params.peers = peers;
6308 params.peerIndex = peerIndex;
6309 params.userProperty = NULL;
6310
6311 if (context->InvokeService(context, _OrthancPluginService_GetPeerName, &params) != OrthancPluginErrorCode_Success)
6312 {
6313 /* Error */
6314 return NULL;
6315 }
6316 else
6317 {
6318 return target;
6319 }
6320 }
6321
6322
6323 /**
6324 * @brief Get the base URL of an Orthanc peer.
6325 *
6326 * This function returns the base URL to the REST API of some Orthanc peer.
6327 *
6328 * This function is thread-safe: Several threads sharing the same
6329 * OrthancPluginPeers object can simultaneously call this function.
6330 *
6331 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6332 * @param peers The data structure describing the Orthanc peers.
6333 * @param peerIndex The index of the peer of interest.
6334 * This value must be lower than OrthancPluginGetPeersCount().
6335 * @result The URL, or NULL in the case of an error.
6336 * @ingroup Toolbox
6337 **/
6338 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl(
6339 OrthancPluginContext* context,
6340 const OrthancPluginPeers* peers,
6341 uint32_t peerIndex)
6342 {
6343 const char* target = NULL;
6344
6345 _OrthancPluginGetPeerProperty params;
6346 memset(&params, 0, sizeof(params));
6347 params.target = &target;
6348 params.peers = peers;
6349 params.peerIndex = peerIndex;
6350 params.userProperty = NULL;
6351
6352 if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, &params) != OrthancPluginErrorCode_Success)
6353 {
6354 /* Error */
6355 return NULL;
6356 }
6357 else
6358 {
6359 return target;
6360 }
6361 }
6362
6363
6364
6365 /**
6366 * @brief Get some user-defined property of an Orthanc peer.
6367 *
6368 * This function returns some user-defined property of some Orthanc
6369 * peer. An user-defined property is a property that is associated
6370 * with the peer in the Orthanc configuration file, but that is not
6371 * recognized by the Orthanc core.
6372 *
6373 * This function is thread-safe: Several threads sharing the same
6374 * OrthancPluginPeers object can simultaneously call this function.
6375 *
6376 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6377 * @param peers The data structure describing the Orthanc peers.
6378 * @param peerIndex The index of the peer of interest.
6379 * This value must be lower than OrthancPluginGetPeersCount().
6380 * @param userProperty The user property of interest.
6381 * @result The value of the user property, or NULL if it is not defined.
6382 * @ingroup Toolbox
6383 **/
6384 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty(
6385 OrthancPluginContext* context,
6386 const OrthancPluginPeers* peers,
6387 uint32_t peerIndex,
6388 const char* userProperty)
6389 {
6390 const char* target = NULL;
6391
6392 _OrthancPluginGetPeerProperty params;
6393 memset(&params, 0, sizeof(params));
6394 params.target = &target;
6395 params.peers = peers;
6396 params.peerIndex = peerIndex;
6397 params.userProperty = userProperty;
6398
6399 if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, &params) != OrthancPluginErrorCode_Success)
6400 {
6401 /* No such user property */
6402 return NULL;
6403 }
6404 else
6405 {
6406 return target;
6407 }
6408 }
6409
6410
6411
6412 typedef struct
6413 {
6414 OrthancPluginMemoryBuffer* answerBody;
6415 OrthancPluginMemoryBuffer* answerHeaders;
6416 uint16_t* httpStatus;
6417 const OrthancPluginPeers* peers;
6418 uint32_t peerIndex;
6419 OrthancPluginHttpMethod method;
6420 const char* uri;
6421 uint32_t additionalHeadersCount;
6422 const char* const* additionalHeadersKeys;
6423 const char* const* additionalHeadersValues;
6424 const void* body;
6425 uint32_t bodySize;
6426 uint32_t timeout;
6427 } _OrthancPluginCallPeerApi;
6428
6429 /**
6430 * @brief Call the REST API of an Orthanc peer.
6431 *
6432 * Make a REST call to the given URI in the REST API of a remote
6433 * Orthanc peer. The result to the query is stored into a newly
6434 * allocated memory buffer. The HTTP request will be done according
6435 * to the "OrthancPeers" configuration option of Orthanc.
6436 *
6437 * This function is thread-safe: Several threads sharing the same
6438 * OrthancPluginPeers object can simultaneously call this function.
6439 *
6440 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6441 * @param answerBody The target memory buffer (out argument).
6442 * It must be freed with OrthancPluginFreeMemoryBuffer().
6443 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
6444 * The answer headers are formatted as a JSON object (associative array).
6445 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
6446 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
6447 * @param httpStatus The HTTP status after the execution of the request (out argument).
6448 * @param peers The data structure describing the Orthanc peers.
6449 * @param peerIndex The index of the peer of interest.
6450 * This value must be lower than OrthancPluginGetPeersCount().
6451 * @param method HTTP method to be used.
6452 * @param uri The URI of interest in the REST API.
6453 * @param additionalHeadersCount The number of HTTP headers to be added to the
6454 * HTTP headers provided in the global configuration of Orthanc.
6455 * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
6456 * @param additionalHeadersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
6457 * @param body The HTTP body for a POST or PUT request.
6458 * @param bodySize The size of the body.
6459 * @param timeout Timeout in seconds (0 for default timeout).
6460 * @return 0 if success, or the error code if failure.
6461 * @see OrthancPluginHttpClient()
6462 * @ingroup Toolbox
6463 **/
6464 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi(
6465 OrthancPluginContext* context,
6466 OrthancPluginMemoryBuffer* answerBody,
6467 OrthancPluginMemoryBuffer* answerHeaders,
6468 uint16_t* httpStatus,
6469 const OrthancPluginPeers* peers,
6470 uint32_t peerIndex,
6471 OrthancPluginHttpMethod method,
6472 const char* uri,
6473 uint32_t additionalHeadersCount,
6474 const char* const* additionalHeadersKeys,
6475 const char* const* additionalHeadersValues,
6476 const void* body,
6477 uint32_t bodySize,
6478 uint32_t timeout)
6479 {
6480 _OrthancPluginCallPeerApi params;
6481 memset(&params, 0, sizeof(params));
6482
6483 params.answerBody = answerBody;
6484 params.answerHeaders = answerHeaders;
6485 params.httpStatus = httpStatus;
6486 params.peers = peers;
6487 params.peerIndex = peerIndex;
6488 params.method = method;
6489 params.uri = uri;
6490 params.additionalHeadersCount = additionalHeadersCount;
6491 params.additionalHeadersKeys = additionalHeadersKeys;
6492 params.additionalHeadersValues = additionalHeadersValues;
6493 params.body = body;
6494 params.bodySize = bodySize;
6495 params.timeout = timeout;
6496
6497 return context->InvokeService(context, _OrthancPluginService_CallPeerApi, &params);
6498 }
6499
6500
6501
6502
6503
6504 typedef struct
6505 {
6506 OrthancPluginJob** target;
6507 void *job;
6508 OrthancPluginJobFinalize finalize;
6509 const char *type;
6510 OrthancPluginJobGetProgress getProgress;
6511 OrthancPluginJobGetContent getContent;
6512 OrthancPluginJobGetSerialized getSerialized;
6513 OrthancPluginJobStep step;
6514 OrthancPluginJobStop stop;
6515 OrthancPluginJobReset reset;
6516 } _OrthancPluginCreateJob;
6517
6518 /**
6519 * @brief Create a custom job.
6520 *
6521 * This function creates a custom job to be run by the jobs engine
6522 * of Orthanc.
6523 *
6524 * Orthanc starts one dedicated thread per custom job that is
6525 * running. It is guaranteed that all the callbacks will only be
6526 * called from this single dedicated thread, in mutual exclusion: As
6527 * a consequence, it is *not* mandatory to protect the various
6528 * callbacks by mutexes.
6529 *
6530 * The custom job can nonetheless launch its own processing threads
6531 * on the first call to the "step()" callback, and stop them once
6532 * the "stop()" callback is called.
6533 *
6534 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6535 * @param job The job to be executed.
6536 * @param finalize The finalization callback.
6537 * @param type The type of the job, provided to the job unserializer.
6538 * See OrthancPluginRegisterJobsUnserializer().
6539 * @param getProgress The progress callback.
6540 * @param getContent The content callback.
6541 * @param getSerialized The serialization callback.
6542 * @param step The callback to execute the individual steps of the job.
6543 * @param stop The callback that is invoked once the job leaves the "running" state.
6544 * @param reset The callback that is invoked if a stopped job is started again.
6545 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(),
6546 * as long as it is not submitted with OrthancPluginSubmitJob().
6547 * @ingroup Toolbox
6548 **/
6549 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob(
6550 OrthancPluginContext *context,
6551 void *job,
6552 OrthancPluginJobFinalize finalize,
6553 const char *type,
6554 OrthancPluginJobGetProgress getProgress,
6555 OrthancPluginJobGetContent getContent,
6556 OrthancPluginJobGetSerialized getSerialized,
6557 OrthancPluginJobStep step,
6558 OrthancPluginJobStop stop,
6559 OrthancPluginJobReset reset)
6560 {
6561 OrthancPluginJob* target = NULL;
6562
6563 _OrthancPluginCreateJob params;
6564 memset(&params, 0, sizeof(params));
6565
6566 params.target = &target;
6567 params.job = job;
6568 params.finalize = finalize;
6569 params.type = type;
6570 params.getProgress = getProgress;
6571 params.getContent = getContent;
6572 params.getSerialized = getSerialized;
6573 params.step = step;
6574 params.stop = stop;
6575 params.reset = reset;
6576
6577 if (context->InvokeService(context, _OrthancPluginService_CreateJob, &params) != OrthancPluginErrorCode_Success ||
6578 target == NULL)
6579 {
6580 /* Error */
6581 return NULL;
6582 }
6583 else
6584 {
6585 return target;
6586 }
6587 }
6588
6589
6590 typedef struct
6591 {
6592 OrthancPluginJob* job;
6593 } _OrthancPluginFreeJob;
6594
6595 /**
6596 * @brief Free a custom job.
6597 *
6598 * This function frees an image that was created with OrthancPluginCreateJob().
6599 *
6600 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6601 * @param job The job.
6602 * @ingroup Toolbox
6603 **/
6604 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob(
6605 OrthancPluginContext* context,
6606 OrthancPluginJob* job)
6607 {
6608 _OrthancPluginFreeJob params;
6609 params.job = job;
6610
6611 context->InvokeService(context, _OrthancPluginService_FreeJob, &params);
6612 }
6613
6614
6615
6616 typedef struct
6617 {
6618 char** resultId;
6619 OrthancPluginJob *job;
6620 int priority;
6621 } _OrthancPluginSubmitJob;
6622
6623 /**
6624 * @brief Submit a new job to the jobs engine of Orthanc.
6625 *
6626 * This function adds the given job to the pending jobs of
6627 * Orthanc. Orthanc will take take of freeing it by invoking the
6628 * finalization callback provided to OrthancPluginCreateJob().
6629 *
6630 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6631 * @param job The job, as received by OrthancPluginCreateJob().
6632 * @param priority The priority of the job.
6633 * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString().
6634 * @ingroup Toolbox
6635 **/
6636 ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob(
6637 OrthancPluginContext *context,
6638 OrthancPluginJob *job,
6639 int priority)
6640 {
6641 char* resultId = NULL;
6642
6643 _OrthancPluginSubmitJob params;
6644 memset(&params, 0, sizeof(params));
6645
6646 params.resultId = &resultId;
6647 params.job = job;
6648 params.priority = priority;
6649
6650 if (context->InvokeService(context, _OrthancPluginService_SubmitJob, &params) != OrthancPluginErrorCode_Success ||
6651 resultId == NULL)
6652 {
6653 /* Error */
6654 return NULL;
6655 }
6656 else
6657 {
6658 return resultId;
6659 }
6660 }
6661
6662
6663
6664 typedef struct
6665 {
6666 OrthancPluginJobsUnserializer unserializer;
6667 } _OrthancPluginJobsUnserializer;
6668
6669 /**
6670 * @brief Register an unserializer for custom jobs.
6671 *
6672 * This function registers an unserializer that decodes custom jobs
6673 * from a JSON string. This callback is invoked when the jobs engine
6674 * of Orthanc is started (on Orthanc initialization), for each job
6675 * that is stored in the Orthanc database.
6676 *
6677 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6678 * @param unserializer The job unserializer.
6679 * @ingroup Callbacks
6680 **/
6681 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer(
6682 OrthancPluginContext* context,
6683 OrthancPluginJobsUnserializer unserializer)
6684 {
6685 _OrthancPluginJobsUnserializer params;
6686 params.unserializer = unserializer;
6687
6688 context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, &params);
6689 }
6690
6691
6692
6693 typedef struct
6694 {
6695 OrthancPluginRestOutput* output;
6696 const char* details;
6697 uint8_t log;
6698 } _OrthancPluginSetHttpErrorDetails;
6699
6700 /**
6701 * @brief Provide a detailed description for an HTTP error.
6702 *
6703 * This function sets the detailed description associated with an
6704 * HTTP error. This description will be displayed in the "Details"
6705 * field of the JSON body of the HTTP answer. It is only taken into
6706 * consideration if the REST callback returns an error code that is
6707 * different from "OrthancPluginErrorCode_Success", and if the
6708 * "HttpDescribeErrors" configuration option of Orthanc is set to
6709 * "true".
6710 *
6711 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6712 * @param output The HTTP connection to the client application.
6713 * @param details The details of the error message.
6714 * @param log Whether to also write the detailed error to the Orthanc logs.
6715 * @ingroup REST
6716 **/
6717 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails(
6718 OrthancPluginContext* context,
6719 OrthancPluginRestOutput* output,
6720 const char* details,
6721 uint8_t log)
6722 {
6723 _OrthancPluginSetHttpErrorDetails params;
6724 params.output = output;
6725 params.details = details;
6726 params.log = log;
6727 context->InvokeService(context, _OrthancPluginService_SetHttpErrorDetails, &params);
6728 }
6729
6730
6731
6732 typedef struct
6733 {
6734 const char** result;
6735 const char* argument;
6736 } _OrthancPluginRetrieveStaticString;
6737
6738 /**
6739 * @brief Detect the MIME type of a file.
6740 *
6741 * This function returns the MIME type of a file by inspecting its extension.
6742 *
6743 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6744 * @param path Path to the file.
6745 * @return The MIME type. This is a statically-allocated
6746 * string, do not free it.
6747 * @ingroup Toolbox
6748 **/
6749 ORTHANC_PLUGIN_INLINE const char* OrthancPluginAutodetectMimeType(
6750 OrthancPluginContext* context,
6751 const char* path)
6752 {
6753 const char* result = NULL;
6754
6755 _OrthancPluginRetrieveStaticString params;
6756 params.result = &result;
6757 params.argument = path;
6758
6759 if (context->InvokeService(context, _OrthancPluginService_AutodetectMimeType, &params) != OrthancPluginErrorCode_Success)
6760 {
6761 /* Error */
6762 return NULL;
6763 }
6764 else
6765 {
6766 return result;
6767 }
6768 }
6769
6770
6771
6772 typedef struct
6773 {
6774 const char* name;
6775 float value;
6776 OrthancPluginMetricsType type;
6777 } _OrthancPluginSetMetricsValue;
6778
6779 /**
6780 * @brief Set the value of a metrics.
6781 *
6782 * This function sets the value of a metrics to monitor the behavior
6783 * of the plugin through tools such as Prometheus. The values of all
6784 * the metrics are stored within the Orthanc context.
6785 *
6786 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6787 * @param name The name of the metrics to be set.
6788 * @param value The value of the metrics.
6789 * @param type The type of the metrics. This parameter is only taken into consideration
6790 * the first time this metrics is set.
6791 * @ingroup Toolbox
6792 **/
6793 ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsValue(
6794 OrthancPluginContext* context,
6795 const char* name,
6796 float value,
6797 OrthancPluginMetricsType type)
6798 {
6799 _OrthancPluginSetMetricsValue params;
6800 params.name = name;
6801 params.value = value;
6802 params.type = type;
6803 context->InvokeService(context, _OrthancPluginService_SetMetricsValue, &params);
6804 }
6805
6806
6807
6808 typedef struct
6809 {
6810 OrthancPluginRefreshMetricsCallback callback;
6811 } _OrthancPluginRegisterRefreshMetricsCallback;
6812
6813 /**
6814 * @brief Register a callback to refresh the metrics.
6815 *
6816 * This function registers a callback to refresh the metrics. The
6817 * callback must make calls to OrthancPluginSetMetricsValue().
6818 *
6819 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6820 * @param callback The callback function to handle the refresh.
6821 * @ingroup Callbacks
6822 **/
6823 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRefreshMetricsCallback(
6824 OrthancPluginContext* context,
6825 OrthancPluginRefreshMetricsCallback callback)
6826 {
6827 _OrthancPluginRegisterRefreshMetricsCallback params;
6828 params.callback = callback;
6829 context->InvokeService(context, _OrthancPluginService_RegisterRefreshMetricsCallback, &params);
6830 }
6831
6832
6833
6834
6835 typedef struct
6836 {
6837 char** target;
6838 const void* dicom;
6839 uint32_t dicomSize;
6840 OrthancPluginDicomWebBinaryCallback callback;
6841 } _OrthancPluginEncodeDicomWeb;
6842
6843 /**
6844 * @brief Convert a DICOM instance to DICOMweb JSON.
6845 *
6846 * This function converts a memory buffer containing a DICOM instance,
6847 * into its DICOMweb JSON representation.
6848 *
6849 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6850 * @param dicom Pointer to the DICOM instance.
6851 * @param dicomSize Size of the DICOM instance.
6852 * @param callback Callback to set the value of the binary tags.
6853 * @see OrthancPluginCreateDicom()
6854 * @return The NULL value in case of error, or the JSON document. This string must
6855 * be freed by OrthancPluginFreeString().
6856 * @deprecated OrthancPluginEncodeDicomWebJson2()
6857 * @ingroup Toolbox
6858 **/
6859 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson(
6860 OrthancPluginContext* context,
6861 const void* dicom,
6862 uint32_t dicomSize,
6863 OrthancPluginDicomWebBinaryCallback callback)
6864 {
6865 char* target = NULL;
6866
6867 _OrthancPluginEncodeDicomWeb params;
6868 params.target = &target;
6869 params.dicom = dicom;
6870 params.dicomSize = dicomSize;
6871 params.callback = callback;
6872
6873 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson, &params) != OrthancPluginErrorCode_Success)
6874 {
6875 /* Error */
6876 return NULL;
6877 }
6878 else
6879 {
6880 return target;
6881 }
6882 }
6883
6884
6885 /**
6886 * @brief Convert a DICOM instance to DICOMweb XML.
6887 *
6888 * This function converts a memory buffer containing a DICOM instance,
6889 * into its DICOMweb XML representation.
6890 *
6891 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6892 * @param dicom Pointer to the DICOM instance.
6893 * @param dicomSize Size of the DICOM instance.
6894 * @param callback Callback to set the value of the binary tags.
6895 * @return The NULL value in case of error, or the XML document. This string must
6896 * be freed by OrthancPluginFreeString().
6897 * @see OrthancPluginCreateDicom()
6898 * @deprecated OrthancPluginEncodeDicomWebXml2()
6899 * @ingroup Toolbox
6900 **/
6901 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml(
6902 OrthancPluginContext* context,
6903 const void* dicom,
6904 uint32_t dicomSize,
6905 OrthancPluginDicomWebBinaryCallback callback)
6906 {
6907 char* target = NULL;
6908
6909 _OrthancPluginEncodeDicomWeb params;
6910 params.target = &target;
6911 params.dicom = dicom;
6912 params.dicomSize = dicomSize;
6913 params.callback = callback;
6914
6915 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml, &params) != OrthancPluginErrorCode_Success)
6916 {
6917 /* Error */
6918 return NULL;
6919 }
6920 else
6921 {
6922 return target;
6923 }
6924 }
6925
6926
6927
6928 typedef struct
6929 {
6930 char** target;
6931 const void* dicom;
6932 uint32_t dicomSize;
6933 OrthancPluginDicomWebBinaryCallback2 callback;
6934 void* payload;
6935 } _OrthancPluginEncodeDicomWeb2;
6936
6937 /**
6938 * @brief Convert a DICOM instance to DICOMweb JSON.
6939 *
6940 * This function converts a memory buffer containing a DICOM instance,
6941 * into its DICOMweb JSON representation.
6942 *
6943 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6944 * @param dicom Pointer to the DICOM instance.
6945 * @param dicomSize Size of the DICOM instance.
6946 * @param callback Callback to set the value of the binary tags.
6947 * @param payload User payload.
6948 * @return The NULL value in case of error, or the JSON document. This string must
6949 * be freed by OrthancPluginFreeString().
6950 * @see OrthancPluginCreateDicom()
6951 * @ingroup Toolbox
6952 **/
6953 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson2(
6954 OrthancPluginContext* context,
6955 const void* dicom,
6956 uint32_t dicomSize,
6957 OrthancPluginDicomWebBinaryCallback2 callback,
6958 void* payload)
6959 {
6960 char* target = NULL;
6961
6962 _OrthancPluginEncodeDicomWeb2 params;
6963 params.target = &target;
6964 params.dicom = dicom;
6965 params.dicomSize = dicomSize;
6966 params.callback = callback;
6967 params.payload = payload;
6968
6969 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson2, &params) != OrthancPluginErrorCode_Success)
6970 {
6971 /* Error */
6972 return NULL;
6973 }
6974 else
6975 {
6976 return target;
6977 }
6978 }
6979
6980
6981 /**
6982 * @brief Convert a DICOM instance to DICOMweb XML.
6983 *
6984 * This function converts a memory buffer containing a DICOM instance,
6985 * into its DICOMweb XML representation.
6986 *
6987 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6988 * @param dicom Pointer to the DICOM instance.
6989 * @param dicomSize Size of the DICOM instance.
6990 * @param callback Callback to set the value of the binary tags.
6991 * @param payload User payload.
6992 * @return The NULL value in case of error, or the XML document. This string must
6993 * be freed by OrthancPluginFreeString().
6994 * @see OrthancPluginCreateDicom()
6995 * @ingroup Toolbox
6996 **/
6997 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml2(
6998 OrthancPluginContext* context,
6999 const void* dicom,
7000 uint32_t dicomSize,
7001 OrthancPluginDicomWebBinaryCallback2 callback,
7002 void* payload)
7003 {
7004 char* target = NULL;
7005
7006 _OrthancPluginEncodeDicomWeb2 params;
7007 params.target = &target;
7008 params.dicom = dicom;
7009 params.dicomSize = dicomSize;
7010 params.callback = callback;
7011 params.payload = payload;
7012
7013 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml2, &params) != OrthancPluginErrorCode_Success)
7014 {
7015 /* Error */
7016 return NULL;
7017 }
7018 else
7019 {
7020 return target;
7021 }
7022 }
7023
7024
7025
7026 /**
7027 * @brief Callback executed when a HTTP header is received during a chunked transfer.
7028 *
7029 * Signature of a callback function that is called by Orthanc acting
7030 * as a HTTP client during a chunked HTTP transfer, as soon as it
7031 * receives one HTTP header from the answer of the remote HTTP
7032 * server.
7033 *
7034 * @see OrthancPluginChunkedHttpClient()
7035 * @param answer The user payload, as provided by the calling plugin.
7036 * @param key The key of the HTTP header.
7037 * @param value The value of the HTTP header.
7038 * @return 0 if success, or the error code if failure.
7039 * @ingroup Toolbox
7040 **/
7041 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddHeader) (
7042 void* answer,
7043 const char* key,
7044 const char* value);
7045
7046
7047 /**
7048 * @brief Callback executed when an answer chunk is received during a chunked transfer.
7049 *
7050 * Signature of a callback function that is called by Orthanc acting
7051 * as a HTTP client during a chunked HTTP transfer, as soon as it
7052 * receives one data chunk from the answer of the remote HTTP
7053 * server.
7054 *
7055 * @see OrthancPluginChunkedHttpClient()
7056 * @param answer The user payload, as provided by the calling plugin.
7057 * @param data The content of the data chunk.
7058 * @param size The size of the data chunk.
7059 * @return 0 if success, or the error code if failure.
7060 * @ingroup Toolbox
7061 **/
7062 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddChunk) (
7063 void* answer,
7064 const void* data,
7065 uint32_t size);
7066
7067
7068 /**
7069 * @brief Callback to know whether the request body is entirely read during a chunked transfer
7070 *
7071 * Signature of a callback function that is called by Orthanc acting
7072 * as a HTTP client during a chunked HTTP transfer, while reading
7073 * the body of a POST or PUT request. The plugin must answer "1" as
7074 * soon as the body is entirely read: The "request" data structure
7075 * must act as an iterator.
7076 *
7077 * @see OrthancPluginChunkedHttpClient()
7078 * @param request The user payload, as provided by the calling plugin.
7079 * @return "1" if the body is over, or "0" if there is still data to be read.
7080 * @ingroup Toolbox
7081 **/
7082 typedef uint8_t (*OrthancPluginChunkedClientRequestIsDone) (void* request);
7083
7084
7085 /**
7086 * @brief Callback to advance in the request body during a chunked transfer
7087 *
7088 * Signature of a callback function that is called by Orthanc acting
7089 * as a HTTP client during a chunked HTTP transfer, while reading
7090 * the body of a POST or PUT request. This function asks the plugin
7091 * to advance to the next chunk of data of the request body: The
7092 * "request" data structure must act as an iterator.
7093 *
7094 * @see OrthancPluginChunkedHttpClient()
7095 * @param request The user payload, as provided by the calling plugin.
7096 * @return 0 if success, or the error code if failure.
7097 * @ingroup Toolbox
7098 **/
7099 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientRequestNext) (void* request);
7100
7101
7102 /**
7103 * @brief Callback to read the current chunk of the request body during a chunked transfer
7104 *
7105 * Signature of a callback function that is called by Orthanc acting
7106 * as a HTTP client during a chunked HTTP transfer, while reading
7107 * the body of a POST or PUT request. The plugin must provide the
7108 * content of the current chunk of data of the request body.
7109 *
7110 * @see OrthancPluginChunkedHttpClient()
7111 * @param request The user payload, as provided by the calling plugin.
7112 * @return The content of the current request chunk.
7113 * @ingroup Toolbox
7114 **/
7115 typedef const void* (*OrthancPluginChunkedClientRequestGetChunkData) (void* request);
7116
7117
7118 /**
7119 * @brief Callback to read the size of the current request chunk during a chunked transfer
7120 *
7121 * Signature of a callback function that is called by Orthanc acting
7122 * as a HTTP client during a chunked HTTP transfer, while reading
7123 * the body of a POST or PUT request. The plugin must provide the
7124 * size of the current chunk of data of the request body.
7125 *
7126 * @see OrthancPluginChunkedHttpClient()
7127 * @param request The user payload, as provided by the calling plugin.
7128 * @return The size of the current request chunk.
7129 * @ingroup Toolbox
7130 **/
7131 typedef uint32_t (*OrthancPluginChunkedClientRequestGetChunkSize) (void* request);
7132
7133
7134 typedef struct
7135 {
7136 void* answer;
7137 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk;
7138 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader;
7139 uint16_t* httpStatus;
7140 OrthancPluginHttpMethod method;
7141 const char* url;
7142 uint32_t headersCount;
7143 const char* const* headersKeys;
7144 const char* const* headersValues;
7145 void* request;
7146 OrthancPluginChunkedClientRequestIsDone requestIsDone;
7147 OrthancPluginChunkedClientRequestGetChunkData requestChunkData;
7148 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize;
7149 OrthancPluginChunkedClientRequestNext requestNext;
7150 const char* username;
7151 const char* password;
7152 uint32_t timeout;
7153 const char* certificateFile;
7154 const char* certificateKeyFile;
7155 const char* certificateKeyPassword;
7156 uint8_t pkcs11;
7157 } _OrthancPluginChunkedHttpClient;
7158
7159
7160 /**
7161 * @brief Issue a HTTP call, using chunked HTTP transfers.
7162 *
7163 * Make a HTTP call to the given URL using chunked HTTP
7164 * transfers. The request body is provided as an iterator over data
7165 * chunks. The answer is provided as a sequence of function calls
7166 * with the individual HTTP headers and answer chunks.
7167 *
7168 * Contrarily to OrthancPluginHttpClient() that entirely stores the
7169 * request body and the answer body in memory buffers, this function
7170 * uses chunked HTTP transfers. This results in a lower memory
7171 * consumption. Pay attention to the fact that Orthanc servers with
7172 * version <= 1.5.6 do not support chunked transfers: You must use
7173 * OrthancPluginHttpClient() if contacting such older servers.
7174 *
7175 * The HTTP request will be done accordingly to the global
7176 * configuration of Orthanc (in particular, the options "HttpProxy",
7177 * "HttpTimeout", "HttpsVerifyPeers", "HttpsCACertificates", and
7178 * "Pkcs11" will be taken into account).
7179 *
7180 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7181 * @param answer The user payload for the answer body. It will be provided to the callbacks for the answer.
7182 * @param answerAddChunk Callback function to report a data chunk from the answer body.
7183 * @param answerAddHeader Callback function to report an HTTP header sent by the remote server.
7184 * @param httpStatus The HTTP status after the execution of the request (out argument).
7185 * @param method HTTP method to be used.
7186 * @param url The URL of interest.
7187 * @param headersCount The number of HTTP headers.
7188 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
7189 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
7190 * @param request The user payload containing the request body, and acting as an iterator.
7191 * It will be provided to the callbacks for the request.
7192 * @param requestIsDone Callback function to tell whether the request body is entirely read.
7193 * @param requestChunkData Callback function to get the content of the current data chunk of the request body.
7194 * @param requestChunkSize Callback function to get the size of the current data chunk of the request body.
7195 * @param requestNext Callback function to advance to the next data chunk of the request body.
7196 * @param username The username (can be <tt>NULL</tt> if no password protection).
7197 * @param password The password (can be <tt>NULL</tt> if no password protection).
7198 * @param timeout Timeout in seconds (0 for default timeout).
7199 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
7200 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
7201 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
7202 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
7203 * @param certificateKeyPassword Password to unlock the key of the client certificate
7204 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
7205 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
7206 * @return 0 if success, or the error code if failure.
7207 * @see OrthancPluginHttpClient()
7208 * @ingroup Toolbox
7209 **/
7210 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginChunkedHttpClient(
7211 OrthancPluginContext* context,
7212 void* answer,
7213 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk,
7214 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader,
7215 uint16_t* httpStatus,
7216 OrthancPluginHttpMethod method,
7217 const char* url,
7218 uint32_t headersCount,
7219 const char* const* headersKeys,
7220 const char* const* headersValues,
7221 void* request,
7222 OrthancPluginChunkedClientRequestIsDone requestIsDone,
7223 OrthancPluginChunkedClientRequestGetChunkData requestChunkData,
7224 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize,
7225 OrthancPluginChunkedClientRequestNext requestNext,
7226 const char* username,
7227 const char* password,
7228 uint32_t timeout,
7229 const char* certificateFile,
7230 const char* certificateKeyFile,
7231 const char* certificateKeyPassword,
7232 uint8_t pkcs11)
7233 {
7234 _OrthancPluginChunkedHttpClient params;
7235 memset(&params, 0, sizeof(params));
7236
7237 /* In common with OrthancPluginHttpClient() */
7238 params.httpStatus = httpStatus;
7239 params.method = method;
7240 params.url = url;
7241 params.headersCount = headersCount;
7242 params.headersKeys = headersKeys;
7243 params.headersValues = headersValues;
7244 params.username = username;
7245 params.password = password;
7246 params.timeout = timeout;
7247 params.certificateFile = certificateFile;
7248 params.certificateKeyFile = certificateKeyFile;
7249 params.certificateKeyPassword = certificateKeyPassword;
7250 params.pkcs11 = pkcs11;
7251
7252 /* For chunked body/answer */
7253 params.answer = answer;
7254 params.answerAddChunk = answerAddChunk;
7255 params.answerAddHeader = answerAddHeader;
7256 params.request = request;
7257 params.requestIsDone = requestIsDone;
7258 params.requestChunkData = requestChunkData;
7259 params.requestChunkSize = requestChunkSize;
7260 params.requestNext = requestNext;
7261
7262 return context->InvokeService(context, _OrthancPluginService_ChunkedHttpClient, &params);
7263 }
7264
7265
7266
7267 /**
7268 * @brief Opaque structure that reads the content of a HTTP request body during a chunked HTTP transfer.
7269 * @ingroup Callback
7270 **/
7271 typedef struct _OrthancPluginServerChunkedRequestReader_t OrthancPluginServerChunkedRequestReader;
7272
7273
7274
7275 /**
7276 * @brief Callback to create a reader to handle incoming chunked HTTP transfers.
7277 *
7278 * Signature of a callback function that is called by Orthanc acting
7279 * as a HTTP server that supports chunked HTTP transfers. This
7280 * callback is only invoked if the HTTP method is POST or PUT. The
7281 * callback must create an user-specific "reader" object that will
7282 * be fed with the body of the incoming body.
7283 *
7284 * @see OrthancPluginRegisterChunkedRestCallback()
7285 * @param reader Memory location that must be filled with the newly-created reader.
7286 * @param url The URI that is accessed.
7287 * @param request The body of the HTTP request. Note that "body" and "bodySize" are not used.
7288 * @return 0 if success, or the error code if failure.
7289 **/
7290 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderFactory) (
7291 OrthancPluginServerChunkedRequestReader** reader,
7292 const char* url,
7293 const OrthancPluginHttpRequest* request);
7294
7295
7296 /**
7297 * @brief Callback invoked whenever a new data chunk is available during a chunked transfer.
7298 *
7299 * Signature of a callback function that is called by Orthanc acting
7300 * as a HTTP server that supports chunked HTTP transfers. This callback
7301 * is invoked as soon as a new data chunk is available for the request body.
7302 *
7303 * @see OrthancPluginRegisterChunkedRestCallback()
7304 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7305 * @param data The content of the data chunk.
7306 * @param size The size of the data chunk.
7307 * @return 0 if success, or the error code if failure.
7308 **/
7309 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderAddChunk) (
7310 OrthancPluginServerChunkedRequestReader* reader,
7311 const void* data,
7312 uint32_t size);
7313
7314
7315 /**
7316 * @brief Callback invoked whenever the request body is entirely received.
7317 *
7318 * Signature of a callback function that is called by Orthanc acting
7319 * as a HTTP server that supports chunked HTTP transfers. This
7320 * callback is invoked as soon as the full body of the HTTP request
7321 * is available. The plugin can then send its answer thanks to the
7322 * provided "output" object.
7323 *
7324 * @see OrthancPluginRegisterChunkedRestCallback()
7325 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7326 * @param output The HTTP connection to the client application.
7327 * @return 0 if success, or the error code if failure.
7328 **/
7329 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderExecute) (
7330 OrthancPluginServerChunkedRequestReader* reader,
7331 OrthancPluginRestOutput* output);
7332
7333
7334 /**
7335 * @brief Callback invoked to release the resources associated with an incoming HTTP chunked transfer.
7336 *
7337 * Signature of a callback function that is called by Orthanc acting
7338 * as a HTTP server that supports chunked HTTP transfers. This
7339 * callback is invoked to release all the resources allocated by the
7340 * given reader. Note that this function might be invoked even if
7341 * the entire body was not read, to deal with client error or
7342 * disconnection.
7343 *
7344 * @see OrthancPluginRegisterChunkedRestCallback()
7345 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7346 **/
7347 typedef void (*OrthancPluginServerChunkedRequestReaderFinalize) (
7348 OrthancPluginServerChunkedRequestReader* reader);
7349
7350 typedef struct
7351 {
7352 const char* pathRegularExpression;
7353 OrthancPluginRestCallback getHandler;
7354 OrthancPluginServerChunkedRequestReaderFactory postHandler;
7355 OrthancPluginRestCallback deleteHandler;
7356 OrthancPluginServerChunkedRequestReaderFactory putHandler;
7357 OrthancPluginServerChunkedRequestReaderAddChunk addChunk;
7358 OrthancPluginServerChunkedRequestReaderExecute execute;
7359 OrthancPluginServerChunkedRequestReaderFinalize finalize;
7360 } _OrthancPluginChunkedRestCallback;
7361
7362
7363 /**
7364 * @brief Register a REST callback to handle chunked HTTP transfers.
7365 *
7366 * This function registers a REST callback against a regular
7367 * expression for a URI. This function must be called during the
7368 * initialization of the plugin, i.e. inside the
7369 * OrthancPluginInitialize() public function.
7370 *
7371 * Contrarily to OrthancPluginRegisterRestCallback(), the callbacks
7372 * will NOT be invoked in mutual exclusion, so it is up to the
7373 * plugin to implement the required locking mechanisms.
7374 *
7375 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7376 * @param pathRegularExpression Regular expression for the URI. May contain groups.
7377 * @param getHandler The callback function to handle REST calls using the GET HTTP method.
7378 * @param postHandler The callback function to handle REST calls using the GET POST method.
7379 * @param deleteHandler The callback function to handle REST calls using the GET DELETE method.
7380 * @param putHandler The callback function to handle REST calls using the GET PUT method.
7381 * @param addChunk The callback invoked when a new chunk is available for the request body of a POST or PUT call.
7382 * @param execute The callback invoked once the entire body of a POST or PUT call is read.
7383 * @param finalize The callback invoked to release the resources associated with a POST or PUT call.
7384 * @see OrthancPluginRegisterRestCallbackNoLock()
7385 *
7386 * @note
7387 * The regular expression is case sensitive and must follow the
7388 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
7389 *
7390 * @ingroup Callbacks
7391 **/
7392 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterChunkedRestCallback(
7393 OrthancPluginContext* context,
7394 const char* pathRegularExpression,
7395 OrthancPluginRestCallback getHandler,
7396 OrthancPluginServerChunkedRequestReaderFactory postHandler,
7397 OrthancPluginRestCallback deleteHandler,
7398 OrthancPluginServerChunkedRequestReaderFactory putHandler,
7399 OrthancPluginServerChunkedRequestReaderAddChunk addChunk,
7400 OrthancPluginServerChunkedRequestReaderExecute execute,
7401 OrthancPluginServerChunkedRequestReaderFinalize finalize)
7402 {
7403 _OrthancPluginChunkedRestCallback params;
7404 params.pathRegularExpression = pathRegularExpression;
7405 params.getHandler = getHandler;
7406 params.postHandler = postHandler;
7407 params.deleteHandler = deleteHandler;
7408 params.putHandler = putHandler;
7409 params.addChunk = addChunk;
7410 params.execute = execute;
7411 params.finalize = finalize;
7412
7413 context->InvokeService(context, _OrthancPluginService_RegisterChunkedRestCallback, &params);
7414 }
7415
7416
7417
7418
7419
7420 typedef struct
7421 {
7422 char** result;
7423 uint16_t group;
7424 uint16_t element;
7425 const char* privateCreator;
7426 } _OrthancPluginGetTagName;
7427
7428 /**
7429 * @brief Returns the symbolic name of a DICOM tag.
7430 *
7431 * This function makes a lookup to the dictionary of DICOM tags that
7432 * are known to Orthanc, and returns the symbolic name of a DICOM tag.
7433 *
7434 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7435 * @param group The group of the tag.
7436 * @param element The element of the tag.
7437 * @param privateCreator For private tags, the name of the private creator (can be NULL).
7438 * @return NULL in the case of an error, or a newly allocated string
7439 * containing the path. This string must be freed by
7440 * OrthancPluginFreeString().
7441 * @ingroup Toolbox
7442 **/
7443 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetTagName(
7444 OrthancPluginContext* context,
7445 uint16_t group,
7446 uint16_t element,
7447 const char* privateCreator)
7448 {
7449 char* result;
7450
7451 _OrthancPluginGetTagName params;
7452 params.result = &result;
7453 params.group = group;
7454 params.element = element;
7455 params.privateCreator = privateCreator;
7456
7457 if (context->InvokeService(context, _OrthancPluginService_GetTagName, &params) != OrthancPluginErrorCode_Success)
7458 {
7459 /* Error */
7460 return NULL;
7461 }
7462 else
7463 {
7464 return result;
7465 }
7466 }
7467
7468
7469
7470 /**
7471 * @brief Callback executed by the storage commitment SCP.
7472 *
7473 * Signature of a factory function that creates an object to handle
7474 * one incoming storage commitment request.
7475 *
7476 * @remark The factory receives the list of the SOP class/instance
7477 * UIDs of interest to the remote storage commitment SCU. This gives
7478 * the factory the possibility to start some prefetch process
7479 * upfront in the background, before the handler object is actually
7480 * queried about the status of these DICOM instances.
7481 *
7482 * @param handler Output variable where the factory puts the handler object it created.
7483 * @param jobId ID of the Orthanc job that is responsible for handling
7484 * the storage commitment request. This job will successively look for the
7485 * status of all the individual queried DICOM instances.
7486 * @param transactionUid UID of the storage commitment transaction
7487 * provided by the storage commitment SCU. It contains the value of the
7488 * (0008,1195) DICOM tag.
7489 * @param sopClassUids Array of the SOP class UIDs (0008,0016) that are queried by the SCU.
7490 * @param sopInstanceUids Array of the SOP instance UIDs (0008,0018) that are queried by the SCU.
7491 * @param countInstances Number of DICOM instances that are queried. This is the size
7492 * of the `sopClassUids` and `sopInstanceUids` arrays.
7493 * @param remoteAet The AET of the storage commitment SCU.
7494 * @param calledAet The AET used by the SCU to contact the storage commitment SCP (i.e. Orthanc).
7495 * @return 0 if success, other value if error.
7496 * @ingroup DicomCallbacks
7497 **/
7498 typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentFactory) (
7499 void** handler /* out */,
7500 const char* jobId,
7501 const char* transactionUid,
7502 const char* const* sopClassUids,
7503 const char* const* sopInstanceUids,
7504 uint32_t countInstances,
7505 const char* remoteAet,
7506 const char* calledAet);
7507
7508
7509 /**
7510 * @brief Callback to free one storage commitment SCP handler.
7511 *
7512 * Signature of a callback function that releases the resources
7513 * allocated by the factory of the storage commitment SCP. The
7514 * handler is the return value of a previous call to the
7515 * OrthancPluginStorageCommitmentFactory() callback.
7516 *
7517 * @param handler The handler object to be destructed.
7518 * @ingroup DicomCallbacks
7519 **/
7520 typedef void (*OrthancPluginStorageCommitmentDestructor) (void* handler);
7521
7522
7523 /**
7524 * @brief Callback to get the status of one DICOM instance in the
7525 * storage commitment SCP.
7526 *
7527 * Signature of a callback function that is successively invoked for
7528 * each DICOM instance that is queried by the remote storage
7529 * commitment SCU. The function must be tought of as a method of
7530 * the handler object that was created by a previous call to the
7531 * OrthancPluginStorageCommitmentFactory() callback. After each call
7532 * to this method, the progress of the associated Orthanc job is
7533 * updated.
7534 *
7535 * @param target Output variable where to put the status for the queried instance.
7536 * @param handler The handler object associated with this storage commitment request.
7537 * @param sopClassUid The SOP class UID (0008,0016) of interest.
7538 * @param sopInstanceUid The SOP instance UID (0008,0018) of interest.
7539 * @ingroup DicomCallbacks
7540 **/
7541 typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentLookup) (
7542 OrthancPluginStorageCommitmentFailureReason* target,
7543 void* handler,
7544 const char* sopClassUid,
7545 const char* sopInstanceUid);
7546
7547
7548 typedef struct
7549 {
7550 OrthancPluginStorageCommitmentFactory factory;
7551 OrthancPluginStorageCommitmentDestructor destructor;
7552 OrthancPluginStorageCommitmentLookup lookup;
7553 } _OrthancPluginRegisterStorageCommitmentScpCallback;
7554
7555 /**
7556 * @brief Register a callback to handle incoming requests to the storage commitment SCP.
7557 *
7558 * This function registers a callback to handle storage commitment SCP requests.
7559 *
7560 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7561 * @param factory Factory function that creates the handler object
7562 * for incoming storage commitment requests.
7563 * @param destructor Destructor function to destroy the handler object.
7564 * @param lookup Callback method to get the status of one DICOM instance.
7565 * @return 0 if success, other value if error.
7566 * @ingroup DicomCallbacks
7567 **/
7568 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterStorageCommitmentScpCallback(
7569 OrthancPluginContext* context,
7570 OrthancPluginStorageCommitmentFactory factory,
7571 OrthancPluginStorageCommitmentDestructor destructor,
7572 OrthancPluginStorageCommitmentLookup lookup)
7573 {
7574 _OrthancPluginRegisterStorageCommitmentScpCallback params;
7575 params.factory = factory;
7576 params.destructor = destructor;
7577 params.lookup = lookup;
7578 return context->InvokeService(context, _OrthancPluginService_RegisterStorageCommitmentScpCallback, &params);
7579 }
7580
7581
7582
7583 /**
7584 * @brief Callback to filter incoming DICOM instances received by Orthanc.
7585 *
7586 * Signature of a callback function that is triggered whenever
7587 * Orthanc receives a new DICOM instance (e.g. through REST API or
7588 * DICOM protocol), and that answers whether this DICOM instance
7589 * should be accepted or discarded by Orthanc.
7590 *
7591 * Note that the metadata information is not available
7592 * (i.e. GetInstanceMetadata() should not be used on "instance").
7593 *
7594 * @param instance The received DICOM instance.
7595 * @return 0 to discard the instance, 1 to store the instance, -1 if error.
7596 * @ingroup Callback
7597 **/
7598 typedef int32_t (*OrthancPluginIncomingDicomInstanceFilter) (
7599 const OrthancPluginDicomInstance* instance);
7600
7601
7602 typedef struct
7603 {
7604 OrthancPluginIncomingDicomInstanceFilter callback;
7605 } _OrthancPluginIncomingDicomInstanceFilter;
7606
7607 /**
7608 * @brief Register a callback to filter incoming DICOM instance.
7609 *
7610 * This function registers a custom callback to filter incoming
7611 * DICOM instances received by Orthanc (either through the REST API
7612 * or through the DICOM protocol).
7613 *
7614 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7615 * @param callback The callback.
7616 * @return 0 if success, other value if error.
7617 * @ingroup Callbacks
7618 **/
7619 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingDicomInstanceFilter(
7620 OrthancPluginContext* context,
7621 OrthancPluginIncomingDicomInstanceFilter callback)
7622 {
7623 _OrthancPluginIncomingDicomInstanceFilter params;
7624 params.callback = callback;
7625
7626 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingDicomInstanceFilter, &params);
7627 }
7628
7629
7630 /**
7631 * @brief Get the transfer syntax of a DICOM file.
7632 *
7633 * This function returns a pointer to a newly created string that
7634 * contains the transfer syntax UID of the DICOM instance. The empty
7635 * string might be returned if this information is unknown.
7636 *
7637 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7638 * @param instance The instance of interest.
7639 * @return The NULL value in case of error, or a string containing the
7640 * transfer syntax UID. This string must be freed by OrthancPluginFreeString().
7641 * @ingroup DicomInstance
7642 **/
7643 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceTransferSyntaxUid(
7644 OrthancPluginContext* context,
7645 const OrthancPluginDicomInstance* instance)
7646 {
7647 char* result;
7648
7649 _OrthancPluginAccessDicomInstance params;
7650 memset(&params, 0, sizeof(params));
7651 params.resultStringToFree = &result;
7652 params.instance = instance;
7653
7654 if (context->InvokeService(context, _OrthancPluginService_GetInstanceTransferSyntaxUid, &params) != OrthancPluginErrorCode_Success)
7655 {
7656 /* Error */
7657 return NULL;
7658 }
7659 else
7660 {
7661 return result;
7662 }
7663 }
7664
7665
7666 /**
7667 * @brief Check whether the DICOM file has pixel data.
7668 *
7669 * This function returns a Boolean value indicating whether the
7670 * DICOM instance contains the pixel data (7FE0,0010) tag.
7671 *
7672 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7673 * @param instance The instance of interest.
7674 * @return "1" if the DICOM instance contains pixel data, or "0" if
7675 * the tag is missing, or "-1" in the case of an error.
7676 * @ingroup DicomInstance
7677 **/
7678 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginHasInstancePixelData(
7679 OrthancPluginContext* context,
7680 const OrthancPluginDicomInstance* instance)
7681 {
7682 int64_t hasPixelData;
7683
7684 _OrthancPluginAccessDicomInstance params;
7685 memset(&params, 0, sizeof(params));
7686 params.resultInt64 = &hasPixelData;
7687 params.instance = instance;
7688
7689 if (context->InvokeService(context, _OrthancPluginService_HasInstancePixelData, &params) != OrthancPluginErrorCode_Success ||
7690 hasPixelData < 0 ||
7691 hasPixelData > 1)
7692 {
7693 /* Error */
7694 return -1;
7695 }
7696 else
7697 {
7698 return (hasPixelData != 0);
7699 }
7700 }
7701
7702
7703
7704
7705
7706
7707 typedef struct
7708 {
7709 OrthancPluginDicomInstance** target;
7710 const void* buffer;
7711 uint32_t size;
7712 const char* transferSyntax;
7713 } _OrthancPluginCreateDicomInstance;
7714
7715 /**
7716 * @brief Parse a DICOM instance.
7717 *
7718 * This function parses a memory buffer that contains a DICOM
7719 * file. The function returns a new pointer to a data structure that
7720 * is managed by the Orthanc core.
7721 *
7722 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7723 * @param buffer The memory buffer containing the DICOM instance.
7724 * @param size The size of the memory buffer.
7725 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance().
7726 * @ingroup DicomInstance
7727 **/
7728 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginCreateDicomInstance(
7729 OrthancPluginContext* context,
7730 const void* buffer,
7731 uint32_t size)
7732 {
7733 OrthancPluginDicomInstance* target = NULL;
7734
7735 _OrthancPluginCreateDicomInstance params;
7736 params.target = &target;
7737 params.buffer = buffer;
7738 params.size = size;
7739
7740 if (context->InvokeService(context, _OrthancPluginService_CreateDicomInstance, &params) != OrthancPluginErrorCode_Success)
7741 {
7742 /* Error */
7743 return NULL;
7744 }
7745 else
7746 {
7747 return target;
7748 }
7749 }
7750
7751 typedef struct
7752 {
7753 OrthancPluginDicomInstance* dicom;
7754 } _OrthancPluginFreeDicomInstance;
7755
7756 /**
7757 * @brief Free a DICOM instance.
7758 *
7759 * This function frees a DICOM instance that was parsed using
7760 * OrthancPluginCreateDicomInstance().
7761 *
7762 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7763 * @param dicom The DICOM instance.
7764 * @ingroup DicomInstance
7765 **/
7766 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeDicomInstance(
7767 OrthancPluginContext* context,
7768 OrthancPluginDicomInstance* dicom)
7769 {
7770 _OrthancPluginFreeDicomInstance params;
7771 params.dicom = dicom;
7772
7773 context->InvokeService(context, _OrthancPluginService_FreeDicomInstance, &params);
7774 }
7775
7776
7777 typedef struct
7778 {
7779 uint32_t* targetUint32;
7780 OrthancPluginMemoryBuffer* targetBuffer;
7781 OrthancPluginImage** targetImage;
7782 char** targetStringToFree;
7783 const OrthancPluginDicomInstance* instance;
7784 uint32_t frameIndex;
7785 OrthancPluginDicomToJsonFormat format;
7786 OrthancPluginDicomToJsonFlags flags;
7787 uint32_t maxStringLength;
7788 OrthancPluginDicomWebBinaryCallback2 dicomWebCallback;
7789 void* dicomWebPayload;
7790 } _OrthancPluginAccessDicomInstance2;
7791
7792 /**
7793 * @brief Get the number of frames in a DICOM instance.
7794 *
7795 * This function returns the number of frames that are part of a
7796 * DICOM image managed by the Orthanc core.
7797 *
7798 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7799 * @param instance The instance of interest.
7800 * @return The number of frames (will be zero in the case of an error).
7801 * @ingroup DicomInstance
7802 **/
7803 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetInstanceFramesCount(
7804 OrthancPluginContext* context,
7805 const OrthancPluginDicomInstance* instance)
7806 {
7807 uint32_t count;
7808
7809 _OrthancPluginAccessDicomInstance2 params;
7810 memset(&params, 0, sizeof(params));
7811 params.targetUint32 = &count;
7812 params.instance = instance;
7813
7814 if (context->InvokeService(context, _OrthancPluginService_GetInstanceFramesCount, &params) != OrthancPluginErrorCode_Success)
7815 {
7816 /* Error */
7817 return 0;
7818 }
7819 else
7820 {
7821 return count;
7822 }
7823 }
7824
7825
7826 /**
7827 * @brief Get the raw content of a frame in a DICOM instance.
7828 *
7829 * This function returns a memory buffer containing the raw content
7830 * of a frame in a DICOM instance that is managed by the Orthanc
7831 * core. This is notably useful for compressed transfer syntaxes, as
7832 * it gives access to the embedded files (such as JPEG, JPEG-LS or
7833 * JPEG2k). The Orthanc core transparently reassembles the fragments
7834 * to extract the raw frame.
7835 *
7836 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7837 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
7838 * @param instance The instance of interest.
7839 * @param frameIndex The index of the frame of interest.
7840 * @return 0 if success, or the error code if failure.
7841 * @ingroup DicomInstance
7842 **/
7843 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetInstanceRawFrame(
7844 OrthancPluginContext* context,
7845 OrthancPluginMemoryBuffer* target,
7846 const OrthancPluginDicomInstance* instance,
7847 uint32_t frameIndex)
7848 {
7849 _OrthancPluginAccessDicomInstance2 params;
7850 memset(&params, 0, sizeof(params));
7851 params.targetBuffer = target;
7852 params.instance = instance;
7853 params.frameIndex = frameIndex;
7854
7855 return context->InvokeService(context, _OrthancPluginService_GetInstanceRawFrame, &params);
7856 }
7857
7858
7859 /**
7860 * @brief Decode one frame from a DICOM instance.
7861 *
7862 * This function decodes one frame of a DICOM image that is managed
7863 * by the Orthanc core.
7864 *
7865 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7866 * @param instance The instance of interest.
7867 * @param frameIndex The index of the frame of interest.
7868 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
7869 * @ingroup DicomInstance
7870 **/
7871 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginGetInstanceDecodedFrame(
7872 OrthancPluginContext* context,
7873 const OrthancPluginDicomInstance* instance,
7874 uint32_t frameIndex)
7875 {
7876 OrthancPluginImage* target = NULL;
7877
7878 _OrthancPluginAccessDicomInstance2 params;
7879 memset(&params, 0, sizeof(params));
7880 params.targetImage = &target;
7881 params.instance = instance;
7882 params.frameIndex = frameIndex;
7883
7884 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDecodedFrame, &params) != OrthancPluginErrorCode_Success)
7885 {
7886 return NULL;
7887 }
7888 else
7889 {
7890 return target;
7891 }
7892 }
7893
7894
7895 /**
7896 * @brief Parse and transcode a DICOM instance.
7897 *
7898 * This function parses a memory buffer that contains a DICOM file,
7899 * then transcodes it to the given transfer syntax. The function
7900 * returns a new pointer to a data structure that is managed by the
7901 * Orthanc core.
7902 *
7903 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7904 * @param buffer The memory buffer containing the DICOM instance.
7905 * @param size The size of the memory buffer.
7906 * @param transferSyntax The transfer syntax UID for the transcoding.
7907 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance().
7908 * @ingroup DicomInstance
7909 **/
7910 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginTranscodeDicomInstance(
7911 OrthancPluginContext* context,
7912 const void* buffer,
7913 uint32_t size,
7914 const char* transferSyntax)
7915 {
7916 OrthancPluginDicomInstance* target = NULL;
7917
7918 _OrthancPluginCreateDicomInstance params;
7919 params.target = &target;
7920 params.buffer = buffer;
7921 params.size = size;
7922 params.transferSyntax = transferSyntax;
7923
7924 if (context->InvokeService(context, _OrthancPluginService_TranscodeDicomInstance, &params) != OrthancPluginErrorCode_Success)
7925 {
7926 /* Error */
7927 return NULL;
7928 }
7929 else
7930 {
7931 return target;
7932 }
7933 }
7934
7935 /**
7936 * @brief Writes a DICOM instance to a memory buffer.
7937 *
7938 * This function returns a memory buffer containing the
7939 * serialization of a DICOM instance that is managed by the Orthanc
7940 * core.
7941 *
7942 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7943 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
7944 * @param instance The instance of interest.
7945 * @return 0 if success, or the error code if failure.
7946 * @ingroup DicomInstance
7947 **/
7948 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSerializeDicomInstance(
7949 OrthancPluginContext* context,
7950 OrthancPluginMemoryBuffer* target,
7951 const OrthancPluginDicomInstance* instance)
7952 {
7953 _OrthancPluginAccessDicomInstance2 params;
7954 memset(&params, 0, sizeof(params));
7955 params.targetBuffer = target;
7956 params.instance = instance;
7957
7958 return context->InvokeService(context, _OrthancPluginService_SerializeDicomInstance, &params);
7959 }
7960
7961
7962 /**
7963 * @brief Format a DICOM memory buffer as a JSON string.
7964 *
7965 * This function takes as DICOM instance managed by the Orthanc
7966 * core, and outputs a JSON string representing the tags of this
7967 * DICOM file.
7968 *
7969 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7970 * @param instance The DICOM instance of interest.
7971 * @param format The output format.
7972 * @param flags Flags governing the output.
7973 * @param maxStringLength The maximum length of a field. Too long fields will
7974 * be output as "null". The 0 value means no maximum length.
7975 * @return The NULL value if the case of an error, or the JSON
7976 * string. This string must be freed by OrthancPluginFreeString().
7977 * @ingroup DicomInstance
7978 * @see OrthancPluginDicomBufferToJson
7979 **/
7980 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceAdvancedJson(
7981 OrthancPluginContext* context,
7982 const OrthancPluginDicomInstance* instance,
7983 OrthancPluginDicomToJsonFormat format,
7984 OrthancPluginDicomToJsonFlags flags,
7985 uint32_t maxStringLength)
7986 {
7987 char* result = NULL;
7988
7989 _OrthancPluginAccessDicomInstance2 params;
7990 memset(&params, 0, sizeof(params));
7991 params.targetStringToFree = &result;
7992 params.instance = instance;
7993 params.format = format;
7994 params.flags = flags;
7995 params.maxStringLength = maxStringLength;
7996
7997 if (context->InvokeService(context, _OrthancPluginService_GetInstanceAdvancedJson, &params) != OrthancPluginErrorCode_Success)
7998 {
7999 /* Error */
8000 return NULL;
8001 }
8002 else
8003 {
8004 return result;
8005 }
8006 }
8007
8008
8009 /**
8010 * @brief Convert a DICOM instance to DICOMweb JSON.
8011 *
8012 * This function converts a DICOM instance that is managed by the
8013 * Orthanc core, into its DICOMweb JSON representation.
8014 *
8015 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8016 * @param instance The DICOM instance of interest.
8017 * @param callback Callback to set the value of the binary tags.
8018 * @param payload User payload.
8019 * @return The NULL value in case of error, or the JSON document. This string must
8020 * be freed by OrthancPluginFreeString().
8021 * @ingroup DicomInstance
8022 **/
8023 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceDicomWebJson(
8024 OrthancPluginContext* context,
8025 const OrthancPluginDicomInstance* instance,
8026 OrthancPluginDicomWebBinaryCallback2 callback,
8027 void* payload)
8028 {
8029 char* target = NULL;
8030
8031 _OrthancPluginAccessDicomInstance2 params;
8032 params.targetStringToFree = &target;
8033 params.instance = instance;
8034 params.dicomWebCallback = callback;
8035 params.dicomWebPayload = payload;
8036
8037 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDicomWebJson, &params) != OrthancPluginErrorCode_Success)
8038 {
8039 /* Error */
8040 return NULL;
8041 }
8042 else
8043 {
8044 return target;
8045 }
8046 }
8047
8048
8049 /**
8050 * @brief Convert a DICOM instance to DICOMweb XML.
8051 *
8052 * This function converts a DICOM instance that is managed by the
8053 * Orthanc core, into its DICOMweb XML representation.
8054 *
8055 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8056 * @param instance The DICOM instance of interest.
8057 * @param callback Callback to set the value of the binary tags.
8058 * @param payload User payload.
8059 * @return The NULL value in case of error, or the XML document. This string must
8060 * be freed by OrthancPluginFreeString().
8061 * @ingroup DicomInstance
8062 **/
8063 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceDicomWebXml(
8064 OrthancPluginContext* context,
8065 const OrthancPluginDicomInstance* instance,
8066 OrthancPluginDicomWebBinaryCallback2 callback,
8067 void* payload)
8068 {
8069 char* target = NULL;
8070
8071 _OrthancPluginAccessDicomInstance2 params;
8072 params.targetStringToFree = &target;
8073 params.instance = instance;
8074 params.dicomWebCallback = callback;
8075 params.dicomWebPayload = payload;
8076
8077 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDicomWebXml, &params) != OrthancPluginErrorCode_Success)
8078 {
8079 /* Error */
8080 return NULL;
8081 }
8082 else
8083 {
8084 return target;
8085 }
8086 }
8087
8088
8089
8090 /**
8091 * @brief Signature of a callback function to transcode a DICOM instance.
8092 * @param transcoded Target memory buffer. It must be allocated by the
8093 * plugin using OrthancPluginCreateMemoryBuffer().
8094 * @param buffer Memory buffer containing the source DICOM instance.
8095 * @param size Size of the source memory buffer.
8096 * @param allowedSyntaxes A C array of possible transfer syntaxes UIDs for the
8097 * result of the transcoding. The plugin must choose by itself the
8098 * transfer syntax that will be used for the resulting DICOM image.
8099 * @param countSyntaxes The number of transfer syntaxes that are contained
8100 * in the "allowedSyntaxes" array.
8101 * @param allowNewSopInstanceUid Whether the transcoding plugin can select
8102 * a transfer syntax that will change the SOP instance UID (or, in other
8103 * terms, whether the plugin can transcode using lossy compression).
8104 * @return 0 if success (i.e. image successfully transcoded and stored into
8105 * "transcoded"), or the error code if failure.
8106 * @ingroup Callbacks
8107 **/
8108 typedef OrthancPluginErrorCode (*OrthancPluginTranscoderCallback) (
8109 OrthancPluginMemoryBuffer* transcoded /* out */,
8110 const void* buffer,
8111 uint64_t size,
8112 const char* const* allowedSyntaxes,
8113 uint32_t countSyntaxes,
8114 uint8_t allowNewSopInstanceUid);
8115
8116
8117 typedef struct
8118 {
8119 OrthancPluginTranscoderCallback callback;
8120 } _OrthancPluginTranscoderCallback;
8121
8122 /**
8123 * @brief Register a callback to handle the transcoding of DICOM images.
8124 *
8125 * This function registers a custom callback to transcode DICOM
8126 * images, extending the built-in transcoder of Orthanc that uses
8127 * DCMTK. The exact behavior is affected by the configuration option
8128 * "BuiltinDecoderTranscoderOrder" of Orthanc.
8129 *
8130 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8131 * @param callback The callback.
8132 * @return 0 if success, other value if error.
8133 * @ingroup Callbacks
8134 **/
8135 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterTranscoderCallback(
8136 OrthancPluginContext* context,
8137 OrthancPluginTranscoderCallback callback)
8138 {
8139 _OrthancPluginTranscoderCallback params;
8140 params.callback = callback;
8141
8142 return context->InvokeService(context, _OrthancPluginService_RegisterTranscoderCallback, &params);
8143 }
8144
8145
8146
8147 typedef struct
8148 {
8149 OrthancPluginMemoryBuffer* target;
8150 uint32_t size;
8151 } _OrthancPluginCreateMemoryBuffer;
8152
8153 /**
8154 * @brief Create a memory buffer.
8155 *
8156 * This function creates a memory buffer that is managed by the
8157 * Orthanc core. The main use case of this function is for plugins
8158 * that act as DICOM transcoders.
8159 *
8160 * Your plugin should never call "free()" on the resulting memory
8161 * buffer, as the C library that is used by the plugin is in general
8162 * not the same as the one used by the Orthanc core.
8163 *
8164 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8165 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
8166 * @param size Size of the memory buffer to be created.
8167 * @return 0 if success, or the error code if failure.
8168 * @ingroup Toolbox
8169 **/
8170 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateMemoryBuffer(
8171 OrthancPluginContext* context,
8172 OrthancPluginMemoryBuffer* target,
8173 uint32_t size)
8174 {
8175 _OrthancPluginCreateMemoryBuffer params;
8176 params.target = target;
8177 params.size = size;
8178
8179 return context->InvokeService(context, _OrthancPluginService_CreateMemoryBuffer, &params);
8180 }
8181
8182
8183 #ifdef __cplusplus
8184 }
8185 #endif
8186
8187
8188 /** @} */
8189
1010 import urllib2
1111
1212 TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc')
13 PLUGIN_SDK_VERSION = '1.5.7'
14 REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw'
13 PLUGIN_SDK_VERSION = '1.7.0'
14 REPOSITORY = 'https://hg.orthanc-server.com/orthanc/raw-file'
1515
1616 FILES = [
1717 'DownloadOrthancFramework.cmake',
00 Reference: http://dicom.nema.org/MEDICAL/dicom/2019a/output/html/part18.html
11
2 If you need some missing feature as an industrial player, please
3 consider hiring the development team from Osimis by filling the
4 dedicated form on the Orthanc Web site:
5 https://www.orthanc-server.com/orthanc-pro.php
26
37
48 =======================================
102106 * GIF output
103107 * The following "Retrieve Rendered Query Parameters" (table 6.5.8-2):
104108 annotation, charset, iccprofile
105 * URI "/studies/.../rendered" (only available for series, instances and frames)
106109
107110
108111
147150
148151
149152
153 ===================
154 6.8 RS Capabilities
155 ===================
156
157 Not supported.
158
159
160
161 ===================
162 6.9 UPS-RS Worklist
163 ===================
164
165 Not supported.
166
167
168
150169 ==========================================================
151170 CP 1509 - Refactor media type description for web services
152171 ==========================================================