Orthanc Plugin SDK  1.9.7
Documentation of the plugin interface of Orthanc
OrthancCDatabasePlugin.h
1 
27 #pragma once
28 
29 #include "OrthancCPlugin.h"
30 
31 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38 
39 
44  typedef struct _OrthancPluginDatabaseContext_t OrthancPluginDatabaseContext;
45 
46 
52  typedef struct _OrthancPluginDatabaseTransaction_t OrthancPluginDatabaseTransaction;
53 
54 
55 /*<! @cond Doxygen_Suppress */
56  typedef enum
57  {
58  _OrthancPluginDatabaseAnswerType_None = 0,
59 
60  /* Events */
61  _OrthancPluginDatabaseAnswerType_DeletedAttachment = 1,
62  _OrthancPluginDatabaseAnswerType_DeletedResource = 2,
63  _OrthancPluginDatabaseAnswerType_RemainingAncestor = 3,
64 
65  /* Return value */
66  _OrthancPluginDatabaseAnswerType_Attachment = 10,
67  _OrthancPluginDatabaseAnswerType_Change = 11,
68  _OrthancPluginDatabaseAnswerType_DicomTag = 12,
69  _OrthancPluginDatabaseAnswerType_ExportedResource = 13,
70  _OrthancPluginDatabaseAnswerType_Int32 = 14,
71  _OrthancPluginDatabaseAnswerType_Int64 = 15,
72  _OrthancPluginDatabaseAnswerType_Resource = 16,
73  _OrthancPluginDatabaseAnswerType_String = 17,
74  _OrthancPluginDatabaseAnswerType_MatchingResource = 18, /* New in Orthanc 1.5.2 */
75  _OrthancPluginDatabaseAnswerType_Metadata = 19, /* New in Orthanc 1.5.4 */
76 
77  _OrthancPluginDatabaseAnswerType_INTERNAL = 0x7fffffff
78  } _OrthancPluginDatabaseAnswerType;
79 
80 
81  typedef struct
82  {
83  const char* uuid;
84  int32_t contentType;
85  uint64_t uncompressedSize;
86  const char* uncompressedHash;
87  int32_t compressionType;
88  uint64_t compressedSize;
89  const char* compressedHash;
90  } OrthancPluginAttachment;
91 
92  typedef struct
93  {
94  uint16_t group;
95  uint16_t element;
96  const char* value;
97  } OrthancPluginDicomTag;
98 
99  typedef struct
100  {
101  int64_t seq;
102  int32_t changeType;
103  OrthancPluginResourceType resourceType;
104  const char* publicId;
105  const char* date;
106  } OrthancPluginChange;
107 
108  typedef struct
109  {
110  int64_t seq;
111  OrthancPluginResourceType resourceType;
112  const char* publicId;
113  const char* modality;
114  const char* date;
115  const char* patientId;
116  const char* studyInstanceUid;
117  const char* seriesInstanceUid;
118  const char* sopInstanceUid;
119  } OrthancPluginExportedResource;
120 
121  typedef struct /* New in Orthanc 1.5.2 */
122  {
124  uint16_t tagGroup;
125  uint16_t tagElement;
126  uint8_t isIdentifierTag;
127  uint8_t isCaseSensitive;
128  uint8_t isMandatory;
130  uint32_t valuesCount;
131  const char* const* values;
132  } OrthancPluginDatabaseConstraint;
133 
134  typedef struct /* New in Orthanc 1.5.2 */
135  {
136  const char* resourceId;
137  const char* someInstanceId; /* Can be NULL if not requested */
138  } OrthancPluginMatchingResource;
139 
140  typedef struct /* New in Orthanc 1.5.2 */
141  {
142  /* Mandatory field */
143  uint8_t isNewInstance;
144  int64_t instanceId;
145 
146  /* The following fields must only be set if "isNewInstance" is "true" */
147  uint8_t isNewPatient;
148  uint8_t isNewStudy;
149  uint8_t isNewSeries;
150  int64_t patientId;
151  int64_t studyId;
152  int64_t seriesId;
153  } OrthancPluginCreateInstanceResult;
154 
155  typedef struct /* New in Orthanc 1.5.2 */
156  {
157  int64_t resource;
158  uint16_t group;
159  uint16_t element;
160  const char* value;
161  } OrthancPluginResourcesContentTags;
162 
163  typedef struct /* New in Orthanc 1.5.2 */
164  {
165  int64_t resource;
166  int32_t metadata;
167  const char* value;
168  } OrthancPluginResourcesContentMetadata;
169 
170 
171  typedef struct
172  {
174  _OrthancPluginDatabaseAnswerType type;
175  int32_t valueInt32;
176  uint32_t valueUint32;
177  int64_t valueInt64;
178  const char *valueString;
179  const void *valueGeneric;
180  } _OrthancPluginDatabaseAnswer;
181 
182  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerString(
183  OrthancPluginContext* context,
185  const char* value)
186  {
187  _OrthancPluginDatabaseAnswer params;
188  memset(&params, 0, sizeof(params));
189  params.database = database;
190  params.type = _OrthancPluginDatabaseAnswerType_String;
191  params.valueString = value;
192  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
193  }
194 
195  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerChange(
196  OrthancPluginContext* context,
198  const OrthancPluginChange* change)
199  {
200  _OrthancPluginDatabaseAnswer params;
201  memset(&params, 0, sizeof(params));
202 
203  params.database = database;
204  params.type = _OrthancPluginDatabaseAnswerType_Change;
205  params.valueUint32 = 0;
206  params.valueGeneric = change;
207 
208  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
209  }
210 
211  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerChangesDone(
212  OrthancPluginContext* context,
214  {
215  _OrthancPluginDatabaseAnswer params;
216  memset(&params, 0, sizeof(params));
217 
218  params.database = database;
219  params.type = _OrthancPluginDatabaseAnswerType_Change;
220  params.valueUint32 = 1;
221  params.valueGeneric = NULL;
222 
223  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
224  }
225 
226  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerInt32(
227  OrthancPluginContext* context,
229  int32_t value)
230  {
231  _OrthancPluginDatabaseAnswer params;
232  memset(&params, 0, sizeof(params));
233  params.database = database;
234  params.type = _OrthancPluginDatabaseAnswerType_Int32;
235  params.valueInt32 = value;
236  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
237  }
238 
239  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerInt64(
240  OrthancPluginContext* context,
242  int64_t value)
243  {
244  _OrthancPluginDatabaseAnswer params;
245  memset(&params, 0, sizeof(params));
246  params.database = database;
247  params.type = _OrthancPluginDatabaseAnswerType_Int64;
248  params.valueInt64 = value;
249  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
250  }
251 
252  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerExportedResource(
253  OrthancPluginContext* context,
255  const OrthancPluginExportedResource* exported)
256  {
257  _OrthancPluginDatabaseAnswer params;
258  memset(&params, 0, sizeof(params));
259 
260  params.database = database;
261  params.type = _OrthancPluginDatabaseAnswerType_ExportedResource;
262  params.valueUint32 = 0;
263  params.valueGeneric = exported;
264  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
265  }
266 
267  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerExportedResourcesDone(
268  OrthancPluginContext* context,
270  {
271  _OrthancPluginDatabaseAnswer params;
272  memset(&params, 0, sizeof(params));
273 
274  params.database = database;
275  params.type = _OrthancPluginDatabaseAnswerType_ExportedResource;
276  params.valueUint32 = 1;
277  params.valueGeneric = NULL;
278  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
279  }
280 
281  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerDicomTag(
282  OrthancPluginContext* context,
284  const OrthancPluginDicomTag* tag)
285  {
286  _OrthancPluginDatabaseAnswer params;
287  memset(&params, 0, sizeof(params));
288  params.database = database;
289  params.type = _OrthancPluginDatabaseAnswerType_DicomTag;
290  params.valueGeneric = tag;
291  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
292  }
293 
294  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerAttachment(
295  OrthancPluginContext* context,
297  const OrthancPluginAttachment* attachment)
298  {
299  _OrthancPluginDatabaseAnswer params;
300  memset(&params, 0, sizeof(params));
301  params.database = database;
302  params.type = _OrthancPluginDatabaseAnswerType_Attachment;
303  params.valueGeneric = attachment;
304  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
305  }
306 
307  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerResource(
308  OrthancPluginContext* context,
310  int64_t id,
311  OrthancPluginResourceType resourceType)
312  {
313  _OrthancPluginDatabaseAnswer params;
314  memset(&params, 0, sizeof(params));
315  params.database = database;
316  params.type = _OrthancPluginDatabaseAnswerType_Resource;
317  params.valueInt64 = id;
318  params.valueInt32 = (int32_t) resourceType;
319  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
320  }
321 
322  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerMatchingResource(
323  OrthancPluginContext* context,
325  const OrthancPluginMatchingResource* match)
326  {
327  _OrthancPluginDatabaseAnswer params;
328  memset(&params, 0, sizeof(params));
329  params.database = database;
330  params.type = _OrthancPluginDatabaseAnswerType_MatchingResource;
331  params.valueGeneric = match;
332  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
333  }
334 
335  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerMetadata(
336  OrthancPluginContext* context,
338  int64_t resourceId,
339  int32_t type,
340  const char* value)
341  {
342  OrthancPluginResourcesContentMetadata metadata;
343  _OrthancPluginDatabaseAnswer params;
344  metadata.resource = resourceId;
345  metadata.metadata = type;
346  metadata.value = value;
347  memset(&params, 0, sizeof(params));
348  params.database = database;
349  params.type = _OrthancPluginDatabaseAnswerType_Metadata;
350  params.valueGeneric = &metadata;
351  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
352  }
353 
354  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedAttachment(
355  OrthancPluginContext* context,
357  const OrthancPluginAttachment* attachment)
358  {
359  _OrthancPluginDatabaseAnswer params;
360  memset(&params, 0, sizeof(params));
361  params.database = database;
362  params.type = _OrthancPluginDatabaseAnswerType_DeletedAttachment;
363  params.valueGeneric = attachment;
364  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
365  }
366 
367  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedResource(
368  OrthancPluginContext* context,
370  const char* publicId,
371  OrthancPluginResourceType resourceType)
372  {
373  _OrthancPluginDatabaseAnswer params;
374  memset(&params, 0, sizeof(params));
375  params.database = database;
376  params.type = _OrthancPluginDatabaseAnswerType_DeletedResource;
377  params.valueString = publicId;
378  params.valueInt32 = (int32_t) resourceType;
379  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
380  }
381 
382  ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalRemainingAncestor(
383  OrthancPluginContext* context,
385  const char* ancestorId,
386  OrthancPluginResourceType ancestorType)
387  {
388  _OrthancPluginDatabaseAnswer params;
389  memset(&params, 0, sizeof(params));
390  params.database = database;
391  params.type = _OrthancPluginDatabaseAnswerType_RemainingAncestor;
392  params.valueString = ancestorId;
393  params.valueInt32 = (int32_t) ancestorType;
394  context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, &params);
395  }
396 
397 
398 
399 
400 
401  typedef struct
402  {
403  OrthancPluginErrorCode (*addAttachment) (
404  /* inputs */
405  void* payload,
406  int64_t id,
407  const OrthancPluginAttachment* attachment);
408 
409  OrthancPluginErrorCode (*attachChild) (
410  /* inputs */
411  void* payload,
412  int64_t parent,
413  int64_t child);
414 
415  OrthancPluginErrorCode (*clearChanges) (
416  /* inputs */
417  void* payload);
418 
419  OrthancPluginErrorCode (*clearExportedResources) (
420  /* inputs */
421  void* payload);
422 
423  OrthancPluginErrorCode (*createResource) (
424  /* outputs */
425  int64_t* id,
426  /* inputs */
427  void* payload,
428  const char* publicId,
429  OrthancPluginResourceType resourceType);
430 
431  OrthancPluginErrorCode (*deleteAttachment) (
432  /* inputs */
433  void* payload,
434  int64_t id,
435  int32_t contentType);
436 
437  OrthancPluginErrorCode (*deleteMetadata) (
438  /* inputs */
439  void* payload,
440  int64_t id,
441  int32_t metadataType);
442 
443  OrthancPluginErrorCode (*deleteResource) (
444  /* inputs */
445  void* payload,
446  int64_t id);
447 
448  /* Output: Use OrthancPluginDatabaseAnswerString() */
449  OrthancPluginErrorCode (*getAllPublicIds) (
450  /* outputs */
452  /* inputs */
453  void* payload,
454  OrthancPluginResourceType resourceType);
455 
456  /* Output: Use OrthancPluginDatabaseAnswerChange() and
457  * OrthancPluginDatabaseAnswerChangesDone() */
458  OrthancPluginErrorCode (*getChanges) (
459  /* outputs */
461  /* inputs */
462  void* payload,
463  int64_t since,
464  uint32_t maxResult);
465 
466  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
467  OrthancPluginErrorCode (*getChildrenInternalId) (
468  /* outputs */
470  /* inputs */
471  void* payload,
472  int64_t id);
473 
474  /* Output: Use OrthancPluginDatabaseAnswerString() */
475  OrthancPluginErrorCode (*getChildrenPublicId) (
476  /* outputs */
478  /* inputs */
479  void* payload,
480  int64_t id);
481 
482  /* Output: Use OrthancPluginDatabaseAnswerExportedResource() and
483  * OrthancPluginDatabaseAnswerExportedResourcesDone() */
484  OrthancPluginErrorCode (*getExportedResources) (
485  /* outputs */
487  /* inputs */
488  void* payload,
489  int64_t since,
490  uint32_t maxResult);
491 
492  /* Output: Use OrthancPluginDatabaseAnswerChange() */
493  OrthancPluginErrorCode (*getLastChange) (
494  /* outputs */
496  /* inputs */
497  void* payload);
498 
499  /* Output: Use OrthancPluginDatabaseAnswerExportedResource() */
500  OrthancPluginErrorCode (*getLastExportedResource) (
501  /* outputs */
503  /* inputs */
504  void* payload);
505 
506  /* Output: Use OrthancPluginDatabaseAnswerDicomTag() */
507  OrthancPluginErrorCode (*getMainDicomTags) (
508  /* outputs */
510  /* inputs */
511  void* payload,
512  int64_t id);
513 
514  /* Output: Use OrthancPluginDatabaseAnswerString() */
515  OrthancPluginErrorCode (*getPublicId) (
516  /* outputs */
518  /* inputs */
519  void* payload,
520  int64_t id);
521 
522  OrthancPluginErrorCode (*getResourceCount) (
523  /* outputs */
524  uint64_t* target,
525  /* inputs */
526  void* payload,
527  OrthancPluginResourceType resourceType);
528 
529  OrthancPluginErrorCode (*getResourceType) (
530  /* outputs */
531  OrthancPluginResourceType* resourceType,
532  /* inputs */
533  void* payload,
534  int64_t id);
535 
536  OrthancPluginErrorCode (*getTotalCompressedSize) (
537  /* outputs */
538  uint64_t* target,
539  /* inputs */
540  void* payload);
541 
542  OrthancPluginErrorCode (*getTotalUncompressedSize) (
543  /* outputs */
544  uint64_t* target,
545  /* inputs */
546  void* payload);
547 
548  OrthancPluginErrorCode (*isExistingResource) (
549  /* outputs */
550  int32_t* existing,
551  /* inputs */
552  void* payload,
553  int64_t id);
554 
555  OrthancPluginErrorCode (*isProtectedPatient) (
556  /* outputs */
557  int32_t* isProtected,
558  /* inputs */
559  void* payload,
560  int64_t id);
561 
562  /* Output: Use OrthancPluginDatabaseAnswerInt32() */
563  OrthancPluginErrorCode (*listAvailableMetadata) (
564  /* outputs */
566  /* inputs */
567  void* payload,
568  int64_t id);
569 
570  /* Output: Use OrthancPluginDatabaseAnswerInt32() */
571  OrthancPluginErrorCode (*listAvailableAttachments) (
572  /* outputs */
574  /* inputs */
575  void* payload,
576  int64_t id);
577 
578  OrthancPluginErrorCode (*logChange) (
579  /* inputs */
580  void* payload,
581  const OrthancPluginChange* change);
582 
583  OrthancPluginErrorCode (*logExportedResource) (
584  /* inputs */
585  void* payload,
586  const OrthancPluginExportedResource* exported);
587 
588  /* Output: Use OrthancPluginDatabaseAnswerAttachment() */
589  OrthancPluginErrorCode (*lookupAttachment) (
590  /* outputs */
592  /* inputs */
593  void* payload,
594  int64_t id,
595  int32_t contentType);
596 
597  /* Output: Use OrthancPluginDatabaseAnswerString() */
598  OrthancPluginErrorCode (*lookupGlobalProperty) (
599  /* outputs */
601  /* inputs */
602  void* payload,
603  int32_t property);
604 
605  /* Use "OrthancPluginDatabaseExtensions::lookupIdentifier3"
606  instead of this function as of Orthanc 0.9.5 (db v6), can be set to NULL.
607  Output: Use OrthancPluginDatabaseAnswerInt64() */
608  OrthancPluginErrorCode (*lookupIdentifier) (
609  /* outputs */
611  /* inputs */
612  void* payload,
613  const OrthancPluginDicomTag* tag);
614 
615  /* Unused starting with Orthanc 0.9.5 (db v6), can be set to NULL.
616  Output: Use OrthancPluginDatabaseAnswerInt64() */
617  OrthancPluginErrorCode (*lookupIdentifier2) (
618  /* outputs */
620  /* inputs */
621  void* payload,
622  const char* value);
623 
624  /* Output: Use OrthancPluginDatabaseAnswerString() */
625  OrthancPluginErrorCode (*lookupMetadata) (
626  /* outputs */
628  /* inputs */
629  void* payload,
630  int64_t id,
631  int32_t metadata);
632 
633  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
634  OrthancPluginErrorCode (*lookupParent) (
635  /* outputs */
637  /* inputs */
638  void* payload,
639  int64_t id);
640 
641  /* Output: Use OrthancPluginDatabaseAnswerResource() */
642  OrthancPluginErrorCode (*lookupResource) (
643  /* outputs */
645  /* inputs */
646  void* payload,
647  const char* publicId);
648 
649  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
650  OrthancPluginErrorCode (*selectPatientToRecycle) (
651  /* outputs */
653  /* inputs */
654  void* payload);
655 
656  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
657  OrthancPluginErrorCode (*selectPatientToRecycle2) (
658  /* outputs */
660  /* inputs */
661  void* payload,
662  int64_t patientIdToAvoid);
663 
664  OrthancPluginErrorCode (*setGlobalProperty) (
665  /* inputs */
666  void* payload,
667  int32_t property,
668  const char* value);
669 
670  OrthancPluginErrorCode (*setMainDicomTag) (
671  /* inputs */
672  void* payload,
673  int64_t id,
674  const OrthancPluginDicomTag* tag);
675 
676  OrthancPluginErrorCode (*setIdentifierTag) (
677  /* inputs */
678  void* payload,
679  int64_t id,
680  const OrthancPluginDicomTag* tag);
681 
682  OrthancPluginErrorCode (*setMetadata) (
683  /* inputs */
684  void* payload,
685  int64_t id,
686  int32_t metadata,
687  const char* value);
688 
689  OrthancPluginErrorCode (*setProtectedPatient) (
690  /* inputs */
691  void* payload,
692  int64_t id,
693  int32_t isProtected);
694 
695  OrthancPluginErrorCode (*startTransaction) (
696  /* inputs */
697  void* payload);
698 
699  OrthancPluginErrorCode (*rollbackTransaction) (
700  /* inputs */
701  void* payload);
702 
703  OrthancPluginErrorCode (*commitTransaction) (
704  /* inputs */
705  void* payload);
706 
707  OrthancPluginErrorCode (*open) (
708  /* inputs */
709  void* payload);
710 
711  OrthancPluginErrorCode (*close) (
712  /* inputs */
713  void* payload);
714 
715  } OrthancPluginDatabaseBackend;
716 
717 
718  typedef struct
719  {
724  /* Output: Use OrthancPluginDatabaseAnswerString() */
725  OrthancPluginErrorCode (*getAllPublicIdsWithLimit) (
726  /* outputs */
728  /* inputs */
729  void* payload,
730  OrthancPluginResourceType resourceType,
731  uint64_t since,
732  uint64_t limit);
733 
734  OrthancPluginErrorCode (*getDatabaseVersion) (
735  /* outputs */
736  uint32_t* version,
737  /* inputs */
738  void* payload);
739 
740  OrthancPluginErrorCode (*upgradeDatabase) (
741  /* inputs */
742  void* payload,
743  uint32_t targetVersion,
744  OrthancPluginStorageArea* storageArea);
745 
746  OrthancPluginErrorCode (*clearMainDicomTags) (
747  /* inputs */
748  void* payload,
749  int64_t id);
750 
751  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
752  OrthancPluginErrorCode (*getAllInternalIds) (
753  /* outputs */
755  /* inputs */
756  void* payload,
757  OrthancPluginResourceType resourceType);
758 
759  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
760  OrthancPluginErrorCode (*lookupIdentifier3) (
761  /* outputs */
763  /* inputs */
764  void* payload,
765  OrthancPluginResourceType resourceType,
766  const OrthancPluginDicomTag* tag,
768 
769 
774  /* Output: Use OrthancPluginDatabaseAnswerInt64() */
775  OrthancPluginErrorCode (*lookupIdentifierRange) (
776  /* outputs */
778  /* inputs */
779  void* payload,
780  OrthancPluginResourceType resourceType,
781  uint16_t group,
782  uint16_t element,
783  const char* start,
784  const char* end);
785 
786 
791  /* Ouput: Use OrthancPluginDatabaseAnswerMatchingResource */
792  OrthancPluginErrorCode (*lookupResources) (
793  /* outputs */
795  /* inputs */
796  void* payload,
797  uint32_t constraintsCount,
798  const OrthancPluginDatabaseConstraint* constraints,
799  OrthancPluginResourceType queryLevel,
800  uint32_t limit,
801  uint8_t requestSomeInstance);
802 
803  OrthancPluginErrorCode (*createInstance) (
804  /* output */
805  OrthancPluginCreateInstanceResult* output,
806  /* inputs */
807  void* payload,
808  const char* hashPatient,
809  const char* hashStudy,
810  const char* hashSeries,
811  const char* hashInstance);
812 
813  OrthancPluginErrorCode (*setResourcesContent) (
814  /* inputs */
815  void* payload,
816  uint32_t countIdentifierTags,
817  const OrthancPluginResourcesContentTags* identifierTags,
818  uint32_t countMainDicomTags,
819  const OrthancPluginResourcesContentTags* mainDicomTags,
820  uint32_t countMetadata,
821  const OrthancPluginResourcesContentMetadata* metadata);
822 
823  /* Ouput: Use OrthancPluginDatabaseAnswerString */
824  OrthancPluginErrorCode (*getChildrenMetadata) (
825  /* outputs */
827  /* inputs */
828  void* payload,
829  int64_t resourceId,
830  int32_t metadata);
831 
832  OrthancPluginErrorCode (*getLastChangeIndex) (
833  /* outputs */
834  int64_t* target,
835  /* inputs */
836  void* payload);
837 
838  OrthancPluginErrorCode (*tagMostRecentPatient) (
839  /* inputs */
840  void* payload,
841  int64_t patientId);
842 
843 
848  /* Ouput: Use OrthancPluginDatabaseAnswerMetadata */
849  OrthancPluginErrorCode (*getAllMetadata) (
850  /* outputs */
852  /* inputs */
853  void* payload,
854  int64_t resourceId);
855 
856  /* Ouput: Use OrthancPluginDatabaseAnswerString to send
857  the public ID of the parent (if the resource is not a patient) */
858  OrthancPluginErrorCode (*lookupResourceAndParent) (
859  /* outputs */
861  uint8_t* isExisting,
862  int64_t* id,
864 
865  /* inputs */
866  void* payload,
867  const char* publicId);
868 
869  } OrthancPluginDatabaseExtensions;
870 
871 /*<! @endcond */
872 
873 
874  typedef struct
875  {
877  const OrthancPluginDatabaseBackend* backend;
878  void* payload;
879  } _OrthancPluginRegisterDatabaseBackend;
880 
893  OrthancPluginContext* context,
894  const OrthancPluginDatabaseBackend* backend,
895  void* payload)
896  {
897  OrthancPluginDatabaseContext* result = NULL;
898  _OrthancPluginRegisterDatabaseBackend params;
899 
900  if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType))
901  {
902  return NULL;
903  }
904 
905  memset(&params, 0, sizeof(params));
906  params.backend = backend;
907  params.result = &result;
908  params.payload = payload;
909 
910  if (context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackend, &params) ||
911  result == NULL)
912  {
913  /* Error */
914  return NULL;
915  }
916  else
917  {
918  return result;
919  }
920  }
921 
922 
923  typedef struct
924  {
926  const OrthancPluginDatabaseBackend* backend;
927  void* payload;
928  const OrthancPluginDatabaseExtensions* extensions;
929  uint32_t extensionsSize;
930  } _OrthancPluginRegisterDatabaseBackendV2;
931 
932 
944  OrthancPluginContext* context,
945  const OrthancPluginDatabaseBackend* backend,
946  const OrthancPluginDatabaseExtensions* extensions,
947  void* payload)
948  {
949  OrthancPluginDatabaseContext* result = NULL;
950  _OrthancPluginRegisterDatabaseBackendV2 params;
951 
952  if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType))
953  {
954  return NULL;
955  }
956 
957  memset(&params, 0, sizeof(params));
958  params.backend = backend;
959  params.result = &result;
960  params.payload = payload;
961  params.extensions = extensions;
962  params.extensionsSize = sizeof(OrthancPluginDatabaseExtensions);
963 
964  if (context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackendV2, &params) ||
965  result == NULL)
966  {
967  /* Error */
968  return NULL;
969  }
970  else
971  {
972  return result;
973  }
974  }
975 
976 
977 
982 /*<! @cond Doxygen_Suppress */
983  typedef enum
984  {
985  OrthancPluginDatabaseTransactionType_ReadOnly = 1,
986  OrthancPluginDatabaseTransactionType_ReadWrite = 2,
987  OrthancPluginDatabaseTransactionType_INTERNAL = 0x7fffffff
988  } OrthancPluginDatabaseTransactionType;
989 
990 
991  typedef enum
992  {
993  OrthancPluginDatabaseEventType_DeletedAttachment = 1,
994  OrthancPluginDatabaseEventType_DeletedResource = 2,
995  OrthancPluginDatabaseEventType_RemainingAncestor = 3,
996  OrthancPluginDatabaseEventType_INTERNAL = 0x7fffffff
997  } OrthancPluginDatabaseEventType;
998 
999 
1000  typedef struct
1001  {
1002  OrthancPluginDatabaseEventType type;
1003 
1004  union
1005  {
1006  struct
1007  {
1008  /* For ""DeletedResource" and "RemainingAncestor" */
1010  const char* publicId;
1011  } resource;
1012 
1013  /* For "DeletedAttachment" */
1014  OrthancPluginAttachment attachment;
1015 
1016  } content;
1017 
1018  } OrthancPluginDatabaseEvent;
1019 
1020 
1021  typedef struct
1022  {
1027  OrthancPluginErrorCode (*readAnswersCount) (OrthancPluginDatabaseTransaction* transaction,
1028  uint32_t* target /* out */);
1029 
1030  OrthancPluginErrorCode (*readAnswerAttachment) (OrthancPluginDatabaseTransaction* transaction,
1031  OrthancPluginAttachment* target /* out */,
1032  uint32_t index);
1033 
1034  OrthancPluginErrorCode (*readAnswerChange) (OrthancPluginDatabaseTransaction* transaction,
1035  OrthancPluginChange* target /* out */,
1036  uint32_t index);
1037 
1038  OrthancPluginErrorCode (*readAnswerDicomTag) (OrthancPluginDatabaseTransaction* transaction,
1039  uint16_t* group,
1040  uint16_t* element,
1041  const char** value,
1042  uint32_t index);
1043 
1044  OrthancPluginErrorCode (*readAnswerExportedResource) (OrthancPluginDatabaseTransaction* transaction,
1045  OrthancPluginExportedResource* target /* out */,
1046  uint32_t index);
1047 
1048  OrthancPluginErrorCode (*readAnswerInt32) (OrthancPluginDatabaseTransaction* transaction,
1049  int32_t* target /* out */,
1050  uint32_t index);
1051 
1052  OrthancPluginErrorCode (*readAnswerInt64) (OrthancPluginDatabaseTransaction* transaction,
1053  int64_t* target /* out */,
1054  uint32_t index);
1055 
1056  OrthancPluginErrorCode (*readAnswerMatchingResource) (OrthancPluginDatabaseTransaction* transaction,
1057  OrthancPluginMatchingResource* target /* out */,
1058  uint32_t index);
1059 
1060  OrthancPluginErrorCode (*readAnswerMetadata) (OrthancPluginDatabaseTransaction* transaction,
1061  int32_t* metadata /* out */,
1062  const char** value /* out */,
1063  uint32_t index);
1064 
1065  OrthancPluginErrorCode (*readAnswerString) (OrthancPluginDatabaseTransaction* transaction,
1066  const char** target /* out */,
1067  uint32_t index);
1068 
1069  OrthancPluginErrorCode (*readEventsCount) (OrthancPluginDatabaseTransaction* transaction,
1070  uint32_t* target /* out */);
1071 
1072  OrthancPluginErrorCode (*readEvent) (OrthancPluginDatabaseTransaction* transaction,
1073  OrthancPluginDatabaseEvent* event /* out */,
1074  uint32_t index);
1075 
1076 
1077 
1083  OrthancPluginErrorCode (*open) (void* database);
1084 
1085  OrthancPluginErrorCode (*close) (void* database);
1086 
1087  OrthancPluginErrorCode (*destructDatabase) (void* database);
1088 
1089  OrthancPluginErrorCode (*getDatabaseVersion) (void* database,
1090  uint32_t* target /* out */);
1091 
1092  OrthancPluginErrorCode (*hasRevisionsSupport) (void* database,
1093  uint8_t* target /* out */);
1094 
1095  OrthancPluginErrorCode (*upgradeDatabase) (void* database,
1096  OrthancPluginStorageArea* storageArea,
1097  uint32_t targetVersion);
1098 
1099  OrthancPluginErrorCode (*startTransaction) (void* database,
1100  OrthancPluginDatabaseTransaction** target /* out */,
1101  OrthancPluginDatabaseTransactionType type);
1102 
1103  OrthancPluginErrorCode (*destructTransaction) (OrthancPluginDatabaseTransaction* transaction);
1104 
1105 
1111  OrthancPluginErrorCode (*rollback) (OrthancPluginDatabaseTransaction* transaction);
1112 
1114  int64_t fileSizeDelta);
1115 
1116  /* A call to "addAttachment()" guarantees that this attachment is not already existing ("INSERT") */
1117  OrthancPluginErrorCode (*addAttachment) (OrthancPluginDatabaseTransaction* transaction,
1118  int64_t id,
1119  const OrthancPluginAttachment* attachment,
1120  int64_t revision);
1121 
1122  OrthancPluginErrorCode (*clearChanges) (OrthancPluginDatabaseTransaction* transaction);
1123 
1124  OrthancPluginErrorCode (*clearExportedResources) (OrthancPluginDatabaseTransaction* transaction);
1125 
1126  OrthancPluginErrorCode (*clearMainDicomTags) (OrthancPluginDatabaseTransaction* transaction,
1127  int64_t resourceId);
1128 
1129  OrthancPluginErrorCode (*createInstance) (OrthancPluginDatabaseTransaction* transaction,
1130  OrthancPluginCreateInstanceResult* target /* out */,
1131  const char* hashPatient,
1132  const char* hashStudy,
1133  const char* hashSeries,
1134  const char* hashInstance);
1135 
1136  OrthancPluginErrorCode (*deleteAttachment) (OrthancPluginDatabaseTransaction* transaction,
1137  int64_t id,
1138  int32_t contentType);
1139 
1140  OrthancPluginErrorCode (*deleteMetadata) (OrthancPluginDatabaseTransaction* transaction,
1141  int64_t id,
1142  int32_t metadataType);
1143 
1144  OrthancPluginErrorCode (*deleteResource) (OrthancPluginDatabaseTransaction* transaction,
1145  int64_t id);
1146 
1147  /* Answers are read using "readAnswerMetadata()" */
1148  OrthancPluginErrorCode (*getAllMetadata) (OrthancPluginDatabaseTransaction* transaction,
1149  int64_t id);
1150 
1151  /* Answers are read using "readAnswerString()" */
1152  OrthancPluginErrorCode (*getAllPublicIds) (OrthancPluginDatabaseTransaction* transaction,
1153  OrthancPluginResourceType resourceType);
1154 
1155  /* Answers are read using "readAnswerString()" */
1156  OrthancPluginErrorCode (*getAllPublicIdsWithLimit) (OrthancPluginDatabaseTransaction* transaction,
1157  OrthancPluginResourceType resourceType,
1158  uint64_t since,
1159  uint64_t limit);
1160 
1161  /* Answers are read using "readAnswerChange()" */
1162  OrthancPluginErrorCode (*getChanges) (OrthancPluginDatabaseTransaction* transaction,
1163  uint8_t* targetDone /* out */,
1164  int64_t since,
1165  uint32_t maxResults);
1166 
1167  /* Answers are read using "readAnswerInt64()" */
1168  OrthancPluginErrorCode (*getChildrenInternalId) (OrthancPluginDatabaseTransaction* transaction,
1169  int64_t id);
1170 
1171  /* Answers are read using "readAnswerString()" */
1172  OrthancPluginErrorCode (*getChildrenMetadata) (OrthancPluginDatabaseTransaction* transaction,
1173  int64_t resourceId,
1174  int32_t metadata);
1175 
1176  /* Answers are read using "readAnswerString()" */
1177  OrthancPluginErrorCode (*getChildrenPublicId) (OrthancPluginDatabaseTransaction* transaction,
1178  int64_t id);
1179 
1180  /* Answers are read using "readAnswerExportedResource()" */
1181  OrthancPluginErrorCode (*getExportedResources) (OrthancPluginDatabaseTransaction* transaction,
1182  uint8_t* targetDone /* out */,
1183  int64_t since,
1184  uint32_t maxResults);
1185 
1186  /* Answer is read using "readAnswerChange()" */
1187  OrthancPluginErrorCode (*getLastChange) (OrthancPluginDatabaseTransaction* transaction);
1188 
1189  OrthancPluginErrorCode (*getLastChangeIndex) (OrthancPluginDatabaseTransaction* transaction,
1190  int64_t* target /* out */);
1191 
1192  /* Answer is read using "readAnswerExportedResource()" */
1193  OrthancPluginErrorCode (*getLastExportedResource) (OrthancPluginDatabaseTransaction* transaction);
1194 
1195  /* Answers are read using "readAnswerDicomTag()" */
1196  OrthancPluginErrorCode (*getMainDicomTags) (OrthancPluginDatabaseTransaction* transaction,
1197  int64_t id);
1198 
1199  /* Answer is read using "readAnswerString()" */
1200  OrthancPluginErrorCode (*getPublicId) (OrthancPluginDatabaseTransaction* transaction,
1201  int64_t internalId);
1202 
1203  OrthancPluginErrorCode (*getResourcesCount) (OrthancPluginDatabaseTransaction* transaction,
1204  uint64_t* target /* out */,
1205  OrthancPluginResourceType resourceType);
1206 
1207  OrthancPluginErrorCode (*getResourceType) (OrthancPluginDatabaseTransaction* transaction,
1208  OrthancPluginResourceType* target /* out */,
1209  uint64_t resourceId);
1210 
1211  OrthancPluginErrorCode (*getTotalCompressedSize) (OrthancPluginDatabaseTransaction* transaction,
1212  uint64_t* target /* out */);
1213 
1214  OrthancPluginErrorCode (*getTotalUncompressedSize) (OrthancPluginDatabaseTransaction* transaction,
1215  uint64_t* target /* out */);
1216 
1217  OrthancPluginErrorCode (*isDiskSizeAbove) (OrthancPluginDatabaseTransaction* transaction,
1218  uint8_t* target /* out */,
1219  uint64_t threshold);
1220 
1221  OrthancPluginErrorCode (*isExistingResource) (OrthancPluginDatabaseTransaction* transaction,
1222  uint8_t* target /* out */,
1223  int64_t resourceId);
1224 
1225  OrthancPluginErrorCode (*isProtectedPatient) (OrthancPluginDatabaseTransaction* transaction,
1226  uint8_t* target /* out */,
1227  int64_t resourceId);
1228 
1229  /* Answers are read using "readAnswerInt32()" */
1230  OrthancPluginErrorCode (*listAvailableAttachments) (OrthancPluginDatabaseTransaction* transaction,
1231  int64_t internalId);
1232 
1233  OrthancPluginErrorCode (*logChange) (OrthancPluginDatabaseTransaction* transaction,
1234  int32_t changeType,
1235  int64_t resourceId,
1236  OrthancPluginResourceType resourceType,
1237  const char* date);
1238 
1239  OrthancPluginErrorCode (*logExportedResource) (OrthancPluginDatabaseTransaction* transaction,
1240  OrthancPluginResourceType resourceType,
1241  const char* publicId,
1242  const char* modality,
1243  const char* date,
1244  const char* patientId,
1245  const char* studyInstanceUid,
1246  const char* seriesInstanceUid,
1247  const char* sopInstanceUid);
1248 
1249  /* Answer is read using "readAnswerAttachment()" */
1250  OrthancPluginErrorCode (*lookupAttachment) (OrthancPluginDatabaseTransaction* transaction,
1251  int64_t* revision /* out */,
1252  int64_t resourceId,
1253  int32_t contentType);
1254 
1255  /* Answer is read using "readAnswerString()" */
1256  OrthancPluginErrorCode (*lookupGlobalProperty) (OrthancPluginDatabaseTransaction* transaction,
1257  const char* serverIdentifier,
1258  int32_t property);
1259 
1260  /* Answer is read using "readAnswerString()" */
1261  OrthancPluginErrorCode (*lookupMetadata) (OrthancPluginDatabaseTransaction* transaction,
1262  int64_t* revision /* out */,
1263  int64_t id,
1264  int32_t metadata);
1265 
1266  OrthancPluginErrorCode (*lookupParent) (OrthancPluginDatabaseTransaction* transaction,
1267  uint8_t* isExisting /* out */,
1268  int64_t* parentId /* out */,
1269  int64_t id);
1270 
1271  OrthancPluginErrorCode (*lookupResource) (OrthancPluginDatabaseTransaction* transaction,
1272  uint8_t* isExisting /* out */,
1273  int64_t* id /* out */,
1274  OrthancPluginResourceType* type /* out */,
1275  const char* publicId);
1276 
1277  /* Answers are read using "readAnswerMatchingResource()" */
1278  OrthancPluginErrorCode (*lookupResources) (OrthancPluginDatabaseTransaction* transaction,
1279  uint32_t constraintsCount,
1280  const OrthancPluginDatabaseConstraint* constraints,
1281  OrthancPluginResourceType queryLevel,
1282  uint32_t limit,
1283  uint8_t requestSomeInstanceId);
1284 
1285  /* The public ID of the parent resource is read using "readAnswerString()" */
1286  OrthancPluginErrorCode (*lookupResourceAndParent) (OrthancPluginDatabaseTransaction* transaction,
1287  uint8_t* isExisting /* out */,
1288  int64_t* id /* out */,
1289  OrthancPluginResourceType* type /* out */,
1290  const char* publicId);
1291 
1292  OrthancPluginErrorCode (*selectPatientToRecycle) (OrthancPluginDatabaseTransaction* transaction,
1293  uint8_t* patientAvailable /* out */,
1294  int64_t* patientId /* out */);
1295 
1296  OrthancPluginErrorCode (*selectPatientToRecycle2) (OrthancPluginDatabaseTransaction* transaction,
1297  uint8_t* patientAvailable /* out */,
1298  int64_t* patientId /* out */,
1299  int64_t patientIdToAvoid);
1300 
1301  OrthancPluginErrorCode (*setGlobalProperty) (OrthancPluginDatabaseTransaction* transaction,
1302  const char* serverIdentifier,
1303  int32_t property,
1304  const char* value);
1305 
1306  /* In "setMetadata()", the metadata might already be existing ("INSERT OR REPLACE") */
1307  OrthancPluginErrorCode (*setMetadata) (OrthancPluginDatabaseTransaction* transaction,
1308  int64_t id,
1309  int32_t metadata,
1310  const char* value,
1311  int64_t revision);
1312 
1313  OrthancPluginErrorCode (*setProtectedPatient) (OrthancPluginDatabaseTransaction* transaction,
1314  int64_t id,
1315  uint8_t isProtected);
1316 
1317  OrthancPluginErrorCode (*setResourcesContent) (OrthancPluginDatabaseTransaction* transaction,
1318  uint32_t countIdentifierTags,
1319  const OrthancPluginResourcesContentTags* identifierTags,
1320  uint32_t countMainDicomTags,
1321  const OrthancPluginResourcesContentTags* mainDicomTags,
1322  uint32_t countMetadata,
1323  const OrthancPluginResourcesContentMetadata* metadata);
1324 
1325 
1326  } OrthancPluginDatabaseBackendV3;
1327 
1328 /*<! @endcond */
1329 
1330 
1331  typedef struct
1332  {
1333  const OrthancPluginDatabaseBackendV3* backend;
1334  uint32_t backendSize;
1335  uint32_t maxDatabaseRetries;
1336  void* database;
1337  } _OrthancPluginRegisterDatabaseBackendV3;
1338 
1339 
1340  ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDatabaseBackendV3(
1341  OrthancPluginContext* context,
1342  const OrthancPluginDatabaseBackendV3* backend,
1343  uint32_t backendSize,
1344  uint32_t maxDatabaseRetries, /* To handle "OrthancPluginErrorCode_DatabaseCannotSerialize" */
1345  void* database)
1346  {
1347  _OrthancPluginRegisterDatabaseBackendV3 params;
1348 
1349  if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType))
1350  {
1352  }
1353 
1354  memset(&params, 0, sizeof(params));
1355  params.backend = backend;
1356  params.backendSize = sizeof(OrthancPluginDatabaseBackendV3);
1357  params.maxDatabaseRetries = maxDatabaseRetries;
1358  params.database = database;
1359 
1360  return context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackendV3, &params);
1361  }
1362 
1363 #ifdef __cplusplus
1364 }
1365 #endif
1366 
1367 
OrthancPluginErrorCode
Definition: OrthancCPlugin.h:197
struct _OrthancPluginContext_t OrthancPluginContext
Data structure that contains information about the Orthanc core.
struct _OrthancPluginStorageArea_t OrthancPluginStorageArea
Opaque structure that represents the storage area that is actually used by Orthanc.
Definition: OrthancCPlugin.h:1077
OrthancPluginConstraintType
Definition: OrthancCPlugin.h:885
OrthancPluginResourceType
Definition: OrthancCPlugin.h:704
Definition: OrthancCPlugin.h:201
struct _OrthancPluginDatabaseTransaction_t OrthancPluginDatabaseTransaction
Definition: OrthancCDatabasePlugin.h:52
OrthancPluginDatabaseContext * OrthancPluginRegisterDatabaseBackend(OrthancPluginContext *context, const OrthancPluginDatabaseBackend *backend, void *payload)
Definition: OrthancCDatabasePlugin.h:892
struct _OrthancPluginDatabaseContext_t OrthancPluginDatabaseContext
Definition: OrthancCDatabasePlugin.h:44
OrthancPluginDatabaseContext * OrthancPluginRegisterDatabaseBackendV2(OrthancPluginContext *context, const OrthancPluginDatabaseBackend *backend, const OrthancPluginDatabaseExtensions *extensions, void *payload)
Definition: OrthancCDatabasePlugin.h:943
OrthancPluginIdentifierConstraint
Definition: OrthancCPlugin.h:870