PDU Types

Module contains implementation of the DICOM Protocol Data Units (or PDU for short). Each PDU is represented by class that follows the simple interface that has only two methods:

  • encode - method that transforms PDU into raw byte string
  • decode - factory method that transforms raw byte string to PDU instance

In addition to PDUs, several items and sub-items classes can be found in this module. These classes are:

The rest sub-items for User Data Information Item can be found at User Data Sub-items.

class netdicom2.pdu.AAssociateRqPDU(called_ae_title, calling_ae_title, variable_items, protocol_version=1, reserved1=0, reserved2=0, reserved3=None)

This class represents the A-ASSOCIATE-RQ PDU

Refer to DICOM PS3.8 9.3.2 for A-ASSOCIATE-RQ structure and fields

pdu_type = 1

PDU Type

class netdicom2.pdu.AAssociateAcPDU(called_ae_title, calling_ae_title, variable_items, protocol_version=1, reserved1=0, reserved2=0, reserved3=None)

This class represents the A-ASSOCIATE-AC PDU

Refer to DICOM PS3.8 9.3.3 for A-ASSOCIATE-AC structure and fields

pdu_type = 2

PDU Type

class netdicom2.pdu.AAssociateRjPDU(result, source, reason_diag, reserved1=0, reserved2=0)

This class represents the A-ASSOCIATE-RJ PDU (PS 3.8 9.3.4)

You can look up possible values for fields in DICOM standard (referenced above) or in documentation for AssociationRejectedError

Parameters:
  • result – Result PDU field. (unsigned byte)
  • source – Source PDU field (unsigned byte)
  • reason_diag – Reason/Diag. PDU field (unsigned byte)
  • reserved1 – Reserved field, defaults to 0 (unsigned byte)
  • reserved2 – Reserved field, defaults to 0 (unsigned byte)
pdu_type = 3

PDU Type

pdu_length = 4

This PDU has fixed length of 4 bytes

encode()

Converts PDU class to its binary representation

Returns:PDU as a string of bytes
classmethod decode(rawstring)

Factory method. Decodes A-ASSOCIATE-RJ PDU instance from raw string.

Parameters:rawstring – rawstring containing binary representation of the A-ASSOCIATE-RJ PDU
Returns:decoded PDU
static total_length()

Returns PDU total length.

This PDU has a fixed length of 10, so method always returns 10 regardless of specific instance

Returns:PDU total length
class netdicom2.pdu.PDataTfPDU(data_value_items, reserved=0)

This class represents the P-DATA-TF PDU (as described in PS 3.8 9.3.5).

pdu_type = 4

PDU Type

classmethod decode(rawstring)

Factory method. Decodes P-DATA-TF PDU instance from raw string.

Parameters:rawstring – rawstring containing binary representation of the P-DATA-TF PDU
Returns:decoded PDU
class netdicom2.pdu.AReleasePDUBase(reserved1=0, reserved2=0)

Base class for the A-RELEASE-* PDUs.

pdu_length = 4

Association Release PDUs have fixed length of 4 bytes

classmethod decode(rawstring)

Factory method. Decodes A-RELEASE-* PDU instance from raw string.

Parameters:rawstring – rawstring containing binary representation of the A-RELEASE-* PDU
Returns:decoded PDU
static total_length()

Returns PDU total length.

This PDU has a fixed length of 10, so method always returns 10 regardless of specific instance

Returns:PDU total length
class netdicom2.pdu.AReleaseRqPDU(reserved1=0, reserved2=0)

This class represents the A-RELEASE-RQ PDU as described in PS 3.8 9.3.6

pdu_type = 5

PDU Type

class netdicom2.pdu.AReleaseRpPDU(reserved1=0, reserved2=0)

This class represents the A-RELEASE-RP PDU as described in PS 3.8 9.3.7

pdu_type = 6

PDU Type

class netdicom2.pdu.AAbortPDU(source, reason_diag, reserved1=0, reserved2=0, reserved3=0)

This class represents the A-ABORT PDU as described in PS 3.8 9.3.8

pdu_type = 7

PDU Type

pdu_length = 4

Association Abort PDU have fixed length of 4 bytes

classmethod decode(rawstring)

Factory method. Decodes A-ABORT PDU instance from raw string.

Parameters:rawstring – rawstring containing binary representation of the A-ABORT PDU
Returns:decoded PDU
static total_length()

Returns PDU total length.

This PDU has a fixed length of 10, so method always returns 10 regardless of specific instance

Returns:PDU total length
class netdicom2.pdu.ApplicationContextItem(context_name, reserved=0)

Application Context Item (PS 3.8 9.3.2.1)

item_type = 16

PDU Item-type

classmethod decode(stream)

Decodes application context item from data stream

Parameters:stream – raw data stream
Returns:decoded item
class netdicom2.pdu.PresentationContextItemRQ(context_id, abs_sub_item, ts_sub_items, reserved1=0, reserved2=0, reserved3=0, reserved4=0)

Presentation Context Item (request) PS 3.8 9.3.2.2

item_type = 32

PDU Item-type

classmethod decode(stream)

Decodes presentation context item ‘request’ from data stream

Parameters:stream – raw data stream
Returns:decoded context item
class netdicom2.pdu.PresentationContextItemAC(context_id, result_reason, ts_sub_item, reserved1=0, reserved2=0, reserved3=0)

Presentation Context Item (response) PS 3.8 9.3.3.2

item_type = 33

PDU Item-type

classmethod decode(stream)

Decodes presentation context item ‘accepted’ from data stream

Parameters:stream – raw data stream
Returns:decoded context item
class netdicom2.pdu.AbstractSyntaxSubItem(name, reserved=0)

Abstract Syntax Sub-Item (PS 3.8 9.3.2.2.1)

Parameters:
  • name – Abstract Syntax name (UID) as byte string
  • reserved – reserved field. In most cases value should be default (0x00). Standard advises against testing this field value.
item_type = 48

Item type

classmethod decode(stream)

Decodes abstract syntax sub-item from data stream

Parameters:stream – raw data stream
Returns:decoded abstract syntax sub-item
class netdicom2.pdu.TransferSyntaxSubItem(name, reserved=0)

Transfer Syntax Sub-Item (PS 3.8 9.3.2.2.2)

Parameters:
  • name – Transfer Syntax name (UID) as byte string
  • reserved – reserved field. In most cases value should be default (0x00). Standard advises against testing this field value.
item_type = 64

Item type

classmethod decode(stream)

Decodes transfer syntax sub-item from data stream

Parameters:stream – raw data stream
Returns:decoded transfer syntax sub-item
class netdicom2.pdu.UserInformationItem(user_data, reserved=0)

User Information Item (PS 3.8 9.3.2.3)

Parameters:
  • reserved – reserved field. In most cases value should be default (0x00). Standard advises against testing this field value.
  • user_data

    list containing the following:

    • one MaximumLengthSubItem
    • zero or more raw strings encoding user data items
classmethod decode(stream)

Decodes user information item from data stream

Parameters:stream – raw data stream
Returns:decoded user information item