fo-dicom / fo-dicom-samples

Sample applications associated with the fo-dicom framework
Other
152 stars 144 forks source link

How get image data from DICOM File and show it in view using .net core with fo-dicom #64

Closed farooqbutt closed 2 years ago

farooqbutt commented 3 years ago

Right now I am using fo-Dicom in .net core for getting a list of studies of a patient with their PatientID. The code is below for your better understanding:

var SOPInstanceUID = "";
            var cfind = DicomCFindRequest.CreateImageQuery(studyInstanceUid: "1.2.826.0.1.3680043.11.105",
                seriesInstanceUid: "1.3.46.670589.14.8100.181.152054.3.4.20210707121631.25.3");

            cfind.OnResponseReceived += (req, resp) =>
            {
                if(resp.Status.State.ToString() == "Pending")
                {
                    SOPInstanceUID = resp.Dataset?.GetSingleValue<string>(DicomTag.SOPInstanceUID);
                    Debug.WriteLine("SOP Instance UID : " + SOPInstanceUID);
                }
            };

            var client = new Dicom.Network.Client.DicomClient(ServerHost, ServerPort, false, AET, AeTitle);
            //client.NegotiateAsyncOps();
            await client.AddRequestAsync(cfind);
            var cancellationTokenSource = new CancellationTokenSource();
            //await client.SendAsync(cancellationToken: cancellationTokenSource.Token, cancellationMode: cancellationMode).ConfigureAwait(false);

            var cmove = new DicomCMoveRequest(AeTitle, studyInstanceUid: "1.2.826.0.1.3680043.11.105",
                seriesInstanceUid: "1.3.46.670589.14.8100.181.152054.3.4.20210707121631.25.3",
                sopInstanceUid: SOPInstanceUID);

            //var cmove = new DicomCGetRequest(studyInstanceUid: "1.2.826.0.1.3680043.11.105",
            //    seriesInstanceUid: "1.3.46.670589.14.8100.181.152054.3.4.20210707121631.25.3",
            //    sopInstanceUid: SOPInstanceUID);

            cmove.OnResponseReceived = (req, resp) =>
            {
                //if (resp.Status..State.ToString() == "Pending")
                //{
                DicomDataset dataset = resp.Dataset;
                dataset.AddOrUpdate(DicomTag.StudyInstanceUID, "1.2.826.0.1.3680043.11.105");
                dataset.AddOrUpdate(DicomTag.SeriesInstanceUID, "1.3.46.670589.14.8100.181.152054.3.4.20210707121631.25.3");
                DicomFile dicomFile = new DicomFile(dataset);
                Debug.WriteLine(dicomFile);
                //}
            };
            //client.NegotiateAsyncOps();
            await client.AddRequestAsync(cmove);
            await client.SendAsync(cancellationToken: cancellationTokenSource.Token, cancellationMode: cancellationMode).ConfigureAwait(false);

So now I want to get the image data to show In browser as a picture to users for this patient Dicom file or files, how can we do that please guide. By the way, I am using Medical Connections as a PACS server for getting this patient record. Regards & Thanks Farooq

gofal commented 3 years ago

you mixed up something. This code does a CMoveRequest. A Move works in that way, that the PACS server creates a new separate association and sends the requested data to the move-destination. the response that you get in the cmove.OnResponseReceived is just some status update so that you know how how fast it's going on. But the images are arriving on the StoreSCP that is configured on the PACS with the aetitle. If you want to receive the images on the same association as your request, then you have to send a CGetRequest. But sadly many PACS systems out there do not support CGet. I think MedicalConnections should support CGet. In the CGet association there are 2 callbacks: the CGetRequest.OnResponseReceived is only some status-update. the DicomClient.OnInstanceReceived is then the event that is raised with the image datasets.