pynetdicom.events.Event

class pynetdicom.events.Event(assoc: Association, event: NotificationEvent | InterventionEvent, attrs: dict[str, Any] | None = None)[source]

Representation of an event.

Added in version 1.3.

Warning

Some of Event’s attributes are set dynamically when an event is triggered and are available only for a specific event. For example, the Event.context attribute is only available for events such as evt.EVT_C_ECHO, evt.EVT_C_STORE, etc. See the handler documentation for a list of what attributes are available for a given event.

assoc

The association in which the event occurred.

Type:

association.Association

timestamp

The date/time the event was created. Will be slightly before or after the actual event that this object represents.

Type:

datetime.datetime

__init__(assoc: Association, event: NotificationEvent | InterventionEvent, attrs: dict[str, Any] | None = None) None[source]

Create a new Event.

Parameters:

Methods

__init__(assoc, event[, attrs])

Create a new Event.

encoded_dataset([include_meta])

Return the encoded C-STORE dataset sent by the peer without first decoding it.

Attributes

action_information

Return an N-ACTION request's Action Information as a pydicom Dataset.

action_type

Return an N-ACTION request's Action Type ID as an int.

attribute_identifiers

Return an N-GET request's Attribute Identifier List as a list of pydicom BaseTag.

attribute_list

Return an N-CREATE request's Attribute List as a pydicom Dataset.

dataset

Return a C-STORE request's Data Set as a pydicom Dataset.

dataset_path

Return the path to the dataset when STORE_RECV_CHUNKED_DATASET is True.

event

Return the corresponding event.

event_information

Return an N-EVENT-REPORT request's Event Information as a pydicom Dataset.

event_type

Return an N-EVENT-REPORT request's Event Type ID as an int.

file_meta

Return a pydicom Dataset with the File Meta Information for a C-STORE request's Data Set.

identifier

Return a C-FIND, C-GET or C-MOVE request's Identifier as a pydicom Dataset.

is_cancelled

Return True if a C-CANCEL request has been received.

message_id

Return a DIMSE service request's Message ID as int.

modification_list

Return an N-SET request's Modification List as a pydicom Dataset.

move_destination

Return a C-MOVE request's Move Destination as str.

property action_information: Dataset

Return an N-ACTION request’s Action Information as a pydicom Dataset.

Because pydicom defers data parsing during decoding until an element is actually required the returned Dataset may raise an exception when any element is first accessed. It’s therefore important that proper error handling be part of any handler that uses the returned Dataset.

Returns:

The decoded Action Information dataset.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not an N-ACTION request.

property action_type: int | None

Return an N-ACTION request’s Action Type ID as an int.

Added in version 1.4.

Returns:

The request’s (0000,1008) Action Type ID value, may be None if the peer’s N-ACTION request is non-conformant.

Return type:

int or None

Raises:

AttributeError – If the corresponding event is not an N-ACTION request.

property attribute_identifiers: list[BaseTag]

Return an N-GET request’s Attribute Identifier List as a list of pydicom BaseTag.

Returns:

The (0000,1005) Attribute Identifier List tags, may be an empty list if no Attribute Identifier List was included in the C-GET request.

Return type:

list of pydicom.tag.BaseTag

Raises:

AttributeError – If the corresponding event is not an N-GET request.

property attribute_list: Dataset

Return an N-CREATE request’s Attribute List as a pydicom Dataset.

Because pydicom defers data parsing during decoding until an element is actually required the returned Dataset may raise an exception when any element is first accessed. It’s therefore important that proper error handling be part of any handler that uses the returned Dataset.

Returns:

The decoded Attribute List dataset.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not an N-CREATE request.

property dataset: Dataset

Return a C-STORE request’s Data Set as a pydicom Dataset.

Because pydicom defers data parsing during decoding until an element is actually required the returned Dataset may raise an exception when any element is first accessed. It’s therefore important that proper error handling be part of any handler that uses the returned Dataset.

Returns:

The decoded Data Set dataset.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not a C-STORE request.

property dataset_path: Path

Return the path to the dataset when STORE_RECV_CHUNKED_DATASET is True.

Added in version 2.0.

Returns:

The path to the dataset.

Return type:

pathlib.Path

encoded_dataset(include_meta: bool = True) bytes[source]

Return the encoded C-STORE dataset sent by the peer without first decoding it.

Added in version 2.1.

Examples

Retrieve the encoded dataset as sent by the peer:

def handle_store(event: pynetdicom.events.Event) -> int:
    stream: bytes = event.encoded_dataset(include_meta=False)

    return 0x0000

Write the encoded dataset to file in the DICOM File Format without having to first decode it:

def handle_store(event: pynetdicom.events.Event, dst: pathlib.Path) -> int:
    with dst.open("wb") as f:
        f.write(event.encoded_dataset())

    return 0x0000
Parameters:

include_meta (bool, optional) – If True (default) then include the encoded DICOM preamble, prefix and file meta information with the returned bytestream.

Returns:

The encoded dataset as sent by the peer, with or without the file meta information.

Return type:

bytes

Raises:

AttributeError – If the corresponding event is not a C-STORE request.

property event: NotificationEvent | InterventionEvent

Return the corresponding event.

Added in version 1.4.

Returns:

The corresponding event as a namedtuple.

Return type:

events.InterventionEvent or events.NotificationEvent

property event_information: Dataset

Return an N-EVENT-REPORT request’s Event Information as a pydicom Dataset.

Because pydicom defers data parsing during decoding until an element is actually required the returned Dataset may raise an exception when any element is first accessed. It’s therefore important that proper error handling be part of any handler that uses the returned Dataset.

Returns:

The decoded Event Information dataset.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not an N-EVENT-REPORT request.

property event_type: int | None

Return an N-EVENT-REPORT request’s Event Type ID as an int.

Added in version 1.4.

Returns:

The request’s (0000,1002) Event Type ID value, may be None if the peer’s N-EVENT-REPORT request is non-conformant.

Return type:

int or None

Raises:

AttributeError – If the corresponding event is not an N-EVENT-REPORT request.

property file_meta: FileMetaDataset

Return a pydicom Dataset with the File Meta Information for a C-STORE request’s Data Set.

Contains the following File Meta Information elements:

  • (0002,0000) File Meta Information Group Length - set as 0, will be updated with the correct value during write

  • (0002,0001) File Meta Information Version - set as 0x0001

  • (0002,0002) Media Storage SOP Class UID - set from the request’s Affected SOP Class UID

  • (0002,0003) Media Storage SOP Instance UID - set from the request’s Affected SOP Instance UID

  • (0002,0010) Transfer Syntax UID - set from the presentation context used to transfer the Data Set

  • (0002,0012) Implementation Class UID - set using PYNETDICOM_IMPLEMENTATION_UID

  • (0002,0013) Implementation Version Name - set using PYNETDICOM_IMPLEMENTATION_VERSION

Examples

Add the File Meta Information to the decoded Data Set and save it to the DICOM File Format.

>>> ds = event.dataset
>>> ds.file_meta = event.file_meta
>>> ds.save_as('example.dcm', write_like_original=False)

Encode the File Meta Information in a new file and append the encoded Data Set to it. This skips having to decode/re-encode the Data Set as in the previous example (or alternatively, just use the encoded_dataset() method).

>>> from pydicom.filewriter import write_file_meta_info
>>> with open('example.dcm', 'wb') as f:
...     f.write(b'\x00' * 128)
...     f.write(b'DICM')
...     write_file_meta_info(f, event.file_meta)
...     f.write(event.request.DataSet.getvalue())
Returns:

The File Meta Information suitable for use with the decoded C-STORE request’s Data Set.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not a C-STORE request.

property identifier: Dataset

Return a C-FIND, C-GET or C-MOVE request’s Identifier as a pydicom Dataset.

Because pydicom defers data parsing during decoding until an element is actually required the returned Dataset may raise an exception when any element is first accessed. It’s therefore important that proper error handling be part of any handler that uses the returned Dataset.

Returns:

The decoded Identifier dataset.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not a C-FIND, C-GET or C-MOVE request.

property is_cancelled: bool

Return True if a C-CANCEL request has been received.

Returns:

If this event corresponds to a C-FIND, C-GET or C-MOVE request being received by a Service Class then returns True if a C-CANCEL request with a Message ID Being Responded To parameter value corresponding to the Message ID of the service request has been received. If no such C-CANCEL request has been received or if the event is not a C-FIND, C-GET or C-MOVE request then returns False.

Return type:

bool

property message_id: int

Return a DIMSE service request’s Message ID as int.

Added in version 1.5.

Returns:

The request’s (0000,0110) Message ID value.

Return type:

int

Raises:

AttributeError – If the corresponding event is not one of the DIMSE service requests.

property modification_list: Dataset

Return an N-SET request’s Modification List as a pydicom Dataset.

Because pydicom defers data parsing during decoding until an element is actually required the returned Dataset may raise an exception when any element is first accessed. It’s therefore important that proper error handling be part of any handler that uses the returned Dataset.

Returns:

The decoded Modification List dataset.

Return type:

pydicom.dataset.Dataset

Raises:

AttributeError – If the corresponding event is not an N-SET request.

property move_destination: str | None

Return a C-MOVE request’s Move Destination as str.

Added in version 1.4.

Changed in version 2.0: Changed to return str and trailing spaces removed.

Returns:

The request’s (0000,0600) Move Destination value, without any trailing padding spaces. May be None if the peer’s C-MOVE request is non-conformant.

Return type:

str or None

Raises:

AttributeError – If the corresponding event is not a C-MOVE request.