Exemplo n.º 1
0
        public async Task RetrieveAsync(DicomCGetRequest request, Func <DicomDataset, Task <bool> > storeHandler)
        {
            async Task <DicomCStoreResponse> cStoreHandler(DicomCStoreRequest cStoreRequest)
            {
                var success = await storeHandler(cStoreRequest.Dataset);

                return(new DicomCStoreResponse(cStoreRequest, success ? DicomStatus.Success : DicomStatus.QueryRetrieveUnableToPerformSuboperations));
            }

            var client = CreateClient();
            var presentationContexts = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(DicomStorageCategory.Image, DicomTransferSyntax.ExplicitVRLittleEndian,
                                                                                                              DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(presentationContexts);
            presentationContexts = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(DicomStorageCategory.Document, DicomTransferSyntax.ExplicitVRLittleEndian,
                                                                                                          DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ImplicitVRBigEndian);
            client.AdditionalPresentationContexts.AddRange(presentationContexts);
            try
            {
                client.OnCStoreRequest += cStoreHandler;
                await client.AddRequestAsync(request);

                await client.SendAsync();
            }
            finally
            {
                client.OnCStoreRequest -= cStoreHandler;
            }
        }
Exemplo n.º 2
0
        public async Task <List <DicomFile> > GetDicomFiles(string studyInstanceUID, string seriesInstanceUID)
        {
            ReceivedFiles.Clear();
            DicomCMoveRequest moveRequest = new DicomCMoveRequest(_preferences.AETitle, studyInstanceUID, seriesInstanceUID);

            moveRequest.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) =>
            {
                if (response.Status.State == DicomState.Pending)
                {
                    //logger.Trace("PresentationContext: " + response.PresentationContext.AcceptedTransferSyntax.ToString());
                }
                else if (response.Status.State == DicomState.Success)
                {
                    logger.Trace("Sending successfully finished");
                }
                else if (response.Status.State == DicomState.Failure)
                {
                    logger.Error("Error sending datasets: " + response.Status.Description);
                }
            };
            logger.Debug("Move Request; AE Title: " + _preferences.AETitle + "; Level: " + moveRequest.Level + "; SOP Class UID: " + moveRequest.SOPClassUID);
            foreach (StoredDicomServer s in DicomServers)
            {
                logger.Trace("GetDicomFiles(" + studyInstanceUID + "," + seriesInstanceUID + ") on " + s.AETitle);


                var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                    DicomStorageCategory.Image,
                    DicomTransferSyntax.ExplicitVRLittleEndian,
                    DicomTransferSyntax.ImplicitVRLittleEndian);
                DicomClient client = new DicomClient(s.IPAddress, s.Port, false, _preferences.AETitle, s.AETitle);
                client.AdditionalPresentationContexts.AddRange(pcs);
                client.AssociationRejected += Client_AssociationRejected;
                client.AssociationAccepted += Client_AssociationAccepted;
                client.NegotiateAsyncOps();
                await client.AddRequestAsync(moveRequest);

                await client.SendAsync();
            }

            return(ReceivedFiles);
        }
Exemplo n.º 3
0
        public void DicomClientSend_TooManyPresentationContexts_YieldsInformativeException()
        {
            var port = Ports.GetNext();

            using (DicomServer.Create <DicomCEchoProvider>(port))
            {
                var client = new DicomClient();

                // this just illustrates the issue of too many presentation contexts, not real world application.
                var pcs =
                    DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                        DicomStorageCategory.None,
                        DicomTransferSyntax.ImplicitVRLittleEndian);

                client.AdditionalPresentationContexts.AddRange(pcs);

                var exception = Record.Exception(() => client.Send("localhost", port, false, "SCU", "SCP"));
                Assert.IsType <DicomNetworkException>(exception);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Send CGet to Get Target Frame
        /// </summary>
        /// <param name="SOPInstanceUID">the SOPInstanceUID Where Frame in</param>
        /// <param name="FrameIndex"> the FrameIndex Where Frame in</param>
        /// <returns></returns>
        internal async Task SaveTargetFramesAsyn(String SOPInstanceUID, int FrameIndex)
        {
            client = new DicomClient();
            var cGetRequest = CreateCGetRquest_FramesByList(SOPInstanceUID, FrameIndex);

            cGetRequest.Dataset.AddOrUpdate(new DicomTag(0x8, 0x5), "ISO_IR 100");
            cGetRequest.Dataset.AddOrUpdate(new DicomSequence(DicomTag.PerFrameFunctionalGroupsSequence));
            var FrameExtractionSequence = new DicomSequence(DicomTag.FrameExtractionSequence);

            cGetRequest.Dataset.AddOrUpdate(DicomTag.SOPInstanceUID, SOPInstanceUID);

            cGetRequest.Dataset.AddOrUpdate(DicomTag.QueryRetrieveLevel, DicomQueryRetrieveLevel.NotApplicable);

            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian,
                DicomTransferSyntax.JPEGLSLossless,
                DicomTransferSyntax.JPEG2000Lossless,
                DicomTransferSyntax.JPEGProcess14SV1,
                DicomTransferSyntax.JPEGProcess14,
                DicomTransferSyntax.RLELossless,
                DicomTransferSyntax.JPEGLSNearLossless,
                DicomTransferSyntax.JPEG2000Lossy,
                DicomTransferSyntax.JPEGProcess1,
                DicomTransferSyntax.JPEGProcess2_4
                );

            client.AdditionalPresentationContexts.AddRange(pcs);
            client.OnCStoreRequest += (DicomCStoreRequest req) =>
            {
                SaveImage(req.Dataset);

                return(new DicomCStoreResponse(req, DicomStatus.Success));
            };
            client.AddRequest(cGetRequest);
            client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET);
        }
Exemplo n.º 5
0
        public async Task DicomCGetRequest_OneImageInSeries_Received()
        {
            var client = DicomClientFactory.Create("localhost", 11112, false, "SCU", "COMMON");

            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);

            DicomDataset dataset = null;

            client.OnCStoreRequest = request =>
            {
                dataset = request.Dataset;
                return(Task.FromResult(new DicomCStoreResponse(request, DicomStatus.Success)));
            };

            var get = new DicomCGetRequest(
                "1.2.840.113619.2.1.1.322987881.621.736170080.681",
                "1.2.840.113619.2.1.2411.1031152382.365.736169244");

            var handle = new ManualResetEventSlim();

            get.OnResponseReceived = (request, response) =>
            {
                handle.Set();
            };
            await client.AddRequestAsync(get);

            await client.SendAsync().ConfigureAwait(false);

            handle.Wait();

            Assert.Equal("RT ANKLE", dataset.GetString(DicomTag.StudyDescription));
        }
Exemplo n.º 6
0
        public async Task <DicomDataset> GetImagesBySOPInstanceAsync(string serverIp, int serverPort, string serverAET, string localAET, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid)
        {
            DicomDataset imageDatasets = null;

            DicomCGetRequest request = RequestFactory.CreateCGetBySeriesUID(studyInstanceUid, seriesInstanceUid);
            DicomClient      client  = new DicomClient(serverIp, serverPort, false, localAET, serverAET);

            client.OnCStoreRequest += async(req) =>
            {
                if (req.HasDataset)
                {
                    imageDatasets = req.Dataset;
                    return(await Task.FromResult(new DicomCStoreResponse(req, DicomStatus.Success)));
                }
                else
                {
                    logger.Error("C-STORE request has no dataset.");
                    return(await Task.FromResult(new DicomCStoreResponse(req, DicomStatus.AttributeListError)));
                }
            };
            // the client has to accept storage of the images. We know that the requested images are of SOP class Secondary capture,
            // so we add the Secondary capture to the additional presentation context
            // a more general approach would be to mace a cfind-request on image level and to read a list of distinct SOP classes of all
            // the images. these SOP classes shall be added here.
            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);
            await client.AddRequestAsync(request);

            await client.SendAsync();

            return(imageDatasets);
        }
        public async Task <bool> DataQuery()
        {
            try
            {
                var host       = _configuration.GetSection("Source:Host").Value;
                var scpAeTitle = _configuration.GetSection("Source:AeTitle").Value;
                var port       = Int32.Parse(_configuration.GetSection("Source:Port").Value);

                clientQuery = new Dicom.Network.Client.DicomClient(host, port, false, "SCU", scpAeTitle);

                var cFindStudy = new DicomCFindRequest(DicomQueryRetrieveLevel.Study);

                cFindStudy.Dataset.AddOrUpdate(DicomTag.StudyInstanceUID, "");

                cFindStudy.OnResponseReceived = async(DicomCFindRequest rq, DicomCFindResponse rp) => {
                    if (null != rp.Dataset)
                    {
                        var    cFindSeries = new DicomCFindRequest(DicomQueryRetrieveLevel.Series, DicomPriority.Medium);
                        string studyUid    = rp.Dataset.GetSingleValue <string>(DicomTag.StudyInstanceUID);
                        cFindSeries.Dataset.AddOrUpdate(DicomTag.StudyInstanceUID, studyUid);
                        cFindSeries.Dataset.AddOrUpdate(DicomTag.SeriesInstanceUID, "");
                        cFindSeries.OnResponseReceived = async(DicomCFindRequest req, DicomCFindResponse rep) => {
                            if (null != rep.Dataset)
                            {
                                var cFindImage = new DicomCFindRequest(DicomQueryRetrieveLevel.Image, DicomPriority.Medium);
                                var seriesUid  = rep.Dataset.GetSingleValue <string>(DicomTag.SeriesInstanceUID);

                                cFindImage.Dataset.AddOrUpdate(DicomTag.StudyInstanceUID, studyUid);
                                cFindImage.Dataset.AddOrUpdate(DicomTag.SeriesInstanceUID, seriesUid);
                                cFindImage.Dataset.AddOrUpdate(DicomTag.SOPInstanceUID, "");

                                cFindImage.OnResponseReceived = async(DicomCFindRequest reqi, DicomCFindResponse repi) =>
                                {
                                    if (null != repi.Dataset)
                                    {
                                        var imageUid   = repi.Dataset.GetString(DicomTag.SOPInstanceUID);
                                        var clientCGet = new Dicom.Network.Client.DicomClient(host, port, false, "SCU", scpAeTitle);

                                        clientCGet.OnCStoreRequest += (DicomCStoreRequest reqs) =>
                                        {
                                            _dicomFileQueue.Enqueue(reqs.Dataset);
                                            return(Task.FromResult(new DicomCStoreResponse(reqs, DicomStatus.Success)));
                                        };
                                        var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                                            DicomStorageCategory.Image,
                                            DicomTransferSyntax.ExplicitVRLittleEndian,
                                            DicomTransferSyntax.ImplicitVRLittleEndian,
                                            DicomTransferSyntax.ImplicitVRBigEndian);
                                        clientCGet.AdditionalPresentationContexts.AddRange(pcs);
                                        var cGetRequest = new DicomCGetRequest(studyUid, seriesUid, imageUid);
                                        await clientCGet.AddRequestAsync(cGetRequest);

                                        await clientCGet.SendAsync();
                                    }
                                };
                                await clientQuery.AddRequestAsync(cFindImage);

                                await clientQuery.SendAsync();
                            }
                        };
                        await clientQuery.AddRequestAsync(cFindSeries);

                        await clientQuery.SendAsync();
                    }
                };

                await clientQuery.AddRequestAsync(cFindStudy);

                await clientQuery.SendAsync();

                Thread.Sleep(Timeout.Infinite);
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        static async Task Main(string[] args)
        {
            var client = new DicomClient(QRServerHost, QRServerPort, false, CallingAE, CalledAE);

            client.NegotiateAsyncOps();

            //// Find a list of Studies

            //var request = CreateStudyRequestByPatientName("Traxler^Y*");

            //var studyUids = new List<string>();
            //request.OnResponseReceived += (req, response) =>
            //{
            //    DebugStudyResponse(response);
            //    studyUids.Add(response.Dataset?.GetSingleValue<string>(DicomTag.StudyInstanceUID));
            //};
            //await client.AddRequestAsync(request);
            //await client.SendAsync();

            //// find all series from a study that previous was returned
            var studyUID = "111";

            //var studyUID = studyUids[0];
            //request = CreateSeriesRequestByStudyUID(studyUID);
            //var serieUids = new List<string>();
            //request.OnResponseReceived += (req, response) =>
            //{
            //    DebugSerieResponse(response);
            //    serieUids.Add(response.Dataset?.GetSingleValue<string>(DicomTag.SeriesInstanceUID));
            //};
            //await client.AddRequestAsync(request);
            //await client.SendAsync();

            // now get all the images of a serie with cGet in the same association

            client = new DicomClient(QRServerHost, QRServerPort, false, CallingAE, CalledAE);
            var cGetRequest = CreateCGetBySeriesUID(studyUID, "11");

            client.OnCStoreRequest += (DicomCStoreRequest req) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " recived");
                SaveImage(req.Dataset);
                return(Task.FromResult(new DicomCStoreResponse(req, DicomStatus.Success)));
            };
            // the client has to accept storage of the images. We know that the requested images are of SOP class Secondary capture,
            // so we add the Secondary capture to the additional presentation context
            // a more general approach would be to mace a cfind-request on image level and to read a list of distinct SOP classes of all
            // the images. these SOP classes shall be added here.
            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);
            await client.AddRequestAsync(cGetRequest);

            await client.SendAsync();

            // if the images shall be sent to an existing storescp and this storescp is configured on the QR SCP then a CMove could be performed:

            // here we want to see how a error case looks like - because the test QR Server does not know the node FODICOMSCP
            client = new DicomClient(QRServerHost, QRServerPort, false, CallingAE, CalledAE);
            var  cMoveRequest     = CreateCMoveByStudyUID("STORESCP", studyUID);
            bool?moveSuccessfully = null;

            cMoveRequest.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) =>
            {
                if (response.Status.State == DicomState.Pending)
                {
                    Console.WriteLine("Sending is in progress. please wait: " + response.Remaining.ToString());
                }
                else if (response.Status.State == DicomState.Success)
                {
                    Console.WriteLine("Sending successfully finished");
                    moveSuccessfully = true;
                }
                else if (response.Status.State == DicomState.Failure)
                {
                    Console.WriteLine("Error sending datasets: " + response.Status.Description);
                    moveSuccessfully = false;
                }
                Console.WriteLine(response.Status);
            };
            await client.AddRequestAsync(cMoveRequest);

            await client.SendAsync();

            if (moveSuccessfully.GetValueOrDefault(false))
            {
                Console.WriteLine("images sent successfully");
                // images sent successfully from QR Server to the store scp
            }
            Console.ReadLine();
        }
Exemplo n.º 9
0
        public void MoveAndStore(Selector sel, String seriesInstanceUID, String studyUID)
        {
            //  NON FUNZIONA find all series from a study that previous was returned

            request   = CreateSeriesRequestByStudyUID(studyUID);
            serieUids = new List <string>();

            /*
             * request.OnResponseReceived += (req, response) =>
             * {
             *  DebugSerieResponse(response);
             *  serieUids.Add(response.Dataset?.GetSingleValue<string>(DicomTag.SeriesInstanceUID));
             *  Console.WriteLine("aggiungo serie");
             * };
             * // -> porto StudyUID nella classe AvvioQuery
             */
            serieUids.Add(seriesInstanceUID);
            Console.WriteLine("ho prodotto lo study uid " + studyUID);


            client.AddRequest(request);
            client.SendAsync(QRServerHost, QRServerPort, false, AET, QRServerAET).Wait();

            // now get all the images of a serie with cGet in the same association

            client = new DicomClient();
            var cGetRequest = CreateCGetBySeriesUID(studyUID, serieUids.First());

            client.OnCStoreRequest += (DicomCStoreRequest req) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " recived");
                SaveImage(req.Dataset);
                return(new DicomCStoreResponse(req, DicomStatus.Success));
            };
            // the client has to accept storage of the images. We know that the requested images are of SOP class Secondary capture,
            // so we add the Secondary capture to the additional presentation context
            // a more general approach would be to mace a cfind-request on image level and to read a list of distinct SOP classes of all
            // the images. these SOP classes shall be added here.
            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);
            client.AddRequest(cGetRequest);
            client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET);

            // if the images shall be sent to an existing storescp and this storescp is configured on the QR SCP then a CMove could be performed:

            // here we want to see how a error case looks like - because the test QR Server does not know the node FODICOMSCP
            client = new DicomClient();
            var  cMoveRequest     = CreateCMoveByStudyUID(QRServerAET, studyUID);
            bool?moveSuccessfully = null;

            cMoveRequest.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) =>
            {
                if (response.Status.State == DicomState.Pending)
                {
                    Console.WriteLine("Sending is in progress. please wait: " + response.Remaining.ToString());
                }
                else if (response.Status.State == DicomState.Success)
                {
                    Console.WriteLine("Sending successfully finished");
                    moveSuccessfully = true;
                }
                else if (response.Status.State == DicomState.Failure)
                {
                    Console.WriteLine("Error sending datasets: " + response.Status.Description);
                    moveSuccessfully = false;
                }
                Console.WriteLine(response.Status);
            };
            client.AddRequest(cMoveRequest);
            client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET);

            if (moveSuccessfully.GetValueOrDefault(false))
            {
                Console.WriteLine("images sent successfully");
                // images sent successfully from QR Server to the store scp
            }
            Console.ReadLine();
        }
Exemplo n.º 10
0
        public void move(string callingAE, QueryObject query, string level, GUILogic guiLogic)
        {
            var cmove = new DicomCMoveRequest("", "");

            if (query.GetType().ToString() == "QueryRetrieveService.StudyResponseQuery")
            {
                string studyId = ((StudyResponseQuery)query).StudyInstanceUID;
                cmove = new DicomCMoveRequest(callingAE, studyId);
            }

            if (query.GetType().ToString() == "QueryRetrieveService.SeriesResponseQuery")
            {
                string studyId  = ((SeriesResponseQuery)query).StudyInstanceUID;
                string seriesId = ((SeriesResponseQuery)query).SeriesInstanceUID;
                cmove = new DicomCMoveRequest(callingAE, studyId, seriesId);
            }

            if (query.GetType().ToString() == "QueryRetrieveService.ImageResponseQuery")
            {
                string studyId  = ((ImageResponseQuery)query).StudyInstanceUID;
                string seriesId = ((ImageResponseQuery)query).SeriesInstanceUID;
                string imageId  = ((ImageResponseQuery)query).SOPInstanceUID;
                cmove = new DicomCMoveRequest(callingAE, studyId, seriesId, imageId);
                Console.WriteLine(studyId + " " + seriesId + " " + imageId);
            }

            var client = new DicomClient();

            bool?moveSuccessfully = null;

            cmove.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) =>
            {
                if (response.Status.State == DicomState.Pending)
                {
                    Console.WriteLine("Sending is in progress. please wait: " + response.Remaining.ToString());
                }
                else if (response.Status.State == DicomState.Success)
                {
                    Console.WriteLine("Sending successfully finished");
                    moveSuccessfully = true;
                }
                else if (response.Status.State == DicomState.Failure)
                {
                    Console.WriteLine("Error sending datasets: " + response.Status.Description);
                    moveSuccessfully = false;
                }
                Console.WriteLine(response.Status);
            };
            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);

            client.AddRequest(cmove);
            // cicle to kill listener and restart it (thus ending associatio) if move takes too much time
            bool sendSuccess = false;

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.Sleep(5000);
                if (!sendSuccess)
                {
                    guiLogic.listenerProcess.Kill();
                    guiLogic.newProcess();
                }
            }).Start();
            client.Send(GUILogic.readFromFile("server"), Int32.Parse(GUILogic.readFromFile("serverPort")), false, GUILogic.readFromFile("thisMachineAE"), GUILogic.readFromFile("serverAE"), 1000);
            sendSuccess = true;
        }