/// <summary>
		/// Creates a new work item.
		/// </summary>
		/// <param name="p"></param>
		/// <param name="expirationTime"></param>
		/// <returns></returns>
		public static WorkQueueItem CreateWorkQueueItem(Procedure p, TimeSpan expirationTime)
		{
			WorkQueueItem item = new WorkQueueItem(WorkQueueItemType);
			item.ExpirationTime = Platform.Time.Add(expirationTime);
			item.ExtendedProperties.Add(ProcedureOIDKey, p.GetRef().Serialize());

			return item;
		}
Example #2
0
			public void EnqueueEvents(Order order)
			{
				var queueItem = new WorkQueueItem(WorkQueueItemType);
				queueItem.ExtendedProperties.Add("EventType", this.EventType);
				queueItem.ExtendedProperties.Add("OrderOID", order.OID.ToString());
				queueItem.ExtendedProperties.Add("AccessionNumber", order.AccessionNumber);
				
				EnqueueWorkItem(queueItem);
			}
		protected override bool ShouldReschedule(WorkQueueItem item, Exception error, out DateTime rescheduleTime)
		{
			if (error == null)
				return base.ShouldReschedule(item, null, out rescheduleTime);

			//todo: should we retry? things might end up being processed out of order
			rescheduleTime = Platform.Time + _failedItemRetryDelay;
			return true;
		}
Example #4
0
		protected override void ActOnItem(WorkQueueItem item)
		{
			var logicalEvent = new LogicalHL7EventArgs(item);
			Platform.Log(LogLevel.Info, String.Format("Procssing HL7LogicalEvent {0}", item.OID));

			foreach (ILogicalHL7EventListener listener in new LogicalHL7EventListenerExtensionPoint().CreateExtensions())
			{
				listener.OnEvent(logicalEvent);
			}
		}
Example #5
0
			public void EnqueueEvents(PatientProfile patientProfile)
			{
				var queueItem = new WorkQueueItem(WorkQueueItemType);
				queueItem.ExtendedProperties.Add("EventType", this.EventType);
				queueItem.ExtendedProperties.Add("PatientOID", patientProfile.Patient.OID.ToString());
				queueItem.ExtendedProperties.Add("PatientProfileOID", patientProfile.OID.ToString());
				queueItem.ExtendedProperties.Add("Mrn", patientProfile.Mrn.ToString());

				EnqueueWorkItem(queueItem);
			}
		protected override void ActOnItem(WorkQueueItem item)
		{
			var actionType = item.ExtendedProperties["ActionType"];
			var action = (IPublicationAction)new PublicationActionExtensionPoint().CreateExtension(new ClassNameExtensionFilter(actionType));
			var reportPartRef = new EntityRef(item.ExtendedProperties["ReportPartRef"]);
			var reportPart = PersistenceScope.CurrentContext.Load<ReportPart>(reportPartRef, EntityLoadFlags.None);

			Platform.Log(LogLevel.Info, String.Format("Processing Publication Action {0} for report part {1}", actionType, reportPart.OID));

			action.Execute(reportPart, PersistenceScope.CurrentContext);
		}
Example #7
0
		private static WorkQueueItem Create(
			string accessionNumber,
			EntityRef reportRef,
			EntityRef practitionerRef,
			EntityRef contactPointRef)
		{
			var workQueueItem = new WorkQueueItem("Mail/Fax Report");
			workQueueItem.ExtendedProperties.Add("AccessionNumber", accessionNumber);
			workQueueItem.ExtendedProperties.Add("ReportOID", reportRef.ToString(false, false));
			workQueueItem.ExtendedProperties.Add("ExternalPractitionerOID", practitionerRef.ToString(false, false));
			workQueueItem.ExtendedProperties.Add("ExternalPractitionerContactPointOID", contactPointRef.ToString(false, false));

			return workQueueItem;
		}
		protected override bool ShouldReschedule(WorkQueueItem item, Exception error, out DateTime rescheduleTime)
		{
			var actionType = item.ExtendedProperties["ActionType"];
			var action = (IPublicationAction)new PublicationActionExtensionPoint().CreateExtension(new ClassNameExtensionFilter(actionType));

			if (error == null)
				return base.ShouldReschedule(item, null, out rescheduleTime);

			if (action.RetryCount >= 0 && item.FailureCount > action.RetryCount)
				return base.ShouldReschedule(item, null, out rescheduleTime);

			//todo: should we retry? things might end up being processed out of order
			rescheduleTime = Platform.Time + _failedItemRetryDelay;
			return true;
		}
		protected override void OnItemSucceeded(WorkQueueItem item)
		{
			// this method is overridden because image availability work items are never considered complete until they expire

			Procedure procedure = ImageAvailabilityWorkQueue.GetProcedure(item, PersistenceScope.CurrentContext);
			DateTime nextPollTime = Platform.Time.Add(GetPollingInterval(procedure.ImageAvailability));
			if(nextPollTime < item.ExpirationTime)
			{
				item.Reschedule(nextPollTime);
			}
			else
			{
				base.OnItemSucceeded(item);
			}
		}
Example #10
0
		public WorkQueueItemSummary CreateWorkQueueItemSummary(WorkQueueItem workQueueItem, IPersistenceContext context)
		{
			WorkQueueItemSummary summary = new WorkQueueItemSummary();

			summary.WorkQueueItemRef = workQueueItem.GetRef();
			summary.CreationTime = workQueueItem.CreationTime;
			summary.ScheduledTime = workQueueItem.ScheduledTime;
			summary.ExpirationTime = workQueueItem.ExpirationTime;
			summary.User = workQueueItem.User;
			summary.Type = workQueueItem.Type;
			summary.Status = EnumUtils.GetEnumValueInfo(workQueueItem.Status, context);
			summary.ProcessedTime = workQueueItem.ProcessedTime;
			summary.FailureCount = workQueueItem.FailureCount;
			summary.FailureDescription = workQueueItem.FailureDescription;

			return summary;
		}
Example #11
0
		public WorkQueueItemDetail CreateWorkQueueItemDetail(WorkQueueItem workQueueItem, IPersistenceContext context)
		{
			WorkQueueItemDetail detail = new WorkQueueItemDetail();

			detail.WorkQueueItemRef = workQueueItem.GetRef();
			detail.CreationTime = workQueueItem.CreationTime;
			detail.ScheduledTime = workQueueItem.ScheduledTime;
			detail.ExpirationTime = workQueueItem.ExpirationTime;
			detail.User = workQueueItem.User;
			detail.Type = workQueueItem.Type;
			detail.Status = EnumUtils.GetEnumValueInfo(workQueueItem.Status, context);
			detail.ProcessedTime = workQueueItem.ProcessedTime;
			detail.FailureCount = workQueueItem.FailureCount;
			detail.FailureDescription = workQueueItem.FailureDescription;
			detail.ExtendedProperties = ExtendedPropertyUtils.Copy(workQueueItem.ExtendedProperties);

			return detail;
		}
Example #12
0
		/// <summary>
		/// Gets the procedure associated with the specified work item.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="context"></param>
		/// <returns></returns>
		public static Procedure GetProcedure(WorkQueueItem item, IPersistenceContext context)
		{
			EntityRef procedureRef = new EntityRef(item.ExtendedProperties[ProcedureOIDKey]);
			return context.Load<Procedure>(procedureRef, EntityLoadFlags.Proxy);
		}
		protected override bool ShouldReschedule(WorkQueueItem item, Exception error, out DateTime retryTime)
		{
			// retry unless expired
			retryTime = Platform.Time.AddSeconds(_settings.PollingIntervalForError);
			return (retryTime < item.ExpirationTime);
		}
		protected override void ActOnItem(WorkQueueItem item)
		{
			Procedure procedure = ImageAvailabilityWorkQueue.GetProcedure(item, PersistenceScope.CurrentContext);
			procedure.ImageAvailability = _imageAvailabilityStrategy.ComputeProcedureImageAvailability(procedure, PersistenceScope.CurrentContext);
		}
Example #15
0
		public static EntityRef GetTargetRef(WorkQueueItem item)
		{
			return new EntityRef(item.ExtendedProperties["Target"]);
		}
Example #16
0
		public static WorkQueueItem Create(EntityRef targetRef)
		{
			var workQueueItem = new WorkQueueItem(Tag);
			workQueueItem.ExtendedProperties.Add("Target", targetRef.Serialize());
			return workQueueItem;
		}
Example #17
0
			public void EnqueueEvents(Report report)
			{
				var orders = report.Procedures.Select(rp => rp.Order).Distinct();

				var workItems =  orders.Select(order =>
						{
							var queueItem = new WorkQueueItem(WorkQueueItemType);
							queueItem.ExtendedProperties.Add("EventType", this.EventType);
							queueItem.ExtendedProperties.Add("OrderOID", order.OID.ToString());
							queueItem.ExtendedProperties.Add("AccessionNumber", order.AccessionNumber);
							queueItem.ExtendedProperties.Add("ReportOID", report.OID.ToString());
							return queueItem;
						});

				EnqueueWorkItems(workItems);
			}
Example #18
0
		protected void EnqueueWorkItem(WorkQueueItem workItem)
		{
			if (!new LogicalHL7EventSettings().EnableEvents)
				return;
			PersistenceScope.CurrentContext.Lock(workItem, DirtyState.New);
		}