Beispiel #1
0
        private static IImageViewer LaunchViewer(OpenStudiesRequest request, string primaryStudyInstanceUid)
        {
            try
            {
                CompleteOpenStudyInfo(request.StudiesToOpen);
            }
            catch (Exception ex)
            {
                if (request.ReportFaultToUser)
                {
                    SynchronizationContext.Current.Post(ReportLoadFailures, ex);
                }
                throw;
            }

            ImageViewerComponent viewer;

            if (!request.LoadPriors.HasValue || request.LoadPriors.Value)
            {
                viewer = new ImageViewerComponent(LayoutManagerCreationParameters.Extended);
            }
            else
            {
                viewer = new ImageViewerComponent(LayoutManagerCreationParameters.Extended, PriorStudyFinder.Null);
            }

            var loadStudyArgs = (from info in request.StudiesToOpen
                                 let server = ServerDirectory.GetRemoteServersByAETitle(info.SourceAETitle).FirstOrDefault() ?? ServerDirectory.GetLocalServer()
                                              select new LoadStudyArgs(info.StudyInstanceUid, server)).ToList();

            try
            {
                viewer.LoadStudies(loadStudyArgs);
            }
            catch (Exception e)
            {
                bool faultThrown = false;
                try
                {
                    HandleLoadStudiesException(e, primaryStudyInstanceUid, viewer);
                }
                catch
                {
                    faultThrown = true;
                    viewer.Dispose();
                    throw;
                }
                finally
                {
                    if (!faultThrown || request.ReportFaultToUser)
                    {
                        SynchronizationContext.Current.Post(ReportLoadFailures, e);
                    }
                }
            }

            ImageViewerComponent.Launch(viewer, new LaunchImageViewerArgs(ViewerLaunchSettings.WindowBehaviour));
            return(viewer);
        }
Beispiel #2
0
        public OpenStudiesResult OpenStudies(OpenStudiesRequest request)
        {
            if (request == null)
            {
                string message = "The open studies request cannot be null.";
                Platform.Log(LogLevel.Debug, message);
                throw new FaultException(message);
            }

            if (request.StudiesToOpen == null || request.StudiesToOpen.Count == 0)
            {
                string message = "At least one study must be specified.";
                Platform.Log(LogLevel.Debug, message);
                throw new FaultException(message);
            }

            OpenStudiesResult result = new OpenStudiesResult();
            bool activateIfOpen      = request.ActivateIfAlreadyOpen ?? true;

            try
            {
                string       primaryStudyInstanceUid = request.StudiesToOpen[0].StudyInstanceUid;
                IImageViewer viewer = null;
                if (activateIfOpen)
                {
                    Workspace workspace = GetViewerWorkspace(primaryStudyInstanceUid);
                    if (workspace != null)
                    {
                        viewer = ImageViewerComponent.GetAsImageViewer(workspace);
                        workspace.Activate();
                    }
                }

                if (viewer == null)
                {
                    viewer = LaunchViewer(request, primaryStudyInstanceUid);
                }

                Guid?viewerId = ViewerAutomationTool.GetViewerId(viewer);
                if (viewerId == null)
                {
                    throw new FaultException("Failed to retrieve the id of the specified viewer.");
                }

                result.Viewer = new Viewer(viewerId.Value, GetPrimaryStudyIdentifier(viewer));
                return(result);
            }
            catch (FaultException)
            {
                throw;
            }
            catch (Exception e)
            {
                string message = "An unexpected error has occurred while attempting to open the study(s).";
                Platform.Log(LogLevel.Error, e, message);
                throw new FaultException(message);
            }
        }
Beispiel #3
0
        private void OnOpenStudy(object sender, EventArgs e)
        {
            StudyItem study = GetSelectedStudy();

            if (study == null)
            {
                return;
            }

            using (AutomationClient client = new AutomationClient())
            {
                try
                {
                    OpenStudiesRequest   request       = new OpenStudiesRequest();
                    List <OpenStudyInfo> studiesToOpen = new List <OpenStudyInfo>();
                    foreach (StudyItem s in GetSelectedStudies())
                    {
                        OpenStudyInfo info = new OpenStudyInfo();
                        info.StudyInstanceUid = s.StudyInstanceUid;
                        info.SourceAETitle    = s.RetrieveAETitle;
                        studiesToOpen.Add(info);
                    }

                    request.StudiesToOpen         = GetStudiesToOpen(studiesToOpen);
                    request.ActivateIfAlreadyOpen = _activateIfOpen.Checked;

                    OpenStudiesResult result = client.OpenStudies(request);
                    if (result.Viewer != null)
                    {
                        bool shouldExist = study.HasViewers && _activateIfOpen.Checked;
                        bool exists      = study.HasViewer(result.Viewer.Identifier);
                        if (shouldExist && !exists)
                        {
                            study.ClearViewers();
                        }

                        if (!exists)
                        {
                            study.AddViewer(result.Viewer.Identifier);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #4
0
 public OpenStudiesResult OpenStudies(OpenStudiesRequest request)
 {
     // Done for reasons of speed, as well as the fact that a call to the service from the same thread
     // that the service is hosted on (the main UI thread) will cause a deadlock.
     if (SynchronizationContext.Current == ViewerAutomationServiceHostTool.HostSynchronizationContext)
     {
         return(new ViewerAutomation().OpenStudies(request));
     }
     else
     {
         using (ViewerAutomationServiceClient client = new ViewerAutomationServiceClient())
         {
             return(client.OpenStudies(request));
         }
     }
 }
            public Viewer OpenViewer(IList <StudyRootStudyIdentifier> studyRootStudyIdentifiers)
            {
                try
                {
                    var request = new OpenStudiesRequest
                    {
                        ActivateIfAlreadyOpen = false,                          // we want to control this manually
                        ReportFaultToUser     = true,
                        StudiesToOpen         = studyRootStudyIdentifiers.Select(i => new OpenStudyInfo(i)).ToList()
                    };

                    var result = _viewerAutomation.OpenStudies(request);
                    return(result.Viewer);
                }
                catch (FaultException <StudyNotFoundFault> e) { throw new OpenStudyException(studyRootStudyIdentifiers, e); }
                catch (FaultException <StudyOfflineFault> e) { throw new OpenStudyException(studyRootStudyIdentifiers, e); }
                catch (FaultException <StudyNearlineFault> e) { throw new OpenStudyException(studyRootStudyIdentifiers, e); }
                catch (FaultException <StudyInUseFault> e) { throw new OpenStudyException(studyRootStudyIdentifiers, e); }
                catch (FaultException <OpenStudiesFault> e) { throw new OpenStudyException(studyRootStudyIdentifiers, e); }
            }
Beispiel #6
0
 public OpenStudiesResult OpenStudies(OpenStudiesRequest request)
 {
     return(Execute(a => a.OpenStudies(request)));
 }
        private void btnRetreive_Click(object sender, EventArgs e)
        {
            if (DataGridView1.SelectedRows == null)
            {
                MessageBox.Show(
                    "Please Select a Study to Retrive It.",
                    "Information- " + Application.ProductName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
                return;
            }

            if (DataGridView1.SelectedCells[1].Value != null)
            {
                modMain.PatName = DataGridView1.SelectedCells[1].Value.ToString();
            }
            if (DataGridView1.SelectedCells[3].Value != null)
            {
                modMain.PatDOB = DataGridView1.SelectedCells[3].Value.ToString();
            }
            if (DataGridView1.SelectedCells[2].Value != null)
            {
                modMain.PatSex = DataGridView1.SelectedCells[2].Value.ToString();
            }
            if (DataGridView1.SelectedCells[5].Value != null)
            {
                modMain.StudyID = DataGridView1.SelectedCells[5].Value.ToString();
            }
            if (DataGridView1.SelectedCells[6].Value != null)
            {
                modMain.StudyDate = DataGridView1.SelectedCells[6].Value.ToString();
            }
            if (DataGridView1.SelectedCells[7].Value != null)
            {
                modMain.StudyTime = DataGridView1.SelectedCells[7].Value.ToString();
            }

            //_MoverSettings = LoadSettingfromXmlFile();

            BasicHttpBinding binding             = new BasicHttpBinding();
            EndpointAddress  endpoint            = new EndpointAddress(ConfigurationManager.AppSettings["AutomationServiceUrl"]);
            ViewerAutomationServiceClient client = new ViewerAutomationServiceClient(binding, endpoint);

            try
            {
                client.Open();
                OpenStudiesRequest request = new OpenStudiesRequest();
                request.ActivateIfAlreadyOpen = true;
                List <OpenStudyInfo> studiesToOpen = new List <OpenStudyInfo>();
                OpenStudyInfo        studyInfo     = new OpenStudyInfo(modMain.StudyID);
                studiesToOpen.Add(studyInfo);
                request.StudiesToOpen = studiesToOpen;
                client.OpenStudies(request);
                client.Close();
            }
            catch (Exception x)
            {
                client.Abort();
                MessageBox.Show(x.Message);
            }
            //this.Close();
        }