Contexts and the Association Requestor#
When acting as the association requestor (usually the SCU), you must propose presentation contexts to be negotiated by the association process. There are a couple of simple rules for these:
There must be at least 1 and up to 128 proposed presentation contexts.
You can use the same abstract syntax in more than one presentation context.
Each presentation context must have at least one transfer syntax.
In pynetdicom this is accomplished through one of the following methods:
Setting the
AE.requested_contexts
attribute directly using a list ofPresentationContext
items.from pynetdicom import AE, build_context from pynetdicom.sop_class import Verification ae = AE() ae.requested_contexts = [build_context(Verification)] assoc = ae.associate("127.0.0.1", 11112)
Using the
AE.add_requested_context()
method to add a newPresentationContext
to theAE.requested_contexts
attribute.from pynetdicom import AE from pynetdicom.sop_class import Verification ae = AE() ae.add_requested_context(Verification) assoc = ae.associate("127.0.0.1", 11112)
Supplying a list of
PresentationContext
items toAE.associate()
via the contexts keyword parameter.from pynetdicom import AE, build_context from pynetdicom.sop_class import Verification ae = AE() requested = [build_context(Verification)] assoc = ae.associate("127.0.0.1", 11112, contexts=requested)
The abstract syntaxes you propose should match the SOP Class or Meta SOP Class that corresponds to the service you wish to use. For example, if you’re intending to use the storage service then you’d propose one or more abstract syntaxes from the corresponding SOP Class UIDs.
The transfer syntaxes you propose for each abstract syntax should match the transfer syntax of the data you wish to send. For example, if you have a CT Image Storage dataset with a (0002,0010) Transfer Syntax UID value of 1.2.840.10008.1.2.4.50 (JPEG Baseline) then you won’t be able to send it unless you propose (and get accepted) a presentation context with a matching transfer syntax.
Note
Uncompressed and deflated transfer syntaxes are the exception to this rule as pydicom is able to freely convert between these (provided the endianness remains the same).
If you have data encoded in a variety of transfer syntaxes then you can propose multiple presentation contexts with the same abstract syntax but different transfer syntaxes:
>>> from pydicom.uid import ImplicitVRLittleEndian, JPEGBaseline
>>> from pynetdicom import AE
>>> from pynetdicom.sop_class import CTImageStorage
>>> ae = AE()
>>> ae.add_requested_context(CTImageStorage, ImplicitVRLittleEndian)
>>> ae.add_requested_context(CTImageStorage, JPEGBaseline)
>>> for cx in ae.requested_contexts:
... print(cx)
...
Abstract Syntax: CT Image Storage
Transfer Syntax(es):
=Implicit VR Little Endian
Abstract Syntax: CT Image Storage
Transfer Syntax(es):
=JPEG Baseline (Process 1)
Provided both contexts get accepted then it becomes possible to transfer CT
Image datasets encoded in JPEG Baseline and/or Implicit VR Little Endian.
Alternatively it may be necessary to
decompress()
datasets prior to sending (as
Implicit VR Little Endian should always be accepted).