예제 #1
0
        public IList<ArchiveStudyStorage> GetArchiveStudyStorage(Study study)
        {
        	Platform.CheckForNullReference(study, "Study");

        	ArchiveStudyStorageAdaptor adaptor = new ArchiveStudyStorageAdaptor();
        	ArchiveStudyStorageSelectCriteria archiveStudyStorageCriteria = new ArchiveStudyStorageSelectCriteria();
        	archiveStudyStorageCriteria.StudyStorageKey.EqualTo(study.StudyStorageKey);
        	archiveStudyStorageCriteria.ArchiveTime.SortDesc(0);

        	return adaptor.Get(archiveStudyStorageCriteria);
        }
예제 #2
0
        public ArchiveStudyStorage GetFirstArchiveStudyStorage(IPersistenceContext read, ServerEntityKey studyStorageKey)
        {
            Platform.CheckForNullReference(studyStorageKey, "studyStorageKey");

            ArchiveStudyStorageAdaptor adaptor = new ArchiveStudyStorageAdaptor();
            ArchiveStudyStorageSelectCriteria archiveStudyStorageCriteria = new ArchiveStudyStorageSelectCriteria();
            archiveStudyStorageCriteria.StudyStorageKey.EqualTo(studyStorageKey);
            archiveStudyStorageCriteria.ArchiveTime.SortDesc(0);

            return adaptor.GetFirst(read, archiveStudyStorageCriteria);
        }
        /// <summary>
        /// Determine if the specified partition can be deleted. If studies are scheduled
        /// to be archived on that partition or studies are already archived on that partition,
        /// then the partition may not be deleted.
        /// 
        /// </summary>
        /// <param name="partition"></param>
        /// <returns></returns>
        public bool CanDelete(PartitionArchive partition)
        {          
            ArchiveQueueAdaptor archiveQueueAdaptor = new ArchiveQueueAdaptor();
            ArchiveQueueSelectCriteria selectCriteria = new ArchiveQueueSelectCriteria();
            selectCriteria.PartitionArchiveKey.EqualTo(partition.GetKey());

            ArchiveStudyStorageAdaptor archiveStudyStorageAdaptor = new ArchiveStudyStorageAdaptor();
            ArchiveStudyStorageSelectCriteria criteria = new ArchiveStudyStorageSelectCriteria();
            criteria.PartitionArchiveKey.EqualTo(partition.GetKey());

            int queueItems = archiveQueueAdaptor.GetCount(selectCriteria);
			int storageItems = 0;
			// only check if we need to.
			if (queueItems == 0) storageItems = archiveStudyStorageAdaptor.GetCount(criteria);

			return !((queueItems > 0) || (storageItems > 0));
        }
 public ArchiveStudyStorageSelectCriteria(ArchiveStudyStorageSelectCriteria other)
 : base(other)
 {}
		/// <summary>
		/// Reprocess a specific study.
		/// </summary>
		/// <param name="partition">The ServerPartition the study is on.</param>
		/// <param name="location">The storage location of the study to process.</param>
		/// <param name="engine">The rules engine to use when processing the study.</param>
		/// <param name="postArchivalEngine">The rules engine used for studies that have been archived.</param>
		/// <param name="dataAccessEngine">The rules engine strictly used for setting data acess.</param>
		protected static void ProcessStudy(ServerPartition partition, StudyStorageLocation location, ServerRulesEngine engine, ServerRulesEngine postArchivalEngine, ServerRulesEngine dataAccessEngine)
		{
			if (!location.QueueStudyStateEnum.Equals(QueueStudyStateEnum.Idle) || !location.AcquireWriteLock())
			{
				Platform.Log(LogLevel.Error, "Unable to lock study {0}. The study is being processed. (Queue State: {1})", location.StudyInstanceUid,location.QueueStudyStateEnum.Description); 
			}
			else
			{
				try
				{
					DicomFile msg = LoadInstance(location);
					if (msg == null)
					{
						Platform.Log(LogLevel.Error, "Unable to load file for study {0}", location.StudyInstanceUid);
						return;
					}

					bool archiveQueueExists;
					bool archiveStudyStorageExists;
					bool filesystemDeleteExists;
					using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
					{
						// Check for existing archive queue entries
						var archiveQueueBroker = read.GetBroker<IArchiveQueueEntityBroker>();
						var archiveQueueCriteria = new ArchiveQueueSelectCriteria();
						archiveQueueCriteria.StudyStorageKey.EqualTo(location.Key);
						archiveQueueExists = archiveQueueBroker.Count(archiveQueueCriteria) > 0;


						var archiveStorageBroker = read.GetBroker<IArchiveStudyStorageEntityBroker>();
						var archiveStudyStorageCriteria = new ArchiveStudyStorageSelectCriteria();
						archiveStudyStorageCriteria.StudyStorageKey.EqualTo(location.Key);
						archiveStudyStorageExists = archiveStorageBroker.Count(archiveStudyStorageCriteria) > 0;

						var filesystemQueueBroker = read.GetBroker<IFilesystemQueueEntityBroker>();
						var filesystemQueueCriteria = new FilesystemQueueSelectCriteria();
						filesystemQueueCriteria.StudyStorageKey.EqualTo(location.Key);
						filesystemQueueCriteria.FilesystemQueueTypeEnum.EqualTo(FilesystemQueueTypeEnum.DeleteStudy);
						filesystemDeleteExists = filesystemQueueBroker.Count(filesystemQueueCriteria) > 0;
					}

					using (var commandProcessor = new ServerCommandProcessor("Study Rule Processor"))
					{
						var context = new ServerActionContext(msg, location.FilesystemKey, partition, location.Key, commandProcessor);
					
						// Check if the Study has been archived 
						if (archiveStudyStorageExists && !archiveQueueExists && !filesystemDeleteExists)
						{
							// Add a command to delete the current filesystemQueue entries, so that they can 
							// be reinserted by the rules engine.
							context.CommandProcessor.AddCommand(new DeleteFilesystemQueueCommand(location.Key, ServerRuleApplyTimeEnum.StudyArchived));

							// How to deal with exiting FilesystemQueue entries is problematic here.  If the study
							// has been migrated off tier 1, we probably don't want to modify the tier migration 
							// entries.  Compression entries may have been entered when the Study was initially 
							// processed, we don't want to delete them, because they might still be valid.  
							// We just re-run the rules engine at this point, and delete only the StudyPurge entries,
							// since those we know at least would only be applied for archived studies.
							var studyRulesEngine = new StudyRulesEngine(postArchivalEngine, location, location.ServerPartition, location.LoadStudyXml());
							studyRulesEngine.Apply(ServerRuleApplyTimeEnum.StudyArchived, commandProcessor);

							// Post Archive doesn't allow data access rules.  Force Data Access rules to be reapplied
							// to these studies also.
							dataAccessEngine.Execute(context);
						}
						else
						{
							// Add a command to delete the current filesystemQueue entries, so that they can 
							// be reinserted by the rules engine.
							context.CommandProcessor.AddCommand(new DeleteFilesystemQueueCommand(location.Key,ServerRuleApplyTimeEnum.StudyProcessed));

							// Execute the rules engine, insert commands to update the database into the command processor.
							// Due to ticket #11673, we create a new rules engine instance for each study, since the Study QC rules
							// don't work right now with a single rules engine.
							//TODO CR (Jan 2014) - Check if we can go back to caching the rules engine to reduce database hits on the rules
							var studyRulesEngine = new StudyRulesEngine(location, location.ServerPartition, location.LoadStudyXml());
							studyRulesEngine.Apply(ServerRuleApplyTimeEnum.StudyProcessed, commandProcessor);
						}

						// Do the actual database updates.
						if (false == context.CommandProcessor.Execute())
						{
							Platform.Log(LogLevel.Error, "Unexpected failure processing Study level rules for study {0}", location.StudyInstanceUid);
						}

						// Log the FilesystemQueue related entries
						location.LogFilesystemQueue();
					}
				}
				finally
				{
					location.ReleaseWriteLock();
				}
			}
		}
예제 #6
0
		/// <summary>
		/// Reset any failed restore requests that may have been left In Progress when the service last shut down.
		/// </summary>
		public void ResetFailedRestoreQueueItems()
		{
			using (IUpdateContext updateContext = PersistentStore.OpenUpdateContext(UpdateContextSyncMode.Flush))
			{
				IRestoreQueueEntityBroker broker = updateContext.GetBroker<IRestoreQueueEntityBroker>();

				ArchiveStudyStorageSelectCriteria selectStudyStorage = new ArchiveStudyStorageSelectCriteria();
				selectStudyStorage.PartitionArchiveKey.EqualTo(_partitionArchive.Key);

				RestoreQueueSelectCriteria criteria = new RestoreQueueSelectCriteria();
				criteria.ProcessorId.EqualTo(ServerPlatform.ProcessorId);
				criteria.RestoreQueueStatusEnum.EqualTo(RestoreQueueStatusEnum.InProgress);
				criteria.ArchiveStudyStorageRelatedEntityCondition.Exists(selectStudyStorage);

				IList<RestoreQueue> failedList = broker.Find(criteria);
				foreach (RestoreQueue failedItem in failedList)
				{
					UpdateRestoreQueue(updateContext, failedItem, RestoreQueueStatusEnum.Pending, Platform.Time.AddMinutes(2));

					Platform.Log(LogLevel.Warn,
								 "Reseting RestoreQueue entry {0} to Pending that was In Progress at startup for PartitionArchive '{1}' on ",
								 failedItem.Key, _partitionArchive.Description);
				}

				if (failedList.Count > 0)
					updateContext.Commit();
				else
					Platform.Log(LogLevel.Info, "No RestoreQueue entries to reset on startup for archive {0}", _partitionArchive.Description);
			}
		}
 public ArchiveStudyStorageSelectCriteria(ArchiveStudyStorageSelectCriteria other)
     : base(other)
 {
 }