private static void SelectPriorsServers(ServerTreeComponent serverTreeComponent)
        {
            ServerTree serverTree = serverTreeComponent.ServerTree;

            var priorsServers = ServerDirectory.GetPriorsServers(false);

            CheckPriorsServers(serverTree, priorsServers);
            IServerTreeNode initialSelection = GetFirstPriorsServerOrGroup(serverTree.RootServerGroup);

            UncheckAllServers(serverTree);

            if (initialSelection == null)
            {
                if (serverTreeComponent.ShowLocalServerNode)
                {
                    initialSelection = serverTreeComponent.ServerTree.LocalServer;
                }
                else
                {
                    initialSelection = serverTreeComponent.ServerTree.RootServerGroup;
                }
            }

            serverTreeComponent.SetSelection(initialSelection);
        }
Exemplo n.º 2
0
            public IList <T> Query(T queryCriteria, out LocateFailureInfo[] failures)
            {
                if (queryCriteria == null)
                {
                    const string message = "The argument cannot be null.";
                    Platform.Log(LogLevel.Error, message);
                    throw new FaultException(message);
                }

                var results     = new List <T>();
                var failureList = new List <LocateFailureInfo>();

                try
                {
                    foreach (var priorsServer in ServerDirectory.GetPriorsServers(true))
                    {
                        try
                        {
                            IList <T> r = null;
                            priorsServer.GetService <IStudyRootQuery>(service => r = _query(queryCriteria, service));
                            results.AddRange(r);
                        }
                        catch (Exception e)
                        {
                            QueryFailedFault fault = new QueryFailedFault();
                            fault.Description = String.Format("Failed to query server {0}.", priorsServer.Name);
                            Platform.Log(LogLevel.Error, e, fault.Description);
                            if (_suppressQueryFailureFaults)
                            {
                                failureList.Add(new LocateFailureInfo(fault, fault.Description)
                                {
                                    ServerName = priorsServer.Name, ServerAE = priorsServer.AETitle
                                });
                            }
                            else
                            {
                                throw new FaultException <QueryFailedFault>(fault, fault.Description);
                            }
                        }
                    }
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    QueryFailedFault fault = new QueryFailedFault();
                    fault.Description = String.Format("An unexpected error has occurred.");
                    Platform.Log(LogLevel.Error, e, fault.Description);
                    throw new FaultException <QueryFailedFault>(fault, fault.Description);
                }

                failures = failureList.ToArray();
                return(results);
            }
Exemplo n.º 3
0
        public void TestGetPriorsServers()
        {
            Initialize1();

            var priorsServers = ServerDirectory.GetPriorsServers(true);

            Assert.AreEqual(2, priorsServers.Count);
            Assert.AreEqual(1, priorsServers.Count(s => s.IsLocal));

            priorsServers = ServerDirectory.GetPriorsServers(false);
            Assert.AreEqual(1, priorsServers.Count);
            Assert.AreEqual(0, priorsServers.Count(s => s.IsLocal));
        }
 private static DicomServiceNodeList GetPriorsServers()
 {
     try
     {
         var priorsServers = ServerDirectory.GetPriorsServers(false);
         return(new DicomServiceNodeList(priorsServers));
     }
     catch (Exception e)
     {
         Platform.Log(LogLevel.Warn, e, "Error initializing priors servers from directory.");
         return(new DicomServiceNodeList());
     }
 }
        public override PriorStudyFinderResult FindPriorStudies()
        {
            _cancel = false;
            var results = new Dictionary <string, StudyItem>();

            IPatientReconciliationStrategy reconciliationStrategy = new DefaultPatientReconciliationStrategy();

            reconciliationStrategy.SetStudyTree(Viewer.StudyTree);

            var patientIds = new Dictionary <string, string>();

            foreach (Patient patient in Viewer.StudyTree.Patients)
            {
                if (_cancel)
                {
                    break;
                }

                IPatientData reconciled = reconciliationStrategy.ReconcileSearchCriteria(patient);
                patientIds[reconciled.PatientId] = reconciled.PatientId;
            }

            int failedCount  = 0;
            int successCount = 0;

            foreach (var priorsServer in ServerDirectory.GetPriorsServers(true))
            {
                if (_cancel)
                {
                    break;
                }

                try
                {
                    using (var bridge = new StudyRootQueryBridge(priorsServer.GetService <IStudyRootQuery>()))
                    {
                        foreach (string patientId in patientIds.Keys)
                        {
                            //#10790: don't search for priors if patient id is empty
                            if (string.IsNullOrEmpty(patientId))
                            {
                                continue;
                            }

                            var identifier = new StudyRootStudyIdentifier {
                                PatientId = patientId
                            };

                            IList <StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);

                            Platform.Log(LogLevel.Debug, "Found {0} prior studies on server '{1}'", studies.Count, priorsServer.Name);

                            foreach (StudyRootStudyIdentifier study in studies)
                            {
                                if (_cancel)
                                {
                                    break;
                                }

                                //Eliminate false positives right away.
                                IPatientData reconciled = reconciliationStrategy.ReconcilePatientInformation(study);
                                if (reconciled == null)
                                {
                                    continue;
                                }

                                StudyItem studyItem = ConvertToStudyItem(study);
                                if (studyItem == null || results.ContainsKey(studyItem.StudyInstanceUid))
                                {
                                    continue;
                                }

                                if (!results.ContainsKey(studyItem.StudyInstanceUid))
                                {
                                    results[studyItem.StudyInstanceUid] = studyItem;
                                }
                            }
                        }
                    }

                    ++successCount;
                }
                catch (Exception e)
                {
                    ++failedCount;
                    Platform.Log(LogLevel.Error, e, "Failed to query server: {0}", priorsServer.Name);
                }
            }

            if (_cancel)
            {
                //Just pretend the query never happened.
                return(new PriorStudyFinderResult(new StudyItemList(), true));
            }

            if (failedCount > 0)
            {
                PriorStudyLoaderExceptionPolicy.NotifyFailedQuery();

                if (successCount == 0)
                {
                    throw new Exception("The search for prior studies has failed.");
                }
            }
            else
            {
                //Even if success count is zero, we'll still consider it "successful".
                PriorStudyLoaderExceptionPolicy.NotifySuccessfulQuery();
            }

            Platform.Log(LogLevel.Debug, "Found {0} prior studies in total.", results.Count);

            return(new PriorStudyFinderResult(new StudyItemList(results.Values), failedCount == 0));
        }