How to Query PACS and get Images related to patients

5,520 views
Skip to first unread message

Rashad Reyes

unread,
Jan 11, 2013, 10:57:48 AM1/11/13
to fo-d...@googlegroups.com
Hey,

I'm looking at using this C# library. All I need to do is get a group of images related to a patient.
 
Here are the attributes that I have
 
//example dummy info but I have real info
var AccessionNumber = "BR1222171901";
var SeriesNumber = "71102100";
var InstanceUID = "1.2.840.113681.184214509.1456818185.4592.665";
 
Here's how I'm trying to do it:
 
var client = new DicomClient();
client.NegotiateAnsynOps();
var request = new DicomCMoveRequest(CalledAE, InstanceUID, SeriesNumber);
client.AddRequest(request);
client.Send(Host, 104, false, CallingAE, CalledAE);
 
From this point is something supposed to happen?
 
Ideally I'd love a collection of Images somewhere or something.
 
Can anyone help?

Thanks!
 
 

Rashad Reyes

unread,
Jan 11, 2013, 12:48:01 PM1/11/13
to fo-d...@googlegroups.com
Okay after reading some posts, I've modified my code as follows:
 
var fr = DicomCFindRequest.CreatePatientQuery(PatientID);
var mr = new DicomCMoveRequest(CallingAE, InstanaceUID);
mr.OnResponseReceived = MoveFinished;
 
var client = new DicomClient();
client.NegotiateAsyncOps(2,0);
client.AddRequest(fr);
client.AddRequest(mr);
client.BeginSend(Host,104, false, CallingAE, CalledAE, Done, client);
 
public void MoveFinished(DicomCMoveRequest request, DicomCMoveResponse response)
{
     //.... No code yet but inside response only a command dataset with 9 items, unsigned ints.. no images anywhere
}
 
public void Done(IAsyncResult result)
{
    //...Blank, just made this to get BeginSend to work? Something goes here???
}

I'm thinking I'm closer but still now images.

AgentK

unread,
Jan 11, 2013, 4:51:22 PM1/11/13
to fo-d...@googlegroups.com
Hi! I've got same problem. Here's my code:

                DicomClient client = new DicomClient();
               
var cmove = new DicomCMoveRequest("CONQUESTSRV1", seriesInfo.StudyInstanceUID, seriesInfo.SeriesInstanceUID);
                cmove
.OnResponseReceived += (DicomCMoveRequest request, DicomCMoveResponse response) =>
               
{
// I think that response.DataSet
// must be equal to requested DICOM file, but it is null.
               
};
                client
.AddRequest(cmove);
                client
.Send(PACSServerIP, PACSServerPort, false, "SCU", "CONQUESTSRV1");
I hope we can solve this

Mahesh Dubey

unread,
Jan 12, 2013, 8:02:59 AM1/12/13
to fo-d...@googlegroups.com
Hello;

Move scu  instruct move scp to send the dataset/images to the destination ae , Destination ae is the ae title of store scp  , you will never get the actual dataset/images in the move response, you get only the status of the moved dataset/image.

Regards
Mahesh

AgentK

unread,
Jan 12, 2013, 9:09:25 AM1/12/13
to fo-d...@googlegroups.com
Thank you!
Now it works.
All what i need is to run "STORESCP" server (Dicom.CStoreSCP.exe from examples) to handle DicomCStore request.
And of course setup right config of DICOM server (i'm using Conquest for testing).

cc ko

unread,
Sep 27, 2013, 3:12:31 AM9/27/13
to fo-d...@googlegroups.com
Hello,

I read all the posts, but still don't know how to get Patient's Images.

can anyone help? Thanks

below is my code.

 DicomClient client = new DicomClient();
            
            var host = "192.168.0.3";
            var port = 104;
            var callingAE = "KK";
            var calledAE = "KK";
            var patientID = "47931333";

var cFind = DicomCFindRequest.CreateStudyQuery(patientID);
            
            cFind.OnResponseReceived += (DicomCFindRequest request, DicomCFindResponse response) =>
            {
                if (response.HasDataset)
                {
                    Console.WriteLine("C-Find Response:\n" + response.Dataset.WriteToString());
                    var instance = response.Dataset.Get<string>(Dicom.DicomTag.StudyInstanceUID);
                }
            };
            client.NegotiateAsyncOps();
            client.AddRequest(cFind);
            client.Send(host, port, false, callingAE, calledAE);

DeLe

unread,
Oct 1, 2013, 10:33:32 AM10/1/13
to fo-d...@googlegroups.com
Use your cfind to retrieve a list of study UIDs. Then perform a cmove based on those study UIDs.
 
Something like the following.
 
DicomClient client = new DicomClient();
DicomCMoveRequest request = new DicomCMoveRequest(destinationAE, studyUID);
request.OnResponseReceived = delegate(DicomCMoveRequest req, DicomCMoveResponse response)
{
 Console.WriteLine(String.Format("CMove response ({0}) {1} : Status={2}, TransferSyntax ({3}) {4}",
 response.SOPClassUID.Name, response.SOPClassUID.UID, response.Status.Description,
 response.Command.InternalTransferSyntax, response.Command.InternalTransferSyntax.UID.UID));
};
client.AddRequest(request);
try
{
 client.Send(HostName, Port, IsTLS, callingAE, CalledAE);
 Console.WriteLine("C-Move request to " + CalledAE + " completed in " + timer.ElapsedMilliseconds + " ms");
}
catch (Exception ex)
{
 Console.WriteLine("Failure sending C-Move request to " + CalledAE + ": " + ex.Message);
}

cc ko

unread,
Oct 16, 2013, 1:10:47 AM10/16/13
to fo-d...@googlegroups.com
Thanks for your response.

I tried your sample code. but response dataset is null.

Still don't know how to get what i want.

i am so frustrated

var cFind = DicomCFindRequest.CreateStudyQuery(patientID);
bool complete = false;
            DicomDataset dataset = null;
            while (complete != true)
            {

                cFind.OnResponseReceived += (DicomCFindRequest request, DicomCFindResponse response) =>
                {
                    if (response.HasDataset)
                    {
                        Console.WriteLine("C-Find Response:\n" + response.Dataset.WriteToString());
                        //var instance = response.Dataset.Get<string>(Dicom.DicomTag.StudyInstanceUID);
                        dataset = response.Dataset;
                        complete = true;
                    }
                };
                client.NegotiateAsyncOps();
                client.AddRequest(cFind);
                client.Send(host, port, false, callingAE, calledAE);
            }

            complete = false;

            while (complete != true)
            {
                var cMove = new DicomCMoveRequest(calledAE, dataset.Get<string>(Dicom.DicomTag.StudyInstanceUID));

                cMove.OnResponseReceived += (DicomCMoveRequest req, DicomCMoveResponse rep) =>
                {

                    if (rep.Completed == 4)
                    {
                        //how to get image file?
                        // rep.dataset is null
 
                    }
                    
                };

                client.AddRequest(cMove);

Gustavo Saita

unread,
Dec 12, 2013, 9:33:40 PM12/12/13
to fo-d...@googlegroups.com
Thank you Mahesh Dubey, 

So, if I can't have the images in move response, how can I have it?
How to handle a C-STORE request from server to get the images?

Thank you very much.
Best regards,

Manabu Tokunaga

unread,
Dec 16, 2013, 12:29:00 AM12/16/13
to fo-d...@googlegroups.com
Hi,

To perform a C-MOVE operation at Series Level, you need to get a hold of
  1. The Destination AE TItle of the storage service provider (most likely your PACS or workstation that receives DICOM).
  2. Study Instance UID
  3. Series Instance UID
Please note that accession numbers, series number etc would not work. Consider the UIDs like database keys that you need to specify in Select and Join statements. The following call specifically states what it needs.

public DicomCMoveRequest(string destinationAe, string studyInstanceUid, string seriesInstanceUid, DicomPriority priority = DicomPriority.Medium) 

Please also note that C-MOVE operation occurs in tandem with storing operation often by another Store-SCU thread that's working in conjunction with the C-MOVE service thread as such the Storing process has its own Calling and Called AE titles independent of the C-MOVE AEs you have used. 

Usually C-MOVE will return PENDING status messages with remaining number of  operations while sending images either each image or every so often.

It is also important to know that the Called AE (Source AE) and the Destination AE often must be registered in the destination Store SCP. This means that source AE is actually the source AE of the storage device (not the one that issuing the C-MOVE). 

Mahesh Dubey

unread,
Dec 16, 2013, 2:04:27 AM12/16/13
to fo-d...@googlegroups.com
Hello;
       (If you don't want to dig in more details of these service), Run the cstore scp and pass the AE title of the running store scp in the move request(DestinationAE), Also make sure that The AE title of store scp is configure (IP Address and Port Number ), on the move server.  You receive the images at CStoreSCP,

 If you had some kind of restriction in the configuration at c-move server, or you firewall doesn't permit you to open the  new port , Then go for C-Get.

Mahesh

Gustavo Saita

unread,
Dec 20, 2013, 8:56:19 AM12/20/13
to fo-d...@googlegroups.com
Pre-conditions:

1 Local  C-STORE SCP is started
2 Local node was registered in PACS

Then,

1  send the C-MOVE Request
2  wait for the PACS send the images to Local(using c-store scu)
3 handle the images in your C-STORE SCP implemention
4 handle the c-move progress in your C-MOVE scu  implemention 

-------------

            var server = new DicomServer<CStoreSCP>(Port);

            DicomCMoveRequest dicomCMoveRequest = new DicomCMoveRequest(Ae, studyUID, seriesUID, sOPInstanceUID);
            dicomCMoveRequest.OnResponseReceived = delegate(DicomCMoveRequest req, DicomCMoveResponse res)
            {

            };

            DicomClient client = new DicomClient();
            client.AddRequest(dicomCMoveRequest);
            client.Send(Host, Port, false, Ae, "ANY");

-----------------------

CStoreSCP class you can find here:

The images will be received at OnCStoreRequest at CStoreSCP file.

Good luck! :)

Christos Yiallouras

unread,
Oct 22, 2014, 3:30:40 PM10/22/14
to fo-d...@googlegroups.com
Hi Gustavo Saita,

I want to transfer dicom files from a DICOM server to my computer.
I execute C-Find command successfully, so i have the proper Study Instance UID.

My code is the following:

            var server = new DicomServer<CStoreSCP>(104);
         
            var cmove = new DicomCMoveRequest("SCU", txtqueryseries.Text);
            cmove.OnResponseReceived = delegate(DicomCMoveRequest rq, DicomCMoveResponse rsp)
            {
                MessageBox.Show(rq.ToString());
                MessageBox.Show(rsp.ToString());
            };


            var client = new DicomClient();
            client.AddRequest(cmove);
            client.Send("213.165.94.158", 104, false, "SCU", aetitle);

But when i execute my code i get the error shown in the attachment.
Can you help please?

Thank you very much.
Christos
error.png

Vinay Rathore

unread,
Jan 20, 2015, 10:44:58 AM1/20/15
to fo-d...@googlegroups.com
hi Mahesh

Following code i am using

 // start DICOM server on port 104

            var server = new DicomServer<CStoreSCP>(104);

            DicomClient client = new DicomClient();


            DicomCMoveRequest request = new DicomCMoveRequest("DCMNET", "1.2.840.113619.2.67.2158294438.15745010109084247.20000", DicomPriority.Medium);

            request.OnResponseReceived = MoveDelegate;

            client.NegotiateAsyncOps(2, 0);
            client.AddRequest(request);
            try
            {
                client.Send("172.16.6.151", 11112, false, "DCMNET", "DCM4CHEE");

           
                Console.WriteLine("C-Move request to");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failure sending C-Move request to");
            }



        }

        #region New Code
        public static void MoveDelegate(DicomCMoveRequest request, DicomCMoveResponse response)

        {
            Console.WriteLine(String.Format("CMove response ({0}) {1} : Status={2}, TransferSyntax ({3}) {4}",
                response.SOPClassUID.Name, response.SOPClassUID.UID, response.Status.Description,
                response.Command.InternalTransferSyntax, response.Command.InternalTransferSyntax.UID.UID));
        }


But I am getting Dataset null and Status "Pending".
Please provide me right way to get the Dicom Image .
I have Tried a lot of thing but i could not get right choice ..

khouloud yaakoubi

unread,
May 5, 2016, 5:20:57 PM5/5/16
to Fellow Oak DICOM
My year-end project concerns the    development of an information system radiography in fact I want to archive images on my machine using sonic dicom I mean I use c following entraint move and store scp c .j'execute my code on concole but no response only appeared voila mon code 
class Program
    {
        public readonly static string StoragePath = @"C:\MovedImages";
        static QueryRetrieveSCU qrClient;
        DicomDataset response = new DicomDataset();
        static void Main(string[] args)
        {

            

            //DicomCMoveRequest cmove = new DicomCMoveRequest("SCP-AE", /*" 1.2.840.113619.2.81.290.1.5744.20120622.190751"*/"12");

            //Start Store Server
             var storeServer = new DicomServer<CStoreSCP>(105);
              Console.WriteLine("Store Server 'STORESCP' started on port 105 ...");
              Console.ReadLine();
           
            DicomCMoveRequest cmove = new DicomCMoveRequest("STORESCP", "1.2.840.113619.2.81.290.1.5744.20120622.190751");
            cmove.OnResponseReceived = (DicomCMoveRequest req, DicomCMoveResponse response) =>
            {
                Console.WriteLine("CMove response ({0}) {1} : Status={2}, TransferSyntax ({3}) {4}",
                response.SOPClassUID.Name, response.SOPClassUID.UID, response.Status.Description,
                response.Command.InternalTransferSyntax, response.Command.InternalTransferSyntax.UID.UID);
                Console.ReadKey();
            };
            DicomClient client = new DicomClient();
            client.AddRequest(cmove);
            try
            { client.Send(host: "127.0.0.1", port: 104, useTls: false, callingAe: "SCU-AE", calledAe: "SCP-AE");
                Console.WriteLine("C-Move request to " );
            }


            catch (Exception ex)
{
                    Console.WriteLine("Failure sending C-Move request to "  + ex.Message);
                }
            Console.WriteLine("Sending Q/R Request from Client 'QRSCU' ...");
              qrClient = new QueryRetrieveSCU("127.0.0.1", 104, false, "SCU-AE", "SCP-AE");
             qrClient.StudiesListReceived += ResponseReceived;
              qrClient.SendStudyRequest(patientName: "XX");
          }

        private static void ResponseReceived(object sender, EventArgs e)
        {
            //Get Received List
            Console.WriteLine("Received Studies List");
            var receivedStudiesList = qrClient.GetReceivedStudiesList();
            foreach (Study study in receivedStudiesList)
            {
                Console.WriteLine(study.Patient.Name);
                foreach (Serie serie in study.Series)
                {
                    Console.WriteLine("  description " + serie.Description);
                    Console.WriteLine(" uid " + serie.StudyUID);
                    Console.WriteLine(" uid " + serie.UID);
                }
            }

            ////Get Received List as Json
            //string jsonList = qrClient.GetReceivedStudiesPageAsJson(1, 10);
            //Console.WriteLine(jsonList);

            //Query a series images
            /*    var file = DicomFile.Open(@"D:\images de type DICOM.dcm");

                var patientid = file.Dataset.Get<string>(DicomTag.PatientID);

                file.Dataset.Add(DicomTag.PatientName, "XX");*/

            // creates a new instance of DicomFile
            //  var file = file.ChangeTransferSyntax(DicomTransferSyntax.JPEGProcess14SV1);

            // file.Save(@"C:\MovedImages");
            /********************/

            // DicomDataset response = new DicomDataset();
           /* DicomFile dicomfile = new DicomFile();
            dicomfile.Save(StoragePath);
            dicomfile.ChangeTransferSyntax(DicomTransferSyntax.JPEGLSNearLossless);*/

            Serie requestedSerie = receivedStudiesList[0].Series[0];
            qrClient.QueryImages(requestedSerie);
              Console.WriteLine("Images received. ");


            Console.ReadLine();
            //  sr. Save("StoragePath");

class Program
    {
        public readonly static string StoragePath = @"C:\MovedImages";
        static QueryRetrieveSCU qrClient;
        DicomDataset response = new DicomDataset();
        static void Main(string[] args)
        {

            

            //DicomCMoveRequest cmove = new DicomCMoveRequest("SCP-AE", /*" 1.2.840.113619.2.81.290.1.5744.20120622.190751"*/"12");

            //Start Store Server
             var storeServer = new DicomServer<CStoreSCP>(105);
              Console.WriteLine("Store Server 'STORESCP' started on port 105 ...");
              Console.ReadLine();
           
            DicomCMoveRequest cmove = new DicomCMoveRequest("STORESCP", "1.2.840.113619.2.81.290.1.5744.20120622.190751");
            cmove.OnResponseReceived = (DicomCMoveRequest req, DicomCMoveResponse response) =>
            {
                Console.WriteLine("CMove response ({0}) {1} : Status={2}, TransferSyntax ({3}) {4}",
                response.SOPClassUID.Name, response.SOPClassUID.UID, response.Status.Description,
                response.Command.InternalTransferSyntax, response.Command.InternalTransferSyntax.UID.UID);
                Console.ReadKey();
            };
            DicomClient client = new DicomClient();
            client.AddRequest(cmove);
            try
            { client.Send(host: "127.0.0.1", port: 104, useTls: false, callingAe: "SCU-AE", calledAe: "SCP-AE");
                Console.WriteLine("C-Move request to " );
            }


            catch (Exception ex)
{
                    Console.WriteLine("Failure sending C-Move request to "  + ex.Message);
                }
            Console.WriteLine("Sending Q/R Request from Client 'QRSCU' ...");
              qrClient = new QueryRetrieveSCU("127.0.0.1", 104, false, "SCU-AE", "SCP-AE");
             qrClient.StudiesListReceived += ResponseReceived;
              qrClient.SendStudyRequest(patientName: "XX");
          }

        private static void ResponseReceived(object sender, EventArgs e)
        {
            //Get Received List
            Console.WriteLine("Received Studies List");
            var receivedStudiesList = qrClient.GetReceivedStudiesList();
            foreach (Study study in receivedStudiesList)
            {
                Console.WriteLine(study.Patient.Name);
                foreach (Serie serie in study.Series)
                {
                    Console.WriteLine("  description " + serie.Description);
                    Console.WriteLine(" uid " + serie.StudyUID);
                    Console.WriteLine(" uid " + serie.UID);
                }
            }

            ////Get Received List as Json
            //string jsonList = qrClient.GetReceivedStudiesPageAsJson(1, 10);
            //Console.WriteLine(jsonList);

            //Query a series images
            /*    var file = DicomFile.Open(@"D:\images de type DICOM.dcm");

                var patientid = file.Dataset.Get<string>(DicomTag.PatientID);

                file.Dataset.Add(DicomTag.PatientName, "XX");*/

            // creates a new instance of DicomFile
            //  var file = file.ChangeTransferSyntax(DicomTransferSyntax.JPEGProcess14SV1);

            // file.Save(@"C:\MovedImages");
            /********************/

            // DicomDataset response = new DicomDataset();
           /* DicomFile dicomfile = new DicomFile();
            dicomfile.Save(StoragePath);
            dicomfile.ChangeTransferSyntax(DicomTransferSyntax.JPEGLSNearLossless);*/

            Serie requestedSerie = receivedStudiesList[0].Series[0];
            qrClient.QueryImages(requestedSerie);
              Console.WriteLine("Images received. ")
 Console.ReadLine();
            //  sr. Save("StoragePath");



        }


    }
    } 
pleaseeeeee i need a help



    


Anders Gustafsson Cureos AB

unread,
May 8, 2016, 8:47:07 AM5/8/16
to Fellow Oak DICOM
Khouloud,

Your server is listening on port 105, but your client is sending requests to port 104. Correct this to start with.

Regards,
Anders @ Cureos

khouloud yaakoubi

unread,
May 13, 2016, 8:55:21 AM5/13/16
to Fellow Oak DICOM
Anders Gustafsson Cureos AB,
thank you , but the exeption still in : accées path is incorrect .

Anders Gustafsson Cureos AB

unread,
May 13, 2016, 9:53:38 AM5/13/16
to Fellow Oak DICOM
Sounds like you are using an invalid file or directory path. Check all paths and ensure that they exist and can be written to and read from.

khouloud yaakoubi

unread,
May 13, 2016, 10:00:40 AM5/13/16
to Fellow Oak DICOM
Anders Gustafsson Cureos AB,
the file is valide but how make the file accessibe in write.

Anders Gustafsson Cureos AB

unread,
May 13, 2016, 10:08:34 AM5/13/16
to Fellow Oak DICOM
Please study the examples in the Github repository for fo-dicom and fo-dicom-samples. Try out a simple solution first and get it working, then move on to more complex solutions.

khouloud yaakoubi

unread,
May 13, 2016, 10:17:26 AM5/13/16
to Fellow Oak DICOM
Anders Gustafsson Cureos AB,
Thank you for your help .

Hari Prasath

unread,
Jul 16, 2019, 8:18:02 AM7/16/19
to Fellow Oak DICOM
I'm Using Pacs Communication Project in c#. File Transfer From Machine to System. I Want To Know to get which is the Last File in a transaction. or Total Count of the file Ready to Transfer. I'm Using DicomDecoder Help Me find a solution.
Reply all
Reply to author
Forward
0 new messages