LAUREL BRIDGE

LaurelBridge.DCF.Examples.QuerySCU Namespace

DICOM Connectivity Framework V3.4
The QuerySCU example demonstrates how to use DCF to implement a query service class user.
Classes

  ClassDescription
Public classProgram
Basic query service class user example which should be run with the QuerySCP.
Examples

QuerySCU Sample Code
public class Program : IQueryListener
{
    private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

    private QRSCU _scu;
    private AssociationInfo _ainfo;
    private readonly bool _relationalRetrieve = true;

    /// <summary>
    /// The main entry point for QuerySCU.
    /// </summary>
    [STAThread]
    public static void Main()
    {
        Program queryScu = new Program();
        queryScu.ExecuteQuery();

        if (Debugger.IsAttached)
        {
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey();
        }
    }

    /// <summary>
    /// Execute a c-find request.
    /// </summary>
    public void ExecuteQuery()
    {
        try
        {
            _ainfo = new AssociationInfo();
            _ainfo.CallingTitle = "SCU";
            _ainfo.CalledTitle = "SCP";
            _ainfo.CalledPresentationAddress = "localhost:104";

            // Add the requested presentation context
            RequestedPresentationContext ctx = new RequestedPresentationContext(
                1,
                Uids.StudyRootQueryRetrieveInformationModelFIND,
                Uids.ELE, Uids.ILE);
            if (_relationalRetrieve)
            {
                byte[] extNeg = new byte[1];
                extNeg[0] = 1;
                ctx.SOPSpecificData = extNeg;
            }
            _ainfo.AddRequestedPresentationContext(ctx);

            // Make the SCU here
            _scu = new QRSCU(_ainfo);
            _scu.MaxReturnedResults = 100;
            _scu.QueryTimeoutSeconds = -1; // We only use the progress timer, not the absolute timer
            _scu.SendDimseTimeoutSeconds = 30;
            _scu.ReceiveDimseTimeoutSeconds = 30;
            _scu.ProgressTimeoutSeconds = 30;


            // Make the query identifier used in the find
            QRIdentifier query = new QRIdentifier();
            //Fields to query on.
            query.PatientsName = "*STEPHEN";
            query.QueryRetrieveLevel = "STUDY";

            //Fields to return.
            query.PatientId = "";
            query.PatientsSex = "";
            query.Modality = "";
            query.StudyDate = "";

            Logger.DebugFormat(LogDebugFlags.DimseIO, _scu.SessionSettings, "Query Data set is:{0}{1}", Environment.NewLine, query.DataSet);

            _scu.RequestAssociation();
            _scu.CFind(query.DataSet, this, true);
            _scu.ReleaseAssociation();

        }
        catch (Exception ex)
        {
            Console.WriteLine("Error executing query: {0}{1}{1}Please verify the Query SCP is up and running.", ex, Environment.NewLine);
        }
    }

    #region QueryListener Members
    /// <summary>
    /// This method is called at the completion of the query.
    /// </summary>
    /// <param name="status">The DIMSE status of the final response.</param>
    public virtual void QueryComplete(int status)
    {
        Logger.InfoFormat("Received queryComplete event status = {0}", status);

        switch (status)
        {

            default:
                {
                    Console.WriteLine("Operation status({0})", status);
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_SUCCESS:
                {
                    Console.WriteLine("Operation finished with no errors.");
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_CANCELED:
                {
                    Console.WriteLine("Operation was Canceled successfully");
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_WARNING:
                {
                    Console.WriteLine("Warning: some or all subops failed for C-MOVE");
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_ERROR:
                {
                    Console.WriteLine("Failure.");
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_INTERNAL_ERROR:
                {
                    Console.WriteLine("Internal Error. Association may still be connected. Aborting");

                    if (_scu.Connected)
                    {
                        _scu.AbortAssociation();
                    }
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_TIMEOUT:
                {
                    Console.WriteLine("Operation timed out");

                    if (_scu.Connected)
                    {
                        _scu.AbortAssociation();
                    }
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_SUCCESS_MAX_RETURNED_RESULTS_REACHED:
                {
                    Console.WriteLine("Success, Max Returned Results Reached");

                    if (_scu.Connected)
                    {
                        _scu.AbortAssociation();
                    }
                    break;
                }
            case QueryListenerStatus.QUERY_LISTENER_DIMSE_RECEIVE_TIMEOUT:
                {
                    Console.WriteLine("Operation DIMSE receive timed out");

                    if (_scu.Connected)
                    {
                        _scu.AbortAssociation();
                    }
                    break;
                }
        }
    }

    /// <summary>
    /// This method is called for all incoming DIMSE response messages.
    /// </summary>
    /// <param name="rsp">The DIMSE response messages.</param>
    public virtual void QueryEvent(DimseMessage rsp)
    {
        // This may be either a pending response or a final response
        Console.WriteLine("Got a reply:{0}{1}", Environment.NewLine, rsp);
    }
    #endregion
}