Ejemplo n.º 1
0
		public IList<Study> LoadRelatedStudies()
		{
			using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
			{
				IStudyEntityBroker broker = read.GetBroker<IStudyEntityBroker>();
				StudySelectCriteria criteria = new StudySelectCriteria();
				criteria.PatientKey.EqualTo(Key);
				return broker.Find(criteria);
			}
		}
Ejemplo n.º 2
0
		public IList<Study> LoadRelatedStudies()
		{
            using (var context = new ServerExecutionContext())
            {
				IStudyEntityBroker broker = context.ReadContext.GetBroker<IStudyEntityBroker>();
				StudySelectCriteria criteria = new StudySelectCriteria();
				criteria.PatientKey.EqualTo(Key);
				return broker.Find(criteria);
			}
		}
Ejemplo n.º 3
0
		private void Reload()
		{
			using (var ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
			{
				var broker = ctx.GetBroker<IStudyEntityBroker>();
				var criteria = new StudySelectCriteria();
				criteria.AccessionNumber.Like("%" + _accessionTextBox.Text + "%");
				var studies = broker.Find(criteria);

				_studyList.Clear();
				foreach(var item in studies)
					_studyList.Add(new StudyItem(item));
				
			}
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Create a list of SOP Instances to move based on a Patient level C-MOVE-RQ.
        /// </summary>
        /// <param name="read"></param>
        /// <param name="msg"></param>
        /// <param name="errorComment"> </param>
        /// <returns></returns>
        private bool GetSopListForPatient(IPersistenceContext read, DicomMessageBase msg, out string errorComment)
        {
            errorComment = string.Empty;
            string patientId = msg.DataSet[DicomTags.PatientId].GetString(0, "");

            var select = read.GetBroker<IStudyEntityBroker>();

            var criteria = new StudySelectCriteria();
            criteria.PatientId.EqualTo(patientId);
			criteria.ServerPartitionKey.EqualTo(Partition.Key);

            IList<Study> studyList = select.Find(criteria);

        	bool bOfflineFound = false;
            foreach (Study study in studyList)
            {
                StudyStorageLocation location;

				try
				{
					FilesystemMonitor.Instance.GetReadableStudyStorageLocation(Partition.Key, study.StudyInstanceUid,
					                                                           StudyRestore.True, StudyCache.True, out location);
				}
                catch (StudyIsNearlineException e)
                {
                    errorComment = string.Format(e.RestoreRequested ? "Study is nearline, inserted restore request: {0}" : "Study is nearline: {0}", study.StudyInstanceUid);

                    bOfflineFound = true;
                    continue;				        
                }
				catch (Exception e)
				{
				    errorComment = string.Format("Exception occurred when determining study location: {0}", e.Message);
					bOfflineFound = true;
					continue;
				}

            	StudyXml theStream = LoadStudyXml(location);

                _theScu.LoadStudyFromStudyXml(location.GetStudyPath(), theStream);
            }

            return !bOfflineFound;
        }
		private Study GetStudyAndQueues(StudyStorageLocation location, out int integrityQueueCount, out int workQueueCount)
		{
			using (IReadContext context = _store.OpenReadContext())
			{
				IStudyIntegrityQueueEntityBroker integrityBroker = context.GetBroker<IStudyIntegrityQueueEntityBroker>();
				StudyIntegrityQueueSelectCriteria integrityCriteria = new StudyIntegrityQueueSelectCriteria();
				integrityCriteria.StudyStorageKey.EqualTo(location.Key);
				integrityQueueCount = integrityBroker.Count(integrityCriteria);

				IWorkQueueEntityBroker workBroker = context.GetBroker<IWorkQueueEntityBroker>();
				WorkQueueSelectCriteria workCriteria = new WorkQueueSelectCriteria();
				workCriteria.StudyStorageKey.EqualTo(location.Key);
				workQueueCount = workBroker.Count(workCriteria);

				IStudyEntityBroker procedure = context.GetBroker<IStudyEntityBroker>();
				StudySelectCriteria criteria = new StudySelectCriteria();
				criteria.StudyStorageKey.EqualTo(location.Key);
				return procedure.FindOne(criteria);
			}
		}
Ejemplo n.º 6
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            StudyController studyController = new StudyController();
            ServerPartitionConfigController partitionConfigController = new ServerPartitionConfigController();

            string serverae = Request.QueryString[QUERY_KEY_SERVER_AE];
            if (!String.IsNullOrEmpty(serverae))
            {
                // Load the Partition
                ServerPartitionSelectCriteria partitionCriteria = new ServerPartitionSelectCriteria();
                partitionCriteria.AeTitle.EqualTo(serverae);
                IList<ServerPartition> list = partitionConfigController.GetPartitions(partitionCriteria);
                this.Move.Partition = list[0];

                for (int i = 1;; i++)
                {
                    string studyuid = Request.QueryString[String.Format("{0}{1}", QUERY_KEY_STUDY_INSTANCE_UID, i)];

                    if (!String.IsNullOrEmpty(studyuid))
                    {
                        _uids.Add(studyuid, serverae);

                        StudySelectCriteria studyCriteria = new StudySelectCriteria();
                        studyCriteria.StudyInstanceUid.EqualTo(studyuid);
                        studyCriteria.ServerPartitionKey.EqualTo(list[0].GetKey());

                        IList<Study> studyList = studyController.GetStudies(studyCriteria);

                        this.Move.StudyGridView.StudyList.Add(studyList[0]);
                        this.Move.StudyGridView.Partition = this.Move.Partition;
                    }
                    else
                        break;
                }
            }

            SetPageTitle(Titles.MoveStudiesPageTitle);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Find the <see cref="ServerEntityKey"/> reference for a given Study Instance UID and Server Partition.
        /// </summary>
        /// <param name="read">The connection to use to read the values.</param>
        /// <param name="studyInstanceUid">The list of Study Instance Uids for which to retrieve the table keys.</param>
        /// <returns>A list of <see cref="ServerEntityKey"/>s.</returns>
        protected List<ServerEntityKey> LoadStudyKey(IPersistenceContext read, string[] studyInstanceUid)
        {
            var find = read.GetBroker<IStudyEntityBroker>();

            var criteria = new StudySelectCriteria();

            if (Partition!=null)
                criteria.ServerPartitionKey.EqualTo(Partition.Key);

            if (studyInstanceUid.Length > 1)
                criteria.StudyInstanceUid.In(studyInstanceUid);
            else
                criteria.StudyInstanceUid.EqualTo(studyInstanceUid[0]);

            IList<Study> list = find.Find(criteria);

            var serverList = new List<ServerEntityKey>();

            foreach (Study row in list)
                serverList.Add(row.GetKey());

            return serverList;
        }
Ejemplo n.º 8
0
        public bool DeleteOrderItem(ServerEntityKey partitionKey, ServerEntityKey orderKey)
        {
            using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                // Disconnect studies from order
                var studyBroker = updateContext.GetBroker<IStudyEntityBroker>();
                
                var criteria = new StudySelectCriteria();
                criteria.OrderKey.EqualTo(orderKey);
                criteria.ServerPartitionKey.EqualTo(partitionKey);
                
                var updateColumns = new StudyUpdateColumns
                    {
                        OrderKey = null
                    };
                studyBroker.Update(criteria, updateColumns);

                bool retValue = _adaptor.Delete(updateContext, orderKey);

                updateContext.Commit();

                return retValue;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Method for processing Study level queries.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="presentationId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private void OnReceiveStudyLevelQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var find = read.GetBroker<IStudyEntityBroker>();

                var criteria = new StudySelectCriteria();
                criteria.ServerPartitionKey.EqualTo(Partition.GetKey());

                DicomAttributeCollection data = message.DataSet;
                foreach (DicomAttribute attrib in message.DataSet)
                {
                    tagList.Add(attrib.Tag);
                    if (!attrib.IsNull)
                        switch (attrib.Tag.TagValue)
                        {
                            case DicomTags.StudyInstanceUid:
                                QueryHelper.SetStringArrayCondition(criteria.StudyInstanceUid,
                                                        (string[]) data[DicomTags.StudyInstanceUid].Values);
                                break;
                            case DicomTags.PatientsName:
								QueryHelper.SetStringCondition(criteria.PatientsName, data[DicomTags.PatientsName].GetString(0, string.Empty));
                                break;
                            case DicomTags.PatientId:
								QueryHelper.SetStringCondition(criteria.PatientId, data[DicomTags.PatientId].GetString(0, string.Empty));
                                break;
                            case DicomTags.PatientsBirthDate:
                                QueryHelper.SetRangeCondition(criteria.PatientsBirthDate,
												  data[DicomTags.PatientsBirthDate].GetString(0, string.Empty));
                                break;
                            case DicomTags.PatientsSex:
								QueryHelper.SetStringCondition(criteria.PatientsSex, data[DicomTags.PatientsSex].GetString(0, string.Empty));
                                break;
                            case DicomTags.StudyDate:
								QueryHelper.SetRangeCondition(criteria.StudyDate, data[DicomTags.StudyDate].GetString(0, string.Empty));
                                break;
                            case DicomTags.StudyTime:
								QueryHelper.SetRangeCondition(criteria.StudyTime, data[DicomTags.StudyTime].GetString(0, string.Empty));
                                break;
                            case DicomTags.AccessionNumber:
                                QueryHelper.SetStringCondition(criteria.AccessionNumber,
												   data[DicomTags.AccessionNumber].GetString(0, string.Empty));
                                break;
                            case DicomTags.StudyId:
								QueryHelper.SetStringCondition(criteria.StudyId, data[DicomTags.StudyId].GetString(0, string.Empty));
                                break;
                            case DicomTags.StudyDescription:
                                QueryHelper.SetStringCondition(criteria.StudyDescription,
												   data[DicomTags.StudyDescription].GetString(0, string.Empty));
                                break;
                            case DicomTags.ReferringPhysiciansName:
                                QueryHelper.SetStringCondition(criteria.ReferringPhysiciansName,
												   data[DicomTags.ReferringPhysiciansName].GetString(0, string.Empty));
                                break;
                            case DicomTags.ModalitiesInStudy:
                                // Specify a subselect on Modality in series
                                var seriesSelect = new SeriesSelectCriteria();
                                QueryHelper.SetStringArrayCondition(seriesSelect.Modality,
                                                        (string[]) data[DicomTags.ModalitiesInStudy].Values);
                                criteria.SeriesRelatedEntityCondition.Exists(seriesSelect);
                                break;
                            default:
                                foreach (var q in _queryExtensions)
                                    q.OnReceiveStudyLevelQuery(message, attrib.Tag, criteria);
                                break;
                        }
                }

				int resultCount = 0;
				try
                {
                    // Open another read context, in case additional queries are required.
					using (IReadContext subRead = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                    {
						// First find the Online studies
                    	var storageCriteria = new StudyStorageSelectCriteria();
                    	storageCriteria.StudyStatusEnum.NotEqualTo(StudyStatusEnum.Nearline);
						storageCriteria.QueueStudyStateEnum.NotIn(new[] {QueueStudyStateEnum.DeleteScheduled, QueueStudyStateEnum.WebDeleteScheduled, QueueStudyStateEnum.EditScheduled});
                    	criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria);

                        find.Find(criteria, delegate(Study row)
                                                {
													if (CancelReceived)
														throw new DicomException("DICOM C-Cancel Received");

													resultCount++;
													if (DicomSettings.Default.MaxQueryResponses != -1
														&& DicomSettings.Default.MaxQueryResponses < resultCount)
													{
														SendBufferedResponses(server, presentationId, message);
														throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
													}

                                                    var response = new DicomMessage();
                                                    PopulateStudy(subRead, response, tagList, row, "ONLINE");
													_responseQueue.Enqueue(response);

													if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses)
														SendBufferedResponses(server, presentationId, message);
											
                                                });

						// Now find the Nearline studies
						storageCriteria = new StudyStorageSelectCriteria();
						storageCriteria.StudyStatusEnum.EqualTo(StudyStatusEnum.Nearline);
						storageCriteria.QueueStudyStateEnum.NotIn(new[] { QueueStudyStateEnum.DeleteScheduled, QueueStudyStateEnum.WebDeleteScheduled, QueueStudyStateEnum.EditScheduled });
						criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria);

						find.Find(criteria, delegate(Study row)
												{
													if (CancelReceived)
														throw new DicomException("DICOM C-Cancel Received");

													resultCount++;
													if (DicomSettings.Default.MaxQueryResponses != -1
														&& DicomSettings.Default.MaxQueryResponses < resultCount)
													{
														SendBufferedResponses(server, presentationId, message);
														throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
													}

													var response = new DicomMessage();
													PopulateStudy(subRead, response, tagList, row, "NEARLINE");
													_responseQueue.Enqueue(response);

													if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses)
														SendBufferedResponses(server, presentationId, message);

												});

						SendBufferedResponses(server, presentationId, message);
					}
                }
                catch (Exception e)
                {
					if (CancelReceived)
					{
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
												 DicomStatuses.Cancel);
						AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message);
        
					}
					else if (DicomSettings.Default.MaxQueryResponses != -1
						  && DicomSettings.Default.MaxQueryResponses < resultCount)
					{
						Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: {0} on query from {1}", resultCount, server.AssociationParams.CallingAE);
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
												 DicomStatuses.Success);
						AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message);
        
					}
					else
					{
						Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request.");
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
						                         DicomStatuses.ProcessingFailure);
						AuditLog(server.AssociationParams,
								 EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message);

					}
                	return;
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);

			AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message);
        
        	return;
        }
Ejemplo n.º 10
0
        protected void LoadStudy()
        {
            if (String.IsNullOrEmpty(_studyInstanceUid))
                return;

            if (_partition == null)
                return;

		
			StudyAdaptor studyAdaptor = new StudyAdaptor();
			StudySelectCriteria criteria = new StudySelectCriteria();
			criteria.StudyInstanceUid.EqualTo(_studyInstanceUid);
			criteria.ServerPartitionKey.EqualTo(Partition.GetKey());
			Study study = studyAdaptor.GetFirst(HttpContextData.Current.ReadContext, criteria);

            if (study != null)
            {
                _study = StudySummaryAssembler.CreateStudySummary(HttpContextData.Current.ReadContext, study);
            }
            else
            {
                StudyNotFoundException exception =
                    new StudyNotFoundException(_studyInstanceUid);
                ExceptionHandler.ThrowException(exception);
            }
			
        	StudyDetailsPanel.Study = _study;
            StudyDetailsPanel.DataBind();

	        GenerateAuditLog();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Deletes the <see cref="StudyStorage"/> record
        /// </summary>
        /// <param name="item"></param>
        private void DeleteStudyStorage(Model.WorkQueue item)
        {
            using (IUpdateContext context = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                var study = context.GetBroker<IStudyEntityBroker>();
                var criteria = new StudySelectCriteria();

                criteria.StudyInstanceUid.EqualTo(StorageLocation.StudyInstanceUid);
                criteria.ServerPartitionKey.EqualTo(item.ServerPartitionKey);

                int count = study.Count(criteria);
                if (count == 0)
                {
                    Platform.Log(LogLevel.Debug, "StudyProcess Cleanup: removing study storage record...");
                    var delete = context.GetBroker<IDeleteStudyStorage>();

                    var parms = new DeleteStudyStorageParameters
                    {
                        ServerPartitionKey = item.ServerPartitionKey,
                        StudyStorageKey = item.StudyStorageKey
                    };

                    delete.Execute(parms);

                    context.Commit();
                }

            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Method for processing Patient level queries.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="presentationId"></param>
        /// <param name="message">The Patient level query message.</param>
        /// <returns></returns>
        private void OnReceivePatientQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var find = read.GetBroker<IPatientEntityBroker>();

                var criteria = new PatientSelectCriteria();
                criteria.ServerPartitionKey.EqualTo(Partition.GetKey());

                DicomAttributeCollection data = message.DataSet;
            	var studySelect = new StudySelectCriteria();
            	bool studySubSelect = false;
                foreach (DicomAttribute attrib in message.DataSet)
                {
                    tagList.Add(attrib.Tag);
                    if (!attrib.IsNull)
                        switch (attrib.Tag.TagValue)
                        {
                            case DicomTags.PatientsName:
								QueryHelper.SetStringCondition(criteria.PatientsName, data[DicomTags.PatientsName].GetString(0, string.Empty));
                                break;
                            case DicomTags.PatientId:
								QueryHelper.SetStringCondition(criteria.PatientId, data[DicomTags.PatientId].GetString(0, string.Empty));
                                break;
                            case DicomTags.IssuerOfPatientId:
                                QueryHelper.SetStringCondition(criteria.IssuerOfPatientId,
												   data[DicomTags.IssuerOfPatientId].GetString(0, string.Empty));
                                break;
							case DicomTags.PatientsSex:
								// Specify a subselect on Patients Sex in Study
								QueryHelper.SetStringArrayCondition(studySelect.PatientsSex,
														(string[])data[DicomTags.PatientsSex].Values);
								if (!studySubSelect)
								{
									criteria.StudyRelatedEntityCondition.Exists(studySelect);
									studySubSelect = true;
								}
                        		break;

							case DicomTags.PatientsBirthDate:
								// Specify a subselect on Patients Birth Date in Study
								QueryHelper.SetStringArrayCondition(studySelect.PatientsBirthDate,
														(string[])data[DicomTags.PatientsBirthDate].Values);
								if (!studySubSelect)
								{
									criteria.StudyRelatedEntityCondition.Exists(studySelect);
									studySubSelect = true;
								}
								break;
                            default:
                                foreach (var q in _queryExtensions)
                                {
                                    bool extensionSubSelect;
                                    q.OnReceivePatientLevelQuery(message, attrib.Tag, criteria, studySelect, out extensionSubSelect);
                                    if (extensionSubSelect && !studySubSelect)
                                    {
                                        criteria.StudyRelatedEntityCondition.Exists(studySelect);
                                        studySubSelect = true;
                                    }
                                }
                                break;
                        }
                }

				int resultCount = 0;
                try
                {
                    find.Find(criteria, delegate(Patient row)
                                            {
												if (CancelReceived)
													throw new DicomException("DICOM C-Cancel Received");

                                            	resultCount++;
												if (DicomSettings.Default.MaxQueryResponses != -1
													&& DicomSettings.Default.MaxQueryResponses < resultCount)
												{
													SendBufferedResponses(server, presentationId, message);
													throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
												}

                                            	var response = new DicomMessage();
												PopulatePatient(response, tagList, row);
                                            	_responseQueue.Enqueue(response);

												if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses)
													SendBufferedResponses(server, presentationId, message);
                                            });

                	SendBufferedResponses(server, presentationId, message);

                }
                catch (Exception e)
                {
					if (CancelReceived)
					{
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
												 DicomStatuses.Cancel);
					}
					else if (DicomSettings.Default.MaxQueryResponses != -1 
						  && DicomSettings.Default.MaxQueryResponses < resultCount)
					{
						Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: {0} on query from {1}", resultCount, server.AssociationParams.CallingAE);
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
												 DicomStatuses.Success);
						AuditLog(server.AssociationParams,
								 EventIdentificationContentsEventOutcomeIndicator.Success, message);
					}
					else
					{
						Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request.");
						var errorResponse = new DicomMessage();
						server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
						                         DicomStatuses.QueryRetrieveUnableToProcess);
						AuditLog(server.AssociationParams,
								 EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message);
					}
                	return;
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);
			AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message);
        	return;
        }
Ejemplo n.º 13
0
		public int GetStudyCount(StudySelectCriteria criteria)
		{
			return _adaptor.GetCount(criteria);
		}
		/// <summary>
		/// Do the insertion of the AutoRoute.
		/// </summary>
		protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
		{
			var deviceSelectCriteria = new DeviceSelectCriteria();
			deviceSelectCriteria.AeTitle.EqualTo(_deviceAe);
			deviceSelectCriteria.ServerPartitionKey.EqualTo(_context.ServerPartitionKey);

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

			var 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,
				             "Study 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;
			}

			if (_qcStatus != null)
			{
				var studyBroker = updateContext.GetBroker<IStudyEntityBroker>();
				var studySelect = new StudySelectCriteria();
				studySelect.StudyStorageKey.EqualTo(_context.StudyLocationKey);
				studySelect.ServerPartitionKey.EqualTo(_context.ServerPartitionKey);
				var study = studyBroker.FindOne(studySelect);
				if (!study.QCStatusEnum.Equals(_qcStatus))
				{
					Platform.Log(LogLevel.Debug,
					             "Ignoring Auto-route where the QCStatusEnum status must be {0}, but database has {1} for study {2}",
					             _qcStatus.Description, study.QCStatusEnum.Description, study.StudyInstanceUid);
					return;
				}
			}

			var parms = new InsertWorkQueueParameters
			{
				WorkQueueTypeEnum = WorkQueueTypeEnum.StudyAutoRoute,
				ScheduledTime = _scheduledTime.HasValue
									? _scheduledTime.Value
									: Platform.Time.AddSeconds(30),
				StudyStorageKey = _context.StudyLocationKey,
				ServerPartitionKey = _context.ServerPartitionKey,
				DeviceKey = dev.GetKey()
			};
			var broker = updateContext.GetBroker<IInsertWorkQueue>();

			if (broker.FindOne(parms) == null)
			{
				throw new ApplicationException("InsertWorkQueue for Study Auto-Route failed");
			}
		}
Ejemplo n.º 15
0
        private void LoadStudyPartition(string studyInstanceUid)
        {
            using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IStudyEntityBroker selectStudy = read.GetBroker<IStudyEntityBroker>();

                StudySelectCriteria criteria = new StudySelectCriteria();
                criteria.StudyInstanceUid.EqualTo(studyInstanceUid);
                Study theStudy = selectStudy.FindOne(criteria);

                Partition = ServerPartition.Load(read, theStudy.ServerPartitionKey);
            }
        }
Ejemplo n.º 16
0
 public IList<Study> GetStudies(StudySelectCriteria criteria)
 {
     return _adaptor.Get(criteria);
 }
Ejemplo n.º 17
0
        private void LoadSeriesDetails()
        {

            if (!String.IsNullOrEmpty(_serverae) && !String.IsNullOrEmpty(_studyInstanceUid) && !String.IsNullOrEmpty(_seriesInstanceUid))
            {
                StudyAdaptor studyAdaptor = new StudyAdaptor();
                SeriesSearchAdaptor seriesAdaptor = new SeriesSearchAdaptor();
                        
                ServerPartitionDataAdapter adaptor = new ServerPartitionDataAdapter();
                ServerPartitionSelectCriteria criteria = new ServerPartitionSelectCriteria();
                criteria.AeTitle.EqualTo(_serverae);

                Model.ServerPartition partition = adaptor.GetFirst(criteria);
                if (partition != null)
                {
                    Partition = partition;

                    StudySelectCriteria studyCriteria = new StudySelectCriteria();
                    studyCriteria.StudyInstanceUid.EqualTo(_studyInstanceUid);
                    studyCriteria.ServerPartitionKey.EqualTo(Partition.GetKey());
                    Model.Study study = studyAdaptor.GetFirst(studyCriteria);

                    if (study != null)
                    {
                        // there should be only one study
                        _study = study;

                        SeriesSelectCriteria seriesCriteria = new SeriesSelectCriteria();
                        seriesCriteria.SeriesInstanceUid.EqualTo(_seriesInstanceUid);
                        Series series = seriesAdaptor.GetFirst(seriesCriteria);

                        if (series != null)
                        {
                            _series = series;
                        }
                    }

                }
            }

            if (_study!=null && _series != null)
            {
                SeriesDetailsPanel1.Study = _study;
                SeriesDetailsPanel1.Series = _series;
            }

            DataBind();
        }
Ejemplo n.º 18
0
 static public Study Find(IPersistenceContext context, ServerEntityKey studyStorageKey)
 {
     IStudyEntityBroker broker = context.GetBroker<IStudyEntityBroker>();
     StudySelectCriteria criteria = new StudySelectCriteria();
     criteria.StudyStorageKey.EqualTo( studyStorageKey);
     return broker.FindOne(criteria);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Create a list of DICOM SOP Instances to move based on a Series level C-MOVE-RQ
        /// </summary>
        /// <param name="persistenceContext"></param>
        /// <param name="msg"></param>
        /// <param name="errorComment"> </param>
        /// <returns></returns>
        private bool GetSopListForSeries(IPersistenceContext persistenceContext, DicomMessageBase msg, out string errorComment)
        {
            errorComment = string.Empty;
            string studyInstanceUid = msg.DataSet[DicomTags.StudyInstanceUid].GetString(0, "");
            var seriesList = (string[])msg.DataSet[DicomTags.SeriesInstanceUid].Values;

            // Now get the storage location
            StudyStorageLocation location;

			try
			{
				FilesystemMonitor.Instance.GetReadableStudyStorageLocation(Partition.Key, studyInstanceUid, StudyRestore.True,
				                                                           StudyCache.True, out location);
			}
			catch(StudyIsNearlineException e)
			{
                errorComment = string.Format(e.RestoreRequested ? "Study is nearline, inserted restore request: {0}" : "Study is nearline: {0}", studyInstanceUid);
				return false;
			}
			catch (Exception e)
			{
                errorComment = string.Format("Exception occurred when determining study location: {0}", e.Message);
                return false;
			}

			var select = persistenceContext.GetBroker<IStudyEntityBroker>();

			var criteria = new StudySelectCriteria();
			criteria.StudyInstanceUid.EqualTo(studyInstanceUid);
			criteria.ServerPartitionKey.EqualTo(Partition.Key);

			Study study = select.FindOne(criteria);
        	StudyXml studyStream = LoadStudyXml(location);

            foreach (string seriesInstanceUid in seriesList)
            {
				_theScu.LoadSeriesFromSeriesXml(studyStream, Path.Combine(location.GetStudyPath(), seriesInstanceUid), studyStream[seriesInstanceUid], study.PatientsName, study.PatientId);
            }

            return true;
        }
 public StudySelectCriteria(StudySelectCriteria other)
 : base(other)
 {}
Ejemplo n.º 21
0
        private static IList<StudySummary> LoadStudies(WebViewerInitParams initParams)
        {

            ValidateParameters(initParams);

            var controller = new StudyController();
            var partitionAdapter = new ServerPartitionDataAdapter();
            StudySelectCriteria studyCriteria;
            var partitionCriteria = new ServerPartitionSelectCriteria();
            ServerPartition partition = null;
            IList<Study> studies;
            List<StudySummary> totalStudies = new List<StudySummary>();

            if (!string.IsNullOrEmpty(initParams.AeTitle))
            {
                partitionCriteria.AeTitle.EqualTo(initParams.AeTitle);
                IList<ServerPartition> partitions = partitionAdapter.GetServerPartitions(partitionCriteria);
                if (partitions.Count == 1)
                {
                    partition = partitions[0];
                }
            }

            foreach (string patientId in initParams.PatientIds)
            {
                studyCriteria = new StudySelectCriteria();                
                if (partition != null) studyCriteria.ServerPartitionKey.EqualTo(partition.Key);
                SetStringCondition(studyCriteria.PatientId, patientId);
                studyCriteria.StudyDate.SortDesc(0);
                studies = controller.GetStudies(studyCriteria);

                foreach (Study study in studies)
                {
                    totalStudies.Add(StudySummaryAssembler.CreateStudySummary(HttpContextData.Current.ReadContext, study));
                }
            }

            foreach (string accession in initParams.AccessionNumbers)
            {
                studyCriteria = new StudySelectCriteria();
                if (partition != null) studyCriteria.ServerPartitionKey.EqualTo(partition.Key);
                SetStringCondition(studyCriteria.AccessionNumber, accession);
                studyCriteria.StudyDate.SortDesc(0);
                studies = controller.GetStudies(studyCriteria);

                foreach (Study study in studies)
                {
                    totalStudies.Add(StudySummaryAssembler.CreateStudySummary(HttpContextData.Current.ReadContext, study));
                }
            }

            if (initParams.StudyInstanceUids.Count > 0)
            {
                studyCriteria = new StudySelectCriteria();
                if (partition != null) studyCriteria.ServerPartitionKey.EqualTo(partition.Key);
                studyCriteria.StudyInstanceUid.In(initParams.StudyInstanceUids);
                studyCriteria.StudyDate.SortDesc(0);
                studies = controller.GetStudies(studyCriteria);

                foreach (Study study in studies)
                {
                    totalStudies.Add(StudySummaryAssembler.CreateStudySummary(HttpContextData.Current.ReadContext, study));
                }
            }

            totalStudies.Sort((a, b) => a.StudyDate.CompareTo(b.StudyDate) * -1);

            return totalStudies;
        }
Ejemplo n.º 22
0
        private static WorkQueueDetails CreateEditWorkQueueItemDetails(Model.WorkQueue item)
        {
            string studyPath;
            try
            {
                StudyStorageLocation storage = WorkQueueController.GetLoadStorageLocation(item);
                studyPath = storage.GetStudyPath();
            }
            catch(Exception)
            {
                studyPath = string.Empty;
            }
            var detail = new WorkQueueDetails
                             {
                                 Key = item.Key,
                                 ScheduledDateTime = item.ScheduledTime,
                                 ExpirationTime = item.ExpirationTime,
                                 InsertTime = item.InsertTime,
                                 FailureCount = item.FailureCount,
                                 Type = item.WorkQueueTypeEnum,
                                 Status = item.WorkQueueStatusEnum,
                                 Priority = item.WorkQueuePriorityEnum,
                                 FailureDescription = item.FailureDescription,
                                 ServerDescription = item.ProcessorID,
                                 StorageLocationPath = studyPath
                             };



            // Fetch UIDs
            var wqUidsAdaptor = new WorkQueueUidAdaptor();
            var uidCriteria = new WorkQueueUidSelectCriteria();
            uidCriteria.WorkQueueKey.EqualTo(item.GetKey());
            IList<WorkQueueUid> uids = wqUidsAdaptor.Get(uidCriteria);

            var mapSeries = new Hashtable();
            foreach (WorkQueueUid uid in uids)
            {
                if (mapSeries.ContainsKey(uid.SeriesInstanceUid) == false)
                    mapSeries.Add(uid.SeriesInstanceUid, uid.SopInstanceUid);
            }

            detail.NumInstancesPending = uids.Count;
            detail.NumSeriesPending = mapSeries.Count;


            // Fetch the study and patient info
            var ssAdaptor = new StudyStorageAdaptor();
            StudyStorage storages = ssAdaptor.Get(item.StudyStorageKey);

            var studyAdaptor = new StudyAdaptor();
            var studycriteria = new StudySelectCriteria();
            studycriteria.StudyInstanceUid.EqualTo(storages.StudyInstanceUid);
            studycriteria.ServerPartitionKey.EqualTo(item.ServerPartitionKey);
            Study study = studyAdaptor.GetFirst(studycriteria);

            // Study may not be available until the images are processed.
            if (study != null)
            {
                var studyAssembler = new StudyDetailsAssembler();
                detail.Study = studyAssembler.CreateStudyDetail(study);
            }

            var parser = new EditStudyWorkQueueDataParser();
            EditStudyWorkQueueData data = parser.Parse(item.Data.DocumentElement);

            detail.EditUpdateItems = data.EditRequest.UpdateEntries.ToArray();

            return detail;
        }
Ejemplo n.º 23
0
		/// <summary>
		/// Constructs an instance of <see cref="WorkQueueSummary"/> based on a <see cref="WorkQueue"/> object.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		/// <remark>
		/// 
		/// </remark>
		private ArchiveQueueSummary CreateWorkQueueSummary(ArchiveQueue item)
		{
			ArchiveQueueSummary summary = new ArchiveQueueSummary();
			summary.TheArchiveQueueItem = item;
			summary.ThePartition = Partition;

			if (item.FailureDescription == null)
				summary.Notes = String.Empty;
			else 
				summary.Notes = item.FailureDescription;

			// Fetch the patient info:
			StudyStorageAdaptor ssAdaptor = new StudyStorageAdaptor();
			summary.StudyStorage = ssAdaptor.Get(item.StudyStorageKey);
			if (summary.StudyStorage == null)
			{
				summary.PatientId = "N/A";
				summary.PatientsName = "N/A";
				return summary;
			}
			StudyAdaptor studyAdaptor = new StudyAdaptor();
			StudySelectCriteria studycriteria = new StudySelectCriteria();
			studycriteria.StudyInstanceUid.EqualTo(summary.StudyStorage.StudyInstanceUid);
			studycriteria.ServerPartitionKey.EqualTo(summary.StudyStorage.ServerPartitionKey);
			Study theStudy = studyAdaptor.GetFirst(studycriteria);

			if (theStudy == null)
			{
				summary.PatientId = "N/A";
				summary.PatientsName = "N/A";
			}
			else
			{
				summary.PatientId = theStudy.PatientId;
				summary.PatientsName = theStudy.PatientsName;
			}

			return summary;
		}
Ejemplo n.º 24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ServerPartitionConfigController partitionConfigController = new ServerPartitionConfigController();

            string serverae = Request.QueryString[ImageServerConstants.QueryStrings.ServerAE];

            if (!String.IsNullOrEmpty(serverae))
            {
                // Load the Partition
                ServerPartitionSelectCriteria partitionCriteria = new ServerPartitionSelectCriteria();
                partitionCriteria.AeTitle.EqualTo(serverae);
                IList<ServerPartition> list = partitionConfigController.GetPartitions(partitionCriteria);
                Partition = list[0];
                SeriesGridView.Partition = Partition;
            
                string studyuid = Request.QueryString[ImageServerConstants.QueryStrings.StudyUID];

                if (!String.IsNullOrEmpty(studyuid) || Partition != null)
                {
                    StudyController studyController = new StudyController();
                    StudySelectCriteria criteria = new StudySelectCriteria();
                    criteria.StudyInstanceUid.EqualTo(studyuid);
                    criteria.ServerPartitionKey.EqualTo(Partition.Key);

                    IList<Study> studyList = studyController.GetStudies(criteria);

                    SelectedStudy = studyList[0];
                    SeriesGridView.Study = studyList[0];
                    PatientSummary.PatientSummary = PatientSummaryAssembler.CreatePatientSummary(studyList[0]);
                    StudySummary.Study = studyList[0];
                }
            }

            if (DHCPFilter.Items.Count == 0)
            {
                DHCPFilter.Items.Add(new ListItem(SR.All));
                DHCPFilter.Items.Add(new ListItem(SR.DHCP));
                DHCPFilter.Items.Add(new ListItem(SR.NoDHCP));
            }

            IList<DeviceTypeEnum> deviceTypes = DeviceTypeEnum.GetAll();

            if (DeviceTypeFilter.Items.Count == 0)
            {
                foreach (DeviceTypeEnum t in deviceTypes)
                {
                    DeviceTypeFilter.Items.Add(new ListItem(ServerEnumDescription.GetLocalizedDescription(t), t.Lookup));
                }
            }
            else
            {
                ListItem[] typeItems = new ListItem[DeviceTypeFilter.Items.Count];
                DeviceTypeFilter.Items.CopyTo(typeItems, 0);
                DeviceTypeFilter.Items.Clear();
                int count = 0;
                foreach (DeviceTypeEnum t in deviceTypes)
                {
                    DeviceTypeFilter.Items.Add(new ListItem(ServerEnumDescription.GetLocalizedDescription(t), t.Lookup));
                    DeviceTypeFilter.Items[count].Selected = typeItems[count].Selected;
                    count++;
                }
            }

            LoadSeries();
            LoadDevices();

            DataBind();
        }
Ejemplo n.º 25
0
		/// <summary>
		/// Constructs an instance of <see cref="WorkQueue"/> based on a <see cref="WorkQueueSummary"/> object.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		/// <remark>
		/// 
		/// </remark>
		private RestoreQueueSummary CreateWorkQueueSummary(RestoreQueue item)
		{
			RestoreQueueSummary summary = new RestoreQueueSummary();
			summary.TheRestoreQueueItem = item;
			summary.ThePartition = Partition;

			if (item.FailureDescription == null)
				summary.Notes = String.Empty;
			else
				summary.Notes = item.FailureDescription;

			// Fetch the patient info:
			StudyStorageAdaptor ssAdaptor = new StudyStorageAdaptor();
			summary.StudyStorage = ssAdaptor.Get(item.StudyStorageKey);
			if (summary.StudyStorage == null)
			{
				summary.PatientId = "N/A";
				summary.PatientsName = "N/A";
				return summary;
			}
			StudyAdaptor studyAdaptor = new StudyAdaptor();
			StudySelectCriteria studycriteria = new StudySelectCriteria();
			studycriteria.StudyInstanceUid.EqualTo(summary.StudyStorage.StudyInstanceUid);
			studycriteria.ServerPartitionKey.EqualTo(summary.StudyStorage.ServerPartitionKey);
			IList<Study> studyList = studyAdaptor.Get(studycriteria);

			if (studyList == null || studyList.Count == 0)
			{
				summary.PatientId = "N/A";
				summary.PatientsName = "N/A";
			}
			else
			{
				summary.PatientId = studyList[0].PatientId;
				summary.PatientsName = studyList[0].PatientsName;
			}

			return summary;
		}
Ejemplo n.º 26
0
		public IList<Study> GetRangeStudies(StudySelectCriteria criteria, int startIndex, int maxRows)
		{
			return _adaptor.GetRange(criteria,startIndex,maxRows);
		}
Ejemplo n.º 27
0
        private static WorkQueueDetails CreateGeneralWorkQueueItemDetails(Model.WorkQueue item)
        {
            var detail = new WorkQueueDetails();

            detail.Key = item.Key;
            detail.ScheduledDateTime = item.ScheduledTime;
            detail.ExpirationTime = item.ExpirationTime;
            detail.InsertTime = item.InsertTime;
            detail.FailureCount = item.FailureCount;
            detail.Type = item.WorkQueueTypeEnum;
            detail.Status = item.WorkQueueStatusEnum;
            detail.Priority = item.WorkQueuePriorityEnum;
            detail.FailureDescription = item.FailureDescription;
            detail.ServerDescription = item.ProcessorID;

            StudyStorageLocation storage = WorkQueueController.GetLoadStorageLocation(item);
            detail.StorageLocationPath = storage.GetStudyPath();

            // Fetch UIDs
            var wqUidsAdaptor = new WorkQueueUidAdaptor();
            var uidCriteria = new WorkQueueUidSelectCriteria();
            uidCriteria.WorkQueueKey.EqualTo(item.GetKey());
            IList<WorkQueueUid> uids = wqUidsAdaptor.Get(uidCriteria);

            var mapSeries = new Hashtable();
            foreach (WorkQueueUid uid in uids)
            {
                if (mapSeries.ContainsKey(uid.SeriesInstanceUid) == false)
                    mapSeries.Add(uid.SeriesInstanceUid, uid.SopInstanceUid);
            }

            detail.NumInstancesPending = uids.Count;
            detail.NumSeriesPending = mapSeries.Count;


            // Fetch the study and patient info
            var ssAdaptor = new StudyStorageAdaptor();
            StudyStorage storages = ssAdaptor.Get(item.StudyStorageKey);

            var studyAdaptor = new StudyAdaptor();
            var studycriteria = new StudySelectCriteria();
            studycriteria.StudyInstanceUid.EqualTo(storages.StudyInstanceUid);
            studycriteria.ServerPartitionKey.EqualTo(item.ServerPartitionKey);
            Study study = studyAdaptor.GetFirst(studycriteria);

            // Study may not be available until the images are processed.
            if (study != null)
            {
                var studyAssembler = new StudyDetailsAssembler();
                detail.Study = studyAssembler.CreateStudyDetail(study);
            }
            return detail;
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Find a <see cref="Study"/> with the specified study instance uid on the given partition.
 /// </summary>
 /// <param name="studyInstanceUid"></param>
 /// <param name="partition"></param>
 /// <returns></returns>
 /// 
 static public Study Find(IPersistenceContext context, String studyInstanceUid, ServerPartition partition)
 {
     IStudyEntityBroker broker = context.GetBroker<IStudyEntityBroker>();
     StudySelectCriteria criteria = new StudySelectCriteria();
     criteria.ServerPartitionKey.EqualTo(partition.GetKey());
     criteria.StudyInstanceUid.EqualTo(studyInstanceUid);
     Study study = broker.FindOne(criteria);
     return study;
    
 }
 public StudySelectCriteria(StudySelectCriteria other)
     : base(other)
 {
 }
Ejemplo n.º 30
0
        protected Study LoadStudy(string studyInstanceUID)
        {
            if (String.IsNullOrEmpty(studyInstanceUID))
                return null;

            if (_partition == null)
                return null;

            StudyAdaptor studyAdaptor = new StudyAdaptor();
            StudySelectCriteria criteria = new StudySelectCriteria();
            criteria.StudyInstanceUid.EqualTo(studyInstanceUID);
            criteria.ServerPartitionKey.EqualTo(Partition.Key);
            return studyAdaptor.GetFirst(criteria);
        }
Ejemplo n.º 31
0
		/// <summary>
		/// Constructs an instance of <see cref="WorkQueueSummary"/> based on a <see cref="WorkQueue"/> object.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		/// <remark>
		/// 
		/// </remark>
		private WorkQueueSummary CreateWorkQueueSummary(WorkQueue item)
		{
			WorkQueueSummary summary = new WorkQueueSummary
			                           	{
			                           		TheWorkQueueItem = item,
			                           		ThePartition = Partition
			                           	};

			// Fetch the patient info:
			StudyStorageAdaptor ssAdaptor = new StudyStorageAdaptor();
			StudyStorage storages = ssAdaptor.Get(item.StudyStorageKey);
			if (storages == null)
			{
				summary.PatientId = "N/A";
				summary.PatientsName = "N/A";
				return summary;
			}
			StudyAdaptor studyAdaptor = new StudyAdaptor();
			StudySelectCriteria studycriteria = new StudySelectCriteria();
			studycriteria.StudyInstanceUid.EqualTo(storages.StudyInstanceUid);
			studycriteria.ServerPartitionKey.EqualTo(item.ServerPartitionKey);
			IList<Study> studyList = studyAdaptor.Get(studycriteria);

			if (studyList == null || studyList.Count == 0)
			{
				summary.PatientId = "N/A";
				summary.PatientsName = "N/A";
			}
			else
			{
				summary.PatientId = studyList[0].PatientId;
				summary.PatientsName = studyList[0].PatientsName;
			}

			if (item.WorkQueueTypeEnum == WorkQueueTypeEnum.WebMoveStudy
			    || item.WorkQueueTypeEnum == WorkQueueTypeEnum.AutoRoute)
			{
				DeviceDataAdapter deviceAdaptor = new DeviceDataAdapter();
				Device dest = deviceAdaptor.Get(item.DeviceKey);

				summary.Notes = String.Format("Destination AE : {0}", dest.AeTitle);

				if (item.FailureDescription != null)
				{
					summary.FullDescription = String.Format("{0}, {1}", summary.Notes, item.FailureDescription);   //Set the FullDescription for the Tooltip in the GUI
					summary.Notes = summary.FullDescription.Length > 60 
						? summary.FullDescription.Substring(0, 60) 
						: summary.FullDescription;
				}
			}
			else if (item.FailureDescription != null)
			{
				// This used to only be shown when the status was "Failed" for a 
				// queue entry.  We now show it any time there's 
				if (item.FailureDescription.Length > 60)
				{
					summary.Notes = item.FailureDescription.Substring(0, 60);
					summary.Notes += " ...";
				    summary.FullDescription = item.FailureDescription;  //Set the FullDescription for the Tooltip in the GUI
				}
				else
					summary.Notes = item.FailureDescription;
			}

            summary.RequiresAttention = item.WorkQueueStatusEnum.Equals(WorkQueueStatusEnum.Failed) || !ServerPlatform.IsActiveWorkQueue(item);
			return summary;
		}