예제 #1
0
        private static void QueryByWcf()
        {
            Console.WriteLine(@"--------------------------------------------------------");
            Console.WriteLine(@"-------------------QueryByWcf---------------------------");

            StudyRootQueryBridge client = 
                new StudyRootQueryBridge(new StudyRootQueryServiceClient());

            IList<StudyRootStudyIdentifier> results = client.QueryByPatientId("013127");
            foreach (var id in results)
            {
                Console.WriteLine(@"PatientId = {0}, PatientName = {1}", id.PatientId, id.PatientsName);
            }
        }
예제 #2
0
        private static void QueryByApi()
        {
            ApplicationEntity ae = new ApplicationEntity
                {
                    AETitle = "UIHPACSSERVER",
                    ScpParameters = new ScpParameters("localhost", 3333)
                };

            var query = new StudyRootQueryBridge(new RemoteStudyRootQuery(ae));
            IList<StudyRootStudyIdentifier> results = query.QueryByPatientId("013127");
            foreach (var id in results)
            {
                Console.WriteLine(@"PatientId = {0}, PatientName = {1}", id.PatientId, id.PatientsName);
            }
        }
예제 #3
0
		private void TestClient()
		{
			try
			{
				using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService<IStudyRootQuery>()))
				{
					bridge.QueryByAccessionNumber("test");
				}

				base.Context.DesktopWindow.ShowMessageBox("Success!", MessageBoxActions.Ok);
			}
			catch (Exception e)
			{
				base.Context.DesktopWindow.ShowMessageBox(e.Message, MessageBoxActions.Ok);
			}
		}
        private void TestClient()
        {
            try
            {
                using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService <IStudyRootQuery>()))
                {
                    bridge.QueryByAccessionNumber("test");
                }

                base.Context.DesktopWindow.ShowMessageBox("Success!", MessageBoxActions.Ok);
            }
            catch (Exception e)
            {
                base.Context.DesktopWindow.ShowMessageBox(e.Message, MessageBoxActions.Ok);
            }
        }
        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));
        }
예제 #6
0
        private static IList <StudyRootStudyIdentifier> FindStudies(StartViewerApplicationRequest request)
        {
            bool invalidRequest = true;
            List <StudyRootStudyIdentifier> results = new List <StudyRootStudyIdentifier>();

            using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService <IStudyRootQuery>()))
            {
                if (request.StudyInstanceUid != null && request.StudyInstanceUid.Length > 0)
                {
                    foreach (string studyUid in request.StudyInstanceUid)
                    {
                        //TODO (CR May 2010): can actually trigger a query of all studies
                        if (!String.IsNullOrEmpty(studyUid))
                        {
                            invalidRequest = false;
                        }

                        //TODO (CR May 2010): if request.AeTitle is set, assign RetrieveAeTitle parameter in
                        // StudyRootStudyIndentifer to this value.  Update the query code to then only
                        // search this specified partition and remove the loop code below that looks
                        // for matching AeTitles.
                        StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier
                        {
                            StudyInstanceUid = studyUid
                        };
                        IList <StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);

                        bool found = false;
                        foreach (StudyRootStudyIdentifier study in studies)
                        {
                            if (!string.IsNullOrEmpty(request.AeTitle) && !study.RetrieveAeTitle.Equals(request.AeTitle))
                            {
                                continue;
                            }

                            results.Add(study);
                            found = true;
                        }

                        if (!found)
                        {
                            throw new NotFoundLoadStudyException(studyUid);
                        }
                    }
                }
                if (request.PatientId != null && request.PatientId.Length > 0)
                {
                    foreach (string patientId in request.PatientId)
                    {
                        if (!String.IsNullOrEmpty(patientId))
                        {
                            invalidRequest = false;
                        }

                        StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier
                        {
                            PatientId = patientId
                        };

                        IList <StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);
                        bool found = false;
                        foreach (StudyRootStudyIdentifier study in studies)
                        {
                            if (!string.IsNullOrEmpty(request.AeTitle) && !study.RetrieveAeTitle.Equals(request.AeTitle))
                            {
                                continue;
                            }

                            results.Add(study);
                            found = true;
                        }

                        if (!found)
                        {
                            throw new PatientStudiesNotFoundException(patientId);
                        }
                    }
                }
                if (request.AccessionNumber != null && request.AccessionNumber.Length > 0)
                {
                    foreach (string accession in request.AccessionNumber)
                    {
                        if (!String.IsNullOrEmpty(accession))
                        {
                            invalidRequest = false;
                        }

                        StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier
                        {
                            AccessionNumber = accession
                        };

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

                        bool found = false;
                        foreach (StudyRootStudyIdentifier study in studies)
                        {
                            if (!string.IsNullOrEmpty(request.AeTitle) && !study.RetrieveAeTitle.Equals(request.AeTitle))
                            {
                                continue;
                            }

                            results.Add(study);
                            found = true;
                        }

                        if (!found)
                        {
                            throw new AccessionStudiesNotFoundException(accession);
                        }
                    }
                }
            }

            if (invalidRequest)
            {
                throw new InvalidRequestException();
            }

            return(results);
        }
예제 #7
0
		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)
                        {
                            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);
        }
예제 #8
0
		private static IList<StudyRootStudyIdentifier> FindStudies(StartViewerApplicationRequest request)
		{
			bool invalidRequest = true;
			List<StudyRootStudyIdentifier> results = new List<StudyRootStudyIdentifier>();

			using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService<IStudyRootQuery>()))
			{
				if (request.StudyInstanceUid != null && request.StudyInstanceUid.Length > 0)
				{
					foreach (string studyUid in request.StudyInstanceUid)
					{
						//TODO (CR May 2010): can actually trigger a query of all studies
						if (!String.IsNullOrEmpty(studyUid))
							invalidRequest = false;

                        //TODO (CR May 2010): if request.AeTitle is set, assign RetrieveAeTitle parameter in 
                        // StudyRootStudyIndentifer to this value.  Update the query code to then only
                        // search this specified partition and remove the loop code below that looks
                        // for matching AeTitles.
						StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier
						                                          {
						                                              StudyInstanceUid = studyUid
						                                          };
					    IList<StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);

					    bool found = false;
						foreach (StudyRootStudyIdentifier study in studies)
						{
						    if (!string.IsNullOrEmpty(request.AeTitle) && !study.RetrieveAeTitle.Equals(request.AeTitle)) continue;

						    results.Add(study);
						    found = true;
						}

                        if (!found)
                            throw new NotFoundLoadStudyException(studyUid);
                    }
				}
				if (request.PatientId != null && request.PatientId.Length > 0)
				{
					foreach (string patientId in request.PatientId)
					{
						if (!String.IsNullOrEmpty(patientId))
							invalidRequest = false;

						StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier
						                                          {
						                                              PatientId = patientId
						                                          };

					    IList<StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);
					    bool found = false;
						foreach (StudyRootStudyIdentifier study in studies)
						{
						    if (!string.IsNullOrEmpty(request.AeTitle) && !study.RetrieveAeTitle.Equals(request.AeTitle)) continue;

						    results.Add(study);
						    found = true;
						}

                        if (!found)
                            throw new PatientStudiesNotFoundException(patientId);
                    }
				}
				if (request.AccessionNumber != null && request.AccessionNumber.Length > 0)
				{
					foreach (string accession in request.AccessionNumber)
					{
						if (!String.IsNullOrEmpty(accession))
							invalidRequest = false;

						StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier
						                                          {
						                                              AccessionNumber = accession
						                                          };

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

					    bool found = false;
						foreach (StudyRootStudyIdentifier study in studies)
						{
						    if (!string.IsNullOrEmpty(request.AeTitle) && !study.RetrieveAeTitle.Equals(request.AeTitle)) continue;

						    results.Add(study);
						    found = true;
						}

                        if (!found)
                            throw new AccessionStudiesNotFoundException(accession);
                    }
				}
			}

			if (invalidRequest)
				throw new InvalidRequestException();

			return results;
		}
        public override PriorStudyFinderResult FindPriorStudies()
        {
            _cancel = false;

            var priorsServerQueries = new List <IStudyRootQuery>();

            foreach (ServerPartition partition in ServerPartitionMonitor.Instance)
            {
                using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                {
                    IDeviceEntityBroker  broker   = ctx.GetBroker <IDeviceEntityBroker>();
                    DeviceSelectCriteria criteria = new DeviceSelectCriteria();
                    criteria.DeviceTypeEnum.EqualTo(DeviceTypeEnum.PriorsServer);
                    criteria.ServerPartitionKey.EqualTo(partition.Key);
                    IList <Device> list = broker.Find(criteria);
                    foreach (Device theDevice in list)
                    {
                        // Check the settings and log for debug purposes
                        if (!theDevice.Enabled)
                        {
                            Platform.Log(LogLevel.Debug, "Prior Server '{0}' on partition '{1}' is disabled in the device setting",
                                         theDevice.AeTitle, partition.AeTitle);
                            continue;
                        }

                        DicomStudyRootQuery remoteQuery = new DicomStudyRootQuery(partition.AeTitle, theDevice.AeTitle,
                                                                                  theDevice.IpAddress, theDevice.Port);
                        priorsServerQueries.Add(remoteQuery);
                    }
                }
            }

            // Log the prior servers for debug purpose
            if (Platform.IsLogLevelEnabled(LogLevel.Debug) && priorsServerQueries.Count > 0)
            {
                StringBuilder log = new StringBuilder();
                log.Append("Searching for priors on the following servers:");

                StringBuilder serverList = new StringBuilder();
                foreach (DicomStudyRootQuery server in priorsServerQueries)
                {
                    if (serverList.Length > 0)
                    {
                        serverList.Append(",");
                    }
                    serverList.AppendFormat("{0}", server);
                }

                log.Append(serverList.ToString());
                Platform.Log(LogLevel.Debug, log.ToString());
            }

            StudyItemList results = new StudyItemList();

            DefaultPatientReconciliationStrategy reconciliationStrategy = new DefaultPatientReconciliationStrategy();
            List <string> patientIds = new List <string>();

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

                IPatientData reconciled = reconciliationStrategy.ReconcileSearchCriteria(patient);
                if (!patientIds.Contains(reconciled.PatientId))
                {
                    patientIds.Add(reconciled.PatientId);
                }
            }

            //Note: we don't catch the exception for this one because it's just querying the other
            //partitions, so if it fails we want an outright failure to occur.  Besides, it should never happen
            //if the server is functioning correctly.
            using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService <IStudyRootQuery>()))
            {
                foreach (string patientId in patientIds)
                {
                    StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier {
                        PatientId = patientId
                    };

                    IList <StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);
                    foreach (StudyRootStudyIdentifier study in studies)
                    {
                        if (_cancel)
                        {
                            break;
                        }

                        StudyItem studyItem = ConvertToStudyItem(study);
                        if (studyItem != null)
                        {
                            results.Add(studyItem);
                        }
                    }
                }
            }

            bool complete = true;

            foreach (IStudyRootQuery query in priorsServerQueries)
            {
                foreach (string patientId in patientIds)
                {
                    try
                    {
                        var identifier = new StudyRootStudyIdentifier
                        {
                            PatientId = patientId
                        };

                        IList <StudyRootStudyIdentifier> list = query.StudyQuery(identifier);
                        foreach (StudyRootStudyIdentifier i in list)
                        {
                            if (_cancel)
                            {
                                break;
                            }

                            StudyItem studyItem = ConvertToStudyItem(i);
                            if (studyItem != null)
                            {
                                results.Add(studyItem);
                            }
                        }
                    }
                    catch (FaultException <DataValidationFault> ex)
                    {
                        complete = false;
                        Platform.Log(LogLevel.Error, ex, "An error has occurred when searching for prior studies on server '{0}'", query.ToString());
                    }
                    catch (FaultException <QueryFailedFault> ex)
                    {
                        complete = false;
                        Platform.Log(LogLevel.Error, ex, "An error has occurred when searching for prior studies on server '{0}'", query.ToString());
                    }
                }
            }

            return(new PriorStudyFinderResult(results, complete));
        }
예제 #10
0
        public override PriorStudyFinderResult FindPriorStudies()
		{
			_cancel = false;

            var priorsServerQueries = new List<IStudyRootQuery>();
            foreach (ServerPartition partition in ServerPartitionMonitor.Instance)
            {
                using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                {
                    IDeviceEntityBroker broker = ctx.GetBroker<IDeviceEntityBroker>();
                    DeviceSelectCriteria criteria = new DeviceSelectCriteria();
                    criteria.DeviceTypeEnum.EqualTo(DeviceTypeEnum.PriorsServer);
                    criteria.ServerPartitionKey.EqualTo(partition.Key);
                    IList<Device> list = broker.Find(criteria);
                    foreach (Device theDevice in list)
                    {
                        // Check the settings and log for debug purposes
                        if (!theDevice.Enabled)
                        {
                            Platform.Log(LogLevel.Debug, "Prior Server '{0}' on partition '{1}' is disabled in the device setting",
                                    theDevice.AeTitle, partition.AeTitle);
                            continue;
                        }

                        DicomStudyRootQuery remoteQuery = new DicomStudyRootQuery(partition.AeTitle, theDevice.AeTitle,
                                                                                  theDevice.IpAddress, theDevice.Port);
                        priorsServerQueries.Add(remoteQuery);
                    }
                }
            }

            // Log the prior servers for debug purpose
            if (Platform.IsLogLevelEnabled(LogLevel.Debug) && priorsServerQueries.Count > 0)
            {
                StringBuilder log = new StringBuilder();
                log.Append("Searching for priors on the following servers:");

                StringBuilder serverList = new StringBuilder();
                foreach (DicomStudyRootQuery server in priorsServerQueries)
                {
                    if (serverList.Length > 0)
                        serverList.Append(",");
                    serverList.AppendFormat("{0}", server);
                }

                log.Append(serverList.ToString());
                Platform.Log(LogLevel.Debug, log.ToString());
            }

            StudyItemList results = new StudyItemList();

			DefaultPatientReconciliationStrategy reconciliationStrategy = new DefaultPatientReconciliationStrategy();
			List<string> patientIds = new List<string>();
			foreach (Patient patient in Viewer.StudyTree.Patients)
			{
				if (_cancel)
					break;

				IPatientData reconciled = reconciliationStrategy.ReconcileSearchCriteria(patient);
				if (!patientIds.Contains(reconciled.PatientId))
					patientIds.Add(reconciled.PatientId);
			}

            //Note: we don't catch the exception for this one because it's just querying the other
            //partitions, so if it fails we want an outright failure to occur.  Besides, it should never happen
            //if the server is functioning correctly.
			using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService<IStudyRootQuery>()))
			{
				foreach (string patientId in patientIds)
				{
					StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier {PatientId = patientId};

				    IList<StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);
					foreach (StudyRootStudyIdentifier study in studies)
					{
						if (_cancel)
							break;

						StudyItem studyItem = ConvertToStudyItem(study);
						if (studyItem != null)
							results.Add(studyItem);
					}
				}
			}

            bool complete = true;
            foreach (IStudyRootQuery query in priorsServerQueries)
            {
                foreach (string patientId in patientIds)
                {

                    try
                    {
                        var identifier = new StudyRootStudyIdentifier
                                             {
                                                 PatientId = patientId
                                             };

                        IList<StudyRootStudyIdentifier> list = query.StudyQuery(identifier);
                        foreach (StudyRootStudyIdentifier i in list)
                        {
                            if (_cancel)
                                break;

                            StudyItem studyItem = ConvertToStudyItem(i);
                            if (studyItem != null)
                                results.Add(studyItem);
                        }
                    }
                    catch (FaultException<DataValidationFault> ex)
                    {
                        complete = false;
                        Platform.Log(LogLevel.Error, ex, "An error has occurred when searching for prior studies on server '{0}'", query.ToString());
                    }
                    catch (FaultException<QueryFailedFault> ex)
                    {
                        complete = false;
                        Platform.Log(LogLevel.Error, ex, "An error has occurred when searching for prior studies on server '{0}'", query.ToString());
                    }
                }
            }

            return new PriorStudyFinderResult(results, complete);
		}