PDU Types (pdu)¶
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 stringdecode
- 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 (userdataitems).
-
class
pynetdicom2.pdu.
AAssociatePDUBase
(called_ae_title, calling_ae_title, variable_items, protocol_version=1, reserved1=0, reserved2=0, reserved3=None)¶ Base class for A-ASSOCIATE-RQ and A-ASSOCIATE-AC PDUs
Variables: - called_ae_title – called AE Title (remote AET)
- calling_ae_title – calling AE Title (local AET)
- variable_items – list of various variable items
- protocol_version – protocol version, should be 1
- reserved1 – reserved field, defaults 0
- reserved2 – reserved field, defaults 0
- reserved3 – reserved field, defaults eight 0
-
pdu_length
¶ PDU length without the header
Returns: PDU length Return type: int
-
encode
()¶ Encodes PDU into bytes
Returns: encoded PDU Return type: bytes
-
classmethod
decode
(raw_bytes)¶ Factory method. Decodes A-ASSOCIATE-RQ PDU instance from raw string.
Parameters: raw_bytes – bytes containing binary representation of the A-ASSOCIATE-RQ PDU Returns: decoded PDU
-
total_length
()¶ Returns total PDU length including the header
Returns: total PDU length Return type: int
-
class
pynetdicom2.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
pynetdicom2.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
pynetdicom2.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
Variables: - 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
pynetdicom2.pdu.
PDataTfPDU
(data_value_items, reserved=0)¶ This class represents the P-DATA-TF PDU (as described in PS 3.8 9.3.5).
Variables: - reserved – reserved field, defaults 0
- data_value_items – list of one of more PresentationDataValueItem
-
pdu_type
= 4¶ PDU Type
-
pdu_length
¶ PDU length without the header
Returns: PDU length Return type: int
-
encode
()¶ Encodes PDataTfPDU into bytes
Returns: encoded PDU Return type: bytes
-
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
-
total_length
()¶ Returns total PDU length including the header
Returns: total PDU length Return type: int
-
class
pynetdicom2.pdu.
AReleasePDUBase
(reserved1=0, reserved2=0)¶ Base class for the A-RELEASE-* PDUs.
Variables: - reserved1 – reserved field, defaults 0
- reserved2 – reserved field, defaults 0
-
pdu_length
= 4¶ Association Release PDUs have fixed length of 4 bytes
-
encode
()¶ Encodes PDU into bytes
Returns: encoded PDU Return type: 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
pynetdicom2.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
pynetdicom2.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
pynetdicom2.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
Variables: - reserved1 – reserved field, defaults 0
- reserved2 – reserved field, defaults 0
- reserved3 – reserved field, defaults 0
- reserved3 – reserved field, defaults 0
- source –
abort source:
- 0 - DICOM UL service-user (initiated abort)
- 1 - reserved
- 2 - DICOM UL service-provider (initiated abort)
- reason_diag –
Reason/Diag. value:
- 0 - reason-not-specified
- 1 - unrecognized-PDU
- 2 - unexpected-PDU
- 3 - reserved
- 4 - unrecognized-PDU parameter
- 5 - unexpected-PDU parameter
- 6 - invalid-PDU-parameter value
-
pdu_type
= 7¶ PDU Type
-
pdu_length
= 4¶ Association Abort PDU have fixed length of 4 bytes
-
encode
()¶ Encodes AAbortPDU into bytes
Returns: encoded PDU Return type: 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
pynetdicom2.pdu.
ApplicationContextItem
(context_name, reserved=0)¶ Application Context Item (PS 3.8 9.3.2.1)
Variables: - reserved – reserved field, defaults 0
- context_name – application context name (OID)
-
item_type
= 16¶ PDU Item-type
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
classmethod
decode
(stream)¶ Decodes application context item from data stream
Parameters: stream – raw data stream Returns: decoded item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int
-
class
pynetdicom2.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
Variables: - context_id – presentation context ID
- abs_sub_item – Abstract Syntax sub-item
- ts_sub_items – list of Transfer Syntax sub-items
- reserved1 – reserved field, defaults 0
- reserved2 – reserved field, defaults 0
- reserved3 – reserved field, defaults 0
- reserved4 – reserved field, defaults 0
-
item_type
= 32¶ PDU Item-type
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
classmethod
decode
(stream)¶ Decodes presentation context item ‘request’ from data stream
Parameters: stream – raw data stream Returns: decoded context item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int
-
class
pynetdicom2.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
Variables: - context_id –
- result_reason –
result/reason, can be one of the following:
- 0 - acceptance
- 1 - user-rejection
- 2 - no-reason (provider rejection)
- 3 - abstract-syntax-not-supported (provider rejection)
- 4 - transfer-syntaxes-not-supported (provider rejection)
- ts_sub_item – list of Transfer Syntax sub-items
- reserved1 – reserved field, defaults 0
- reserved2 – reserved field, defaults 0
- reserved3 – reserved field, defaults 0
-
item_type
= 33¶ PDU Item-type
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
classmethod
decode
(stream)¶ Decodes presentation context item ‘accepted’ from data stream
Parameters: stream – raw data stream Returns: decoded context item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int
-
class
pynetdicom2.pdu.
AbstractSyntaxSubItem
(name, reserved=0)¶ Abstract Syntax Sub-Item (PS 3.8 9.3.2.2.1)
Variables: - 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
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
classmethod
decode
(stream)¶ Decodes abstract syntax sub-item from data stream
Parameters: stream – raw data stream Returns: decoded abstract syntax sub-item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int
-
class
pynetdicom2.pdu.
TransferSyntaxSubItem
(name, reserved=0)¶ Transfer Syntax Sub-Item (PS 3.8 9.3.2.2.2)
Variables: - 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
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
classmethod
decode
(stream)¶ Decodes transfer syntax sub-item from data stream
Parameters: stream – raw data stream Returns: decoded transfer syntax sub-item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int
-
class
pynetdicom2.pdu.
UserInformationItem
(user_data, reserved=0)¶ User Information Item (PS 3.8 9.3.2.3)
Variables: - 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 User Information sub-items from User Data Sub-items (userdataitems)
- one
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
static
sub_items
(stream)¶ Reads User Information sub-items from a data stream
Parameters: stream (IO[bytes]) – raw data stream Raises: exceptions.PDUProcessingError – [description] Yield: User Information sub-item
-
classmethod
decode
(stream)¶ Decodes user information item from data stream
Parameters: stream – raw data stream Returns: decoded user information item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int
-
class
pynetdicom2.pdu.
PresentationDataValueItem
(context_id, data_value)¶ Presentation Data Value Item (PS 3.8 9.3.5.1)
Variables: - context_id – presentation context ID
- data_value – item value (bytes)
-
item_length
¶ Item length, excluding the header
Returns: item length Return type: int
-
encode
()¶ Encodes item into bytes
Returns: encoded item Return type: bytes
-
classmethod
decode
(stream)¶ Decodes presentation data value item from data stream
Presentation data value is left in raw string format. The Application Entity is responsible for dealing with it.
Parameters: stream – raw data stream Returns: decoded presentation data value item
-
total_length
()¶ Total item length, including the header
Returns: total item length Return type: int