Exemple #1
0
        private void Apply_Click(object sender, EventArgs e)
        {
            var view = dataGridView1.SelectedRows[0].DataBoundItem as DataRowView;
            if (view != null)
            {
                var guid = (Guid) view.Row["GUID"];

                IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();

                using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush))
                {
                    var studyBroker = ctx.GetBroker<IStudyEntityBroker>();
                    var key = new ServerEntityKey("Study", guid);
                    Model.Study study = studyBroker.Load(key);

                    var storageBroker = ctx.GetBroker<IStudyStorageEntityBroker>();
                    var parms = new StudyStorageSelectCriteria();
                    parms.ServerPartitionKey.EqualTo(study.ServerPartitionKey);
                    parms.StudyInstanceUid.EqualTo(study.StudyInstanceUid);

                    Model.StudyStorage storage = storageBroker.Find(parms)[0];


                    var workQueueBroker = ctx.GetBroker<IWorkQueueEntityBroker>();
                    var columns = new WorkQueueUpdateColumns
                                      {
                                          ServerPartitionKey = study.ServerPartitionKey,
                                          StudyStorageKey = storage.GetKey(),
                                          ExpirationTime = DateTime.Now.AddHours(1),
                                          ScheduledTime = DateTime.Now,
                                          InsertTime = DateTime.Now,
                                          WorkQueuePriorityEnum = Model.WorkQueuePriorityEnum.Medium,
                                          WorkQueueStatusEnum = Model.WorkQueueStatusEnum.Pending,
                                          WorkQueueTypeEnum = Model.WorkQueueTypeEnum.WebEditStudy
                                      };

                    var doc = new XmlDocument();
                    doc.Load(new StringReader(textBox1.Text));

                    columns.Data = doc;

                    workQueueBroker.Insert(columns);

                    ctx.Commit();
                }
            }
        }
		/// <summary>
		/// Get a list of candidates from the <see cref="FilesystemQueue"/>.
		/// </summary>
		/// <param name="item">The ServiceLock item.</param>
		/// <param name="scheduledTime">The scheduled time to query against</param>
		/// <param name="type">The type of FilesystemQueue entry.</param>
		/// <param name="statusCheck">If true, check for specific status value WorkQueue entries already existing, otherwise check for any WorkQueue entry.</param>
		/// <returns>The list of queue entries.</returns>
        protected IList<FilesystemQueue> GetFilesystemQueueCandidates(Model.ServiceLock item, DateTime scheduledTime, FilesystemQueueTypeEnum type, bool statusCheck)
        {
			using (ServerExecutionContext context = new ServerExecutionContext())
			{
				IFilesystemQueueEntityBroker broker = context.ReadContext.GetBroker<IFilesystemQueueEntityBroker>();
				FilesystemQueueSelectCriteria fsQueueCriteria = new FilesystemQueueSelectCriteria();

				fsQueueCriteria.FilesystemKey.EqualTo(item.FilesystemKey);
				fsQueueCriteria.ScheduledTime.LessThanOrEqualTo(scheduledTime);
				fsQueueCriteria.FilesystemQueueTypeEnum.EqualTo(type);

				// Do the select based on the QueueStudyState (used to be based on a link to the WorkQueue table)
				StudyStorageSelectCriteria studyStorageSearchCriteria = new StudyStorageSelectCriteria();
				studyStorageSearchCriteria.QueueStudyStateEnum.EqualTo(QueueStudyStateEnum.Idle);
				fsQueueCriteria.StudyStorage.Exists(studyStorageSearchCriteria);

				fsQueueCriteria.ScheduledTime.SortAsc(0);

				IList<FilesystemQueue> list = broker.Find(fsQueueCriteria, 0, ServiceLockSettings.Default.FilesystemQueueResultCount);

				return list;
			}
        }
        /// <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;
        }
Exemple #4
0
		private static StudyStorage FindStudyStorage(ScanResultEntry result)
        {
            using(IReadContext ctx= PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IStudyStorageEntityBroker broker = ctx.GetBroker<IStudyStorageEntityBroker>();
                StudyStorageSelectCriteria criteria = new StudyStorageSelectCriteria();
                criteria.StudyInstanceUid.EqualTo(result.StudyInstanceUid);
            	criteria.ServerPartitionKey.EqualTo(result.ServerPartitionKey);
                return broker.FindOne(criteria);
            }
        }
 public StudyStorageSelectCriteria(StudyStorageSelectCriteria other)
 : base(other)
 {}
Exemple #6
0
		public static StudyStorage Load(IPersistenceContext read, ServerEntityKey partitionKey, string studyInstanceUid)
		{
	        var broker = read.GetBroker<IStudyStorageEntityBroker>();
			var criteria = new StudyStorageSelectCriteria();
			criteria.StudyInstanceUid.EqualTo(studyInstanceUid);
			criteria.ServerPartitionKey.EqualTo(partitionKey);
            StudyStorage theObject = broker.FindOne(criteria);
            return theObject;        
		}
 public StudyStorageSelectCriteria(StudyStorageSelectCriteria other)
     : base(other)
 {
 }
Exemple #8
0
		private StudySelectCriteria GetSelectCriteria()
		{
			var criteria = new StudySelectCriteria();

			// only query for device in this partition
			criteria.ServerPartitionKey.EqualTo(Partition.Key);

            QueryHelper.SetGuiStringCondition(criteria.PatientId,PatientId);
            QueryHelper.SetGuiStringCondition(criteria.PatientsName, PatientName);

			criteria.PatientsName.SortAsc(0);

            QueryHelper.SetGuiStringCondition(criteria.AccessionNumber, AccessionNumber);

            if (!String.IsNullOrEmpty(ToStudyDate) && !String.IsNullOrEmpty(FromStudyDate))
			{
                string toKey = DateTime.ParseExact(ToStudyDate, DateFormats, null).ToString(STUDYDATE_DATEFORMAT) + " 23:59:59.997";
                string fromKey = DateTime.ParseExact(FromStudyDate, DateFormats, null).ToString(STUDYDATE_DATEFORMAT);
				criteria.StudyDate.Between(fromKey, toKey);
            }
            else if (!String.IsNullOrEmpty(ToStudyDate))
            {
                string toKey = DateTime.ParseExact(ToStudyDate, DateFormats, null).ToString(STUDYDATE_DATEFORMAT);
                criteria.StudyDate.LessThanOrEqualTo(toKey);
            }
            else if (!String.IsNullOrEmpty(FromStudyDate))
            {
                string fromKey = DateTime.ParseExact(FromStudyDate, DateFormats, null).ToString(STUDYDATE_DATEFORMAT);
                criteria.StudyDate.MoreThanOrEqualTo(fromKey);
            }

            QueryHelper.SetGuiStringCondition(criteria.StudyDescription, StudyDescription);
            QueryHelper.SetGuiStringCondition(criteria.ReferringPhysiciansName, ReferringPhysiciansName);
            QueryHelper.SetGuiStringCondition(criteria.ResponsiblePerson, ResponsiblePerson);
            QueryHelper.SetGuiStringCondition(criteria.ResponsibleOrganization, ResponsibleOrganization);

            if(Modalities != null && Modalities.Length > 0)
			{
				var seriesCriteria = new SeriesSelectCriteria();

                QueryHelper.SetStringArrayCondition(seriesCriteria.Modality, Modalities);

				criteria.SeriesRelatedEntityCondition.Exists(seriesCriteria);
			}

            if (Statuses != null && Statuses.Length > 0)
            {
                var storageCriteria = new StudyStorageSelectCriteria();
                if (Statuses.Length == 1)
                    storageCriteria.StudyStatusEnum.EqualTo(StudyStatusEnum.GetEnum(Statuses[0]));
                else
                {
                    var statusList = new List<StudyStatusEnum>();
                    foreach(string status in Statuses)
                    {
                        statusList.Add(StudyStatusEnum.GetEnum(status));
                    }

                    storageCriteria.StudyStatusEnum.In(statusList);
                }

                criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria);
            }

			return criteria;
		}
Exemple #9
0
        /// <summary>
        /// Method for processing Study level queries.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        public override void Query(DicomAttributeCollection message, ServerQueryResultDelegate del)
        {
            var tagList = new List<uint>();

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

                //TODO (CR May 2010): Should change so that the Partition AE Title is passed in the RetrieveAeTitle tag in the query message.

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

                if (!Thread.CurrentPrincipal.IsInRole(ClearCanvas.Enterprise.Common.AuthorityTokens.DataAccess.AllStudies))
                {
                    var principal = Thread.CurrentPrincipal as CustomPrincipal;
                    if (principal != null)
                    {
                        var oidList = new List<ServerEntityKey>();
                        foreach (var oid in principal.Credentials.DataAccessAuthorityGroups)
                            oidList.Add(new ServerEntityKey("OID", oid));
                        var dataAccessGroupSelectCriteria = new DataAccessGroupSelectCriteria();
                        dataAccessGroupSelectCriteria.AuthorityGroupOID.In(oidList);
                        IList<DataAccessGroup> groups;
                        using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                        {
                            var broker = context.GetBroker<IDataAccessGroupEntityBroker>();
                            groups = broker.Find(dataAccessGroupSelectCriteria);
                        }

                        var entityList = new List<ServerEntityKey>();
                        foreach (DataAccessGroup group in groups)
                        {
                            entityList.Add(group.Key);
                        }

                        var dataAccessSelectCriteria = new StudyDataAccessSelectCriteria();
                        dataAccessSelectCriteria.DataAccessGroupKey.In(entityList);

                        criteria.StudyDataAccessRelatedEntityCondition.Exists(dataAccessSelectCriteria);
                    }
                }



                DicomAttributeCollection data = message;
                foreach (DicomAttribute attrib in message)
                {
                    tagList.Add(attrib.Tag.TagValue);
                    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;
                        }
                }

                // 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)
                                            {
                                                var response = new DicomMessage();

                                            	//TODO (CR May 2010): should the availability be NEARLINE?  The criteria above was for ONLINE studies.
                                                PopulateStudy(subRead, response, tagList, row, "NEARLINE");
                                                del(response.DataSet);
                                            });

                    // 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)
                    {
                        var response = new DicomMessage();
                        PopulateStudy(subRead, response, tagList, row, "NEARLINE");
                        del(response.DataSet);
                    });

                }
            }

            return;
        }