Beispiel #1
0
        public void SaveSeriesToLocalDisk(IDicomSeries dicomSeries, string folderPath)
        {
            var moveScu = new StudyRootMoveScu(LocalNode.AeTitle, RemoteNode.AeTitle,
                                               RemoteNode.IpAddress, RemoteNode.Port, LocalNode.AeTitle);

            moveScu.AddStudyInstanceUid(dicomSeries.StudyInstanceUid);
            moveScu.AddSeriesInstanceUid(dicomSeries.SeriesInstanceUid);

            StorageScp.StorageLocation = folderPath;

            try
            {
                StorageScp.StartListening(LocalNode.AeTitle, LocalNode.Port);

                moveScu.Move();

                if (!string.IsNullOrEmpty(moveScu.FailureDescription))
                {
                    throw new DicomException(moveScu.FailureDescription);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex); // TODO3: Implement proper logging
                throw;
            }
            finally
            {
                StorageScp.StopListening();
            }
        }
Beispiel #2
0
        static void Debug2()
        {
            //ADCM.DownloadOneSeries("1.2.840.114202.4.2604463977.4026103162.3502102038.3123374876", "1.3.51.0.7.225049604.36789.12869.46787.35328.59718.43415");

            var cstore = new DicomSCP("CAPITZZRADPAE", 104);

            ////var cstore = new DicomSCP("CAPITZZKPACS", 105);
            cstore.Start();
            ////while (!cstore.IsRunning)
            ////    System.Threading.Thread.Sleep(1000);

            MoveScuBase moveScu = new StudyRootMoveScu("CAPITZZRADPAE", "CAPITCYMOD1", "192.168.115.240", 5000, "CAPITZZRADPAE");


            moveScu.ReadTimeout  = 600000;
            moveScu.WriteTimeout = 600000;
            moveScu.AddStudyInstanceUid("1.2.840.114202.4.2604463977.4026103162.3502102038.3123374876");
            moveScu.AddSeriesInstanceUid("1.3.51.0.7.225049604.36789.12869.46787.35328.59718.43415");
            moveScu.Move();

            Console.WriteLine("Done");
        }
Beispiel #3
0
    public static bool DownloadOneSeries(string studyuid, string seriesuid, int retryCount = 0)
    {
        var node   = GetSelectedNode();
        var cstore = new DicomSCP(node.LocalAe, 104);

        try
        {
            LOG.Write("Retry Count: " + retryCount);

            StudyRootFindScu findScu      = new StudyRootFindScu();
            SeriesQueryIod   queryMessage = new SeriesQueryIod();
            queryMessage.SetCommonTags();
            queryMessage.StudyInstanceUid  = studyuid;
            queryMessage.SeriesInstanceUid = seriesuid;
            IList <SeriesQueryIod> results = findScu.Find(node.LocalAe, node.AET, node.IP, node.Port, queryMessage);
            if (results.Count != 1)
            {
                throw new Exception(string.Format("Unable to query study on PACS: [{0}]", studyuid));
            }

            int expectedFiles = (int)results[0].NumberOfSeriesRelatedInstances;

            if (!System.IO.Directory.Exists(node.LocalStorage))
            {
                System.IO.Directory.CreateDirectory(node.LocalStorage);
            }
            cstore.Start();
            while (!cstore.IsRunning)
            {
                System.Threading.Thread.Sleep(1000);
            }

            MoveScuBase moveScu = new StudyRootMoveScu(node.LocalAe, node.AET, node.IP, node.Port, node.LocalAe);
            moveScu.ReadTimeout  = 600000;
            moveScu.WriteTimeout = 600000;
            moveScu.AddStudyInstanceUid(studyuid);
            moveScu.AddSeriesInstanceUid(seriesuid);

            DateTime started = DateTime.Now;

            moveScu.Move();
            System.Threading.Thread.Sleep(2000);
            if (moveScu.Status == ScuOperationStatus.AssociationRejected || moveScu.Status == ScuOperationStatus.Canceled ||
                moveScu.Status == ScuOperationStatus.ConnectFailed || moveScu.Status == ScuOperationStatus.Failed ||
                moveScu.Status == ScuOperationStatus.NetworkError || moveScu.Status == ScuOperationStatus.TimeoutExpired ||
                moveScu.Status == ScuOperationStatus.UnexpectedMessage || moveScu.FailureSubOperations != 0)
            {
                if (retryCount > 4)
                {
                    throw new Exception(string.Format("Failed moving study [{0}] | Status : {1} | Failed Operations: {2}", studyuid, moveScu.Status, moveScu.FailureSubOperations));
                }
                retryCount += 1;
                if (cstore.IsRunning)
                {
                    cstore.Stop();
                }
                DownloadOneSeries(studyuid, seriesuid, retryCount);
            }

            string downloadFolder = GetStoreString();
            downloadFolder = Path.Combine(downloadFolder, studyuid, seriesuid);
            bool direxist = Directory.Exists(downloadFolder);
            while (!direxist)
            {
                if ((DateTime.Now - started).TotalMinutes > 3)
                {
                    if (cstore.IsRunning)
                    {
                        cstore.Stop();
                    }
                    throw new Exception("Waited too long for images to come in");
                }
                //LOG.Write("Waiting for images to come in...");
                System.Threading.Thread.Sleep(1 * 1000);
                direxist = Directory.Exists(downloadFolder);
            }

            var dcmfiles = Directory.GetFiles(downloadFolder, "*.dcm");
            var dcmCount = dcmfiles.Length;
            while (dcmCount < expectedFiles)
            {
                if ((DateTime.Now - started).TotalMinutes > 3)
                {
                    if (cstore.IsRunning)
                    {
                        cstore.Stop();
                    }
                    throw new Exception("Waited too long for images to come in");
                }
                //LOG.Write("Waiting for images to come in...");
                System.Threading.Thread.Sleep(1 * 1000);
                dcmfiles = Directory.GetFiles(downloadFolder, "*.dcm");
                if (dcmfiles.Length != dcmCount)
                {
                    if (dcmfiles.Length >= expectedFiles)
                    {
                        break;
                    }
                    dcmCount = dcmfiles.Length;
                    started  = DateTime.Now;
                }
            }

            if (cstore.IsRunning)
            {
                cstore.Stop();
            }
            LOG.Write("Series successfully downloaded from PACS");
            return(true);
        }
        catch (Exception ex)
        {
            if (cstore.IsRunning)
            {
                cstore.Stop();
            }
            string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name;
            LOG.Write(errorString);
            LOG.Write(ex.Message);
            return(false);
        }
    }
Beispiel #4
0
        // Note: you may change the name of the 'Apply' method as desired, but be sure to change the
        // corresponding parameter in the MenuAction and ButtonAction attributes

        /// <summary>
        /// Called by the framework when the user clicks the "apply" menu item or toolbar button.
        /// </summary>
        public void Apply()
        {
            // TODO: add code here to implement the functionality of the tool
            //|| this.Context.SelectedServerGroup.IsLocalDatastore
            if (!Enabled || this.Context.SelectedSingleSeries == null)
            {
                return;
            }

            //Dictionary<ApplicationEntity, List<StudyInformation>> retrieveInformation = new Dictionary<ApplicationEntity, List<StudyInformation>>();

            List <string> seriesUIDs = new List <string>();
            List <string> studyUIDs  = new List <string>();

            foreach (SeriesItem item in this.Context.SelectedMultipleSeries)
            {
                string foo = item.SeriesInstanceUID;
                Platform.Log(LogLevel.Info, foo);
                seriesUIDs.Add(item.SeriesInstanceUID);
                studyUIDs.Add(item.StudyInstanceUID);
            }


            string callingAE = ServerTree.GetClientAETitle();


            BackgroundTask task = new BackgroundTask(
                delegate(IBackgroundTaskContext context)
            {
                // Send series level c-move
                //MyMoveScu moveScu = new MyMoveScu(
                //DicomMoveManager.MyMoveScu moveScu = new DicomMoveManager.MyMoveScu(
                MoveScuBase moveScu = new StudyRootMoveScu(
                    callingAE,
                    this.Context.SelectedServer.AETitle,
                    this.Context.SelectedServer.Host,
                    this.Context.SelectedServer.Port,
                    callingAE);
                // Need to disable this line for the 1.5 version, because the movescu
                // code only allows one level per movescu request.  This may not work with some
                // PACS
                moveScu.AddStudyInstanceUid(studyUIDs[0]);
                foreach (string seriesUID in seriesUIDs)
                {
                    moveScu.AddSeriesInstanceUid(seriesUID);
                }
                moveScu.Move();
                //moveScu.updated += delegate(object sender, EventArgs args)
                //{
                //    OnMoveUpdate(context, moveScu.completed, moveScu.total, moveScu.movestatus);
                //    //context.ReportProgress(new BackgroundTaskProgress(moveScu.completed / moveScu.total, "Moving Study"));
                //    //OnMoveUpdate(context, moveScu.completed, moveScu.total);
                //};
                //  += new EventHandler(OnMoveCompleted);
                moveScu.Dispose();
                //OnMoveCompleted();
            }, true);

            task.Run();

            LocalDataStoreActivityMonitorComponentManager.ShowSendReceiveActivityComponent(this.Context.DesktopWindow);



            //        //if (!retrieveInformation.ContainsKey(item.Server))
            //        //    retrieveInformation[item.Server] = new List<StudyInformation>();

            //        //StudyInformation studyInformation = new StudyInformation();
            //        //studyInformation.PatientId = item.PatientId;
            //        //studyInformation.PatientsName = item.PatientsName;
            //        //DateTime studyDate;
            //        //DateParser.Parse(item.StudyDate, out studyDate);
            //        //studyInformation.StudyDate = studyDate;
            //        //studyInformation.StudyDescription = item.StudyDescription;
            //        //studyInformation.StudyInstanceUid = item.StudyInstanceUID;

            //        //retrieveInformation[item.Server].Add(studyInformation);
        }