DICOM PING

This was my first venture into A.I. programming care of Chat GTP . I like to think of this like a next generation Google and I think Microsoft do as they’re busy integrating it with BING.
DICOM is the bread and butter of the medical imaging industry and has its own crazy standards for getting encapsulated data from A to B. A dicom ping is a network and application based test for the presence of a dicom server. I thought I’d lay out the code in the page as its pretty cool.

import argparse
import pydicom
from pynetdicom import AE

def dicom_ping(ae_title, host, port, calling_ae_title):
    """Function to perform a DICOM Ping"""
    ae = AE(ae_title=calling_ae_title)
    ae.add_requested_context('1.2.840.10008.1.1')
    ae.acse_timeout = 5
    ae.dimse_timeout = 5
    ae.network_timeout = 5
    assoc = ae.associate(host, port, ae_title=ae_title)
    if assoc.is_established:
        status = assoc.send_c_echo()
        if status:
            print("DICOM Ping successful!")
            return True
        else:
            print("DICOM Ping failed")
            return False
    else:
        print("Association failed to establish")
        return False

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="DICOM Ping using Python and PyDicom")
    parser.add_argument("target_ae_title", help="Target AE Title")
    parser.add_argument("target_host", help="Target host IP address")
    parser.add_argument("target_port", type=int, help="Target host port")
    parser.add_argument("calling_ae_title", help="Calling AE Title")
    args = parser.parse_args()

    result = dicom_ping(args.target_ae_title, args.target_host, args.target_port, args.calling_ae_title)
    if result:
        print("DICOM Ping was successful!")
    else:
        print("DICOM Ping failed")

The program is called by python and needs the following arguments to work
AETitle to call (16 characters upper lowercase no spaces)
Host/IP (Network hostname or IP address
Port number (network port number to connect to)
MyAEtitle (16 characters upper lowercase no spaces)

Similar Posts