pythondicompynetdicom

Get called_/calling_ae_title


I'm implementing SCP and I'm not sure how to get calling_/called_ae_title correctly. I'd like to get called_/calling_ae_title during connection(client sending DICOM image) on the server side. I don't enforce called_ae_title(ae.require_called_aet = False), but set default AE title in SCP. I'd like to use the called_/calling_ae_title for audit purpose. So, what I can see from the debug log from pytnetdicom SCP that this information is available in the A-ASSOCIATE-RQ PDU

D: Request Parameters:
D: ======================= INCOMING A-ASSOCIATE-RQ PDU ========================
D: Their Implementation Class UID:      1.2.276.0.7230010.3.0.3.6.1
D: Their Implementation Version Name:   OSIRIX_361
D: Application Context Name:    1.2.840.10008.3.1.1.1
D: Calling Application Name:    NO_CLIENT       
D: Called Application Name:     PYDS            
D: Their Max PDU Receive Size:  16384
D: Presentation Context:

According to this document https://pydicom.github.io/pynetdicom/dev/reference/generated/pynetdicom.pdu.A_ASSOCIATE_RQ.html?highlight=calling_ae_title#pynetdicom.pdu.A_ASSOCIATE_RQ.calling_ae_title

I tried this in server side.

from pynetdicom.pdu import (A_ASSOCIATE_RQ, A_ASSOCIATE_AC)
...
...
pdu = A_ASSOCIATE_RQ()
print(type(pdu.calling_ae_title))
print(pdu.calling_ae_title)

My outputs are during connection:

 <class 'bytes'>
b'Default         '

I always got "Default" value instead of real values.

What did I do wrong? Or is it a bug? Both calling_ae_title and called_ae_title produce the same "Default" output when I call it. Many thanks!


Solution

  • When you're creating a new A_ASSOCIATE_RQ instance you're getting its default values (i.e. b'Default') because it hasn't been used in any associations.

    If you want the actual Calling AE Title used by an association requestor then information about the local and peer's association negotiation proposals is available via the Association.acceptor and Association.requestor properties:

    from pynetdicom import AE, evt
    from pynetdicom.sop_class import VerificationSOPClass
    
    def handle_requests(event):
        primitive = event.assoc.requestor.primitive
        print(type(primitive), primitive.calling_ae_title)
    
    ae = AE()
    ae.add_supported_context(VerificationSOPClass)
    ae.start_server(('', 11112), evt_handlers=[(evt.EVT_REQUESTED, handle_requests)])
    

    Where the primitive here is an A-ASSOCIATE primitive.