/// <summary>
        /// Do the insertion of the AutoRoute.
        /// </summary>
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            DeviceSelectCriteria deviceSelectCriteria = new DeviceSelectCriteria();

            deviceSelectCriteria.AeTitle.EqualTo(_deviceAe);
            deviceSelectCriteria.ServerPartitionKey.EqualTo(_context.ServerPartitionKey);

            IDeviceEntityBroker selectDevice = updateContext.GetBroker <IDeviceEntityBroker>();

            Device dev = selectDevice.FindOne(deviceSelectCriteria);

            if (dev == null)
            {
                Platform.Log(LogLevel.Warn,
                             "Device '{0}' on partition {1} not in database for autoroute request!  Ignoring request.", _deviceAe,
                             _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(
                    AlertCategory.Application, AlertLevel.Warning,
                    SR.AlertComponentAutorouteRule, AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                    SR.AlertAutoRouteUnknownDestination, _deviceAe, _context.ServerPartition.AeTitle);

                return;
            }
            if (!dev.AllowAutoRoute)
            {
                Platform.Log(LogLevel.Warn,
                             "Auto-route attempted to device {0} on partition {1} with autoroute support disabled.  Ignoring request.",
                             dev.AeTitle, _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(AlertCategory.Application, AlertLevel.Warning, SR.AlertComponentAutorouteRule, AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                                     SR.AlertAutoRouteDestinationAEDisabled, dev.AeTitle, _context.ServerPartition.AeTitle);

                return;
            }

            InsertWorkQueueParameters parms = new InsertWorkQueueParameters
            {
                WorkQueueTypeEnum = WorkQueueTypeEnum.AutoRoute,
                ScheduledTime     = _scheduledTime.HasValue
                                                                                                ? _scheduledTime.Value
                                                                                                : Platform.Time.AddSeconds(10),
                StudyStorageKey    = _context.StudyLocationKey,
                ServerPartitionKey = _context.ServerPartitionKey,
                DeviceKey          = dev.GetKey(),
                SeriesInstanceUid  =
                    _context.Message.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty),
                SopInstanceUid =
                    _context.Message.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty)
            };
            IInsertWorkQueue broker = updateContext.GetBroker <IInsertWorkQueue>();

            if (broker.FindOne(parms) == null)
            {
                throw new ApplicationException("InsertAutoRouteCommand failed");
            }
        }
Beispiel #2
0
        public ImageServerData()
        {
            using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                TotalStudiesCount = 0;

                IServerPartitionEntityBroker partitionBroker = context.GetBroker <IServerPartitionEntityBroker>();
                var partitions = partitionBroker.Find(new ServerPartitionSelectCriteria());
                foreach (ServerPartition partition in partitions)
                {
                    TotalStudiesCount += partition.StudyCount;
                }

                IDeviceEntityBroker  deviceBroker = context.GetBroker <IDeviceEntityBroker>();
                DeviceSelectCriteria criteria     = new DeviceSelectCriteria();
                criteria.Enabled.EqualTo(true);
                ActiveDeviceCount += deviceBroker.Count(criteria);
            }
        }
        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));
        }