Listening to changes

I am currently exploring Orthanc’s Python plugin and its event subscription capabilities as mentioned in the documentation (Listening to Changes). However, I couldn’t find a comprehensive list of all available events that Orthanc listens to, such as the STABLE_STUDY event.

Does anyone have a complete list of events that can be subscribed to? Additionally, is there an event like DELETE_STUDY that allows listening for study deletion events? If so, I’d appreciate any insights on how to use it.

Hello,

Here is the corresponding excerpt from the source code.

  /**
   * The supported types of changes that can be signaled to the change callback.
   * @ingroup Callbacks
   **/
  typedef enum
  {
    OrthancPluginChangeType_CompletedSeries = 0,    /*!< Series is now complete */
    OrthancPluginChangeType_Deleted = 1,            /*!< Deleted resource */
    OrthancPluginChangeType_NewChildInstance = 2,   /*!< A new instance was added to this resource */
    OrthancPluginChangeType_NewInstance = 3,        /*!< New instance received */
    OrthancPluginChangeType_NewPatient = 4,         /*!< New patient created */
    OrthancPluginChangeType_NewSeries = 5,          /*!< New series created */
    OrthancPluginChangeType_NewStudy = 6,           /*!< New study created */
    OrthancPluginChangeType_StablePatient = 7,      /*!< Timeout: No new instance in this patient */
    OrthancPluginChangeType_StableSeries = 8,       /*!< Timeout: No new instance in this series */
    OrthancPluginChangeType_StableStudy = 9,        /*!< Timeout: No new instance in this study */
    OrthancPluginChangeType_OrthancStarted = 10,    /*!< Orthanc has started */
    OrthancPluginChangeType_OrthancStopped = 11,    /*!< Orthanc is stopping */
    OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */
    OrthancPluginChangeType_UpdatedMetadata = 13,   /*!< Some user-defined metadata has changed for this resource */
    OrthancPluginChangeType_UpdatedPeers = 14,      /*!< The list of Orthanc peers has changed */
    OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */
    OrthancPluginChangeType_JobSubmitted = 16,      /*!< New Job submitted */
    OrthancPluginChangeType_JobSuccess = 17,        /*!< A Job has completed successfully */
    OrthancPluginChangeType_JobFailure = 18,        /*!< A Job has failed */

    _OrthancPluginChangeType_INTERNAL = 0x7fffffff
  } OrthancPluginChangeType;

HTH

2 Likes

And their equivalent in python

2 Likes

@benjamin.golinvaux @alainmazy
Thank you for your response and for sharing the relevant excerpt from the source code, I appreciate your help!

Hello,

PyOrthanc contains a handy skeleton for the Python plugin SDK for the auto-complete. For example the ChangeType enum.

A typical example of usage would be

from pyorthanc import orthanc_sdk


def on_change(change_type: orthanc_sdk.ChangeType, level: orthanc_sdk.ResourceType, resource: str) -> None:
    if changeType == orthanc_sdk.ChangeType.ORTHANC_STARTED:
        with open('/tmp/sample.dcm', 'rb') as f:
            orthanc.RestApiPost('/instances', f.read())

    elif changeType == orthanc_sdk.ChangeType.ORTHANC_STOPPED:
        print('Stopped')

    elif changeType == orthanc_sdk.ChangeType.NEW_INSTANCE:
        print('A new instance was uploaded: %s' % resource)


orthanc_sdk.RegisterOnChangeCallback(on_change)

Note that importing from pyorthanc import orthanc_sdk will import the real Orthanc’s Python Plugin SDK when using as a script in Orthanc. So you’ll be able to use the script with the pyorthanc’s orthanc_sdk as is.

When executing outside Orthanc, it’ll be only a mock (the functions will do nothing, but it is useful for development with the autocompletion).

The details of the implementation are here.

3 Likes

@gacou54 Thank you for your response, this is helpful