Application Entities

netdicom2.applicationentity.write_meta(fp, command_set, ts)

Writes file meta information.

This is a small utility function that can be useful when overriding get_file() method of the AEBase class

Parameters:
  • fp – file or file-like object where dataset will be stored
  • command_set – command dataset of received message
  • ts – dataset transfer syntax
class netdicom2.applicationentity.AEBase(supported_ts, max_pdu_length)

Base Application Entity class.

This class is intended for sub-classing and should not be used directly. Use ClientAE or AE instead

Class provides common API for application entities, such as:
  • requesting association
  • adding services as SCU
  • handful of useful public properties (presentation context definition list, supported transfer syntax list, maximum pdu size)
Variables:
  • supported_ts – Set of transfer syntaxes supported by this application entity. This attribute defaults to default_ts.
  • timeout – Connection timeout in seconds. Default value is 15.
  • max_pdu_length – Maximum size of PDU in bytes.
  • supported_scu – Dictionary that maps Abstract syntax UIDs to specific services that are support in SCU role. This attribute is populated by adding services using add_scu() method. This attribute is intended for read-only use by class clients.
  • supported_scp – Dictionary that maps Abstract syntax UIDs to specific services that are support in SCP role. This attribute is populated by adding services using add_scp() method of the full AE class This attribute is intended for read-only use by class clients.
default_ts = ['1.2.840.10008.1.2.1', '1.2.840.10008.1.2', '1.2.840.10008.1.2.2']

Default list of supported transfer syntaxes.

add_scu(service, sop_classes=None)

Adds service as SCU to the AE.

Presentation context definition list is updated based on SOP Class UIDs that are handled by this service. Calls to this method could be chained, so you can add multiple services in one statement.

Parameters:service – DICOM service

:param sop_classes overrides list of SOP Class UIDs provided by the service

update_context_def_list(sop_classes, store_in_file=False)

Updates presentation context definition list.

Parameters:
  • sop_classes – new SOP Class UIDs that should be added to presentation contexts definition list
  • store_in_file – indicates if incoming datasets for these SOP Classes should be stored in file.
copy_context_def_list()

Makes a shallow copy of presentation context definition list.

Note

This method is tread-safe.

Returns:copy of the presentation context definition list.
request_association(**kwds)

Requests association to a remote application entity.

Request is formed based on configuration dictionary that is passed in. Currently supported parameters are:

  • aet - remote AE title
  • address - remote AE IP address
  • port - remote AE port
  • username - username for DICOM authentication
  • password - password for DICOM authentication
Parameters:remote_ae – dictionary that contains remote AE configuration.
get_file(context, command_set)

Method is used by association to get file-like object to store dataset.

Method is only called when service SOP Class UID is present in self.store_in_file set. Method itself does not own the file object. So it’s service implementation responsibility to close the file after it’s done when handling received message. Default implementation is based on temporary file. User may choose to override this method to provide a permanent storage for dataset.

Parameters:
  • context – presentation context
  • command_set – command dataset of the received message
Returns:

file where association can store received dataset and file starting position.

on_association_request(assoc)

Extra processing of the association request.

Default implementation of the method does nothing and thus accepts all incoming association requests. If association should be rejected user should override this method in a sub-class and raise AssociationRejectedError when appropriate

Parameters:assoc – association request parameters
on_association_response(response)

Extra processing for association response.

Default implementation does nothing.

Parameters:response – response received from remote AE
on_receive_echo(context)

Default handling of C-ECHO command. Always returns SUCCESS code

User should override this method in sub-class to provide custom handling of the command.

Parameters:context – presentation context (contains ID, SOP Class UID and Transfer Syntax)
Returns:status that should be sent in response
on_receive_store(context, ds)

Default handling of C-STORE command. Always returns ELEMENT_DISCARDED code.

User should override this method in sub-class to provide custom handling of the command

Parameters:
  • context – presentation context (contains ID, SOP Class UID and Transfer Syntax)
  • ds – dataset that should be stored
Returns:

status code

on_receive_find(context, ds)

Default handling of C-FIND command. Returns empty iterator.

Parameters:
  • context – presentation context (contains ID, SOP Class UID and Transfer Syntax)
  • ds – dataset with C-FIND parameters
Returns:

iterator that returns tuples: (<result dataset>, <status code>)

on_receive_move(context, ds, destination)

Default handling of C-MOVE command. Returns empty empty values

Parameters:
  • context – presentation context (contains ID, SOP Class UID and Transfer Syntax)
  • ds – dataset with C-MOVE parameters
  • destination – C-MOVE command destination
Returns:

tuple: remote AE parameters, number of operations and iterator that will return datasets for moving

on_commitment_request(remote_ae, uids)

Handle storage commitment request.

Method should return three values:
  • remote AE parameters (IP address, port, etc.)
  • iterable or None for successfully stored SOP Instance UIDs
  • iterable or None for failed SOP Instance UIDs

Default implementation is not provided. Method raises exceptions.EventHandlingError

Parameters:
  • remote_ae – remote AE title
  • uids – iterable of tuples (SOP Class UID, SOP Instance UID)
on_commitment_response(transaction_uid, success, failure)

Handle storage commitment response.

Default implementation is not provided. Method raises exceptions.EventHandlingError

Parameters:
  • transaction_uid – Transaction UID
  • success – iterable of tuples (SOP Class UID, SOP Instance UID)
  • failure – iterable of tuples (SOP Class UID, SOP Instance UID, Failure Reason
class netdicom2.applicationentity.ClientAE(ae_title, supported_ts=None, max_pdu_length=65536)

Simple SCU-only application entity.

Use this class if you only intend to use SCUs service roles. This AE won’t handle any incoming connections.

Parameters:
  • ae_title – AE title (up to 16 characters)
  • supported_ts – list of supported transfer syntaxes. If you are using Storage or Q/R C-GET services be sure to add only transfer syntax of the expected dataset.
  • max_pdu_length – maximum PDU length in bytes (defaults to 64kb).
class netdicom2.applicationentity.AE(ae_title, port, supported_ts=None, max_pdu_length=65536)

Represents a DICOM application entity based on SocketServer.ThreadingTCPServer

Unlike ClientAE this one is fully functional application entity that can take on both SCU and SCP roles. For convenience AE supports context manager interface so it can be used like this:

from netdicom2.sopclass import verification_scp

ae = AE('AET', 104).add_scp(verification_scp)
with ae:
    pass  # AE is running and accepting connection.

Upon exiting context AE is stopped.

Parameters:
  • ae_title – AE title (up to 16 characters)
  • port – port that AE listens on for incoming connection
  • supported_ts – list of transfer syntaxes supported by AE
  • max_pdu_length – maximum PDU length in bytes (defaults to 64kb).
add_scp(service)

Adds service as SCP to the AE.

Method is similar to add_scu method of the AEBase base class.

Parameters:service – DICOM service.
quit()

Stops AE from accepting any more connections.