Example #1
0
        /// <summary>
        /// Check to see if merge is possible.
        /// </summary>
        /// <param name="mergeInfo"></param>
        /// <param name="failureReason"></param>
        /// <returns>True if the merge operation is possible, false otherwise.</returns>
        public virtual bool CanMerge(OrderMergeInfo mergeInfo, out string failureReason)
        {
            var destinationOrder = mergeInfo.MergeDestinationOrder;

            failureReason = null;
            if (this.AccessionNumber == destinationOrder.AccessionNumber)
            {
                failureReason = SR.MessageOrderCannotMergeSameAccessionNumber;
            }
            else if (this.Status != OrderStatus.SC || destinationOrder.Status != OrderStatus.SC)
            {
                failureReason = SR.MessageOrderCannotMergeOrderAlreadyStarted;
            }
            else if (!Equals(this.Patient, destinationOrder.Patient))
            {
                failureReason = SR.MessageOrderCannotMergeDifferentPatientOrders;
            }
            else if (!Equals(this.OrderingFacility.InformationAuthority, destinationOrder.OrderingFacility.InformationAuthority))
            {
                failureReason = SR.MessageOrderCannotMergeDifferentOrderingFacilityOrders;
            }
            else if (CollectionUtils.Contains(this.Procedures, p => p.DowntimeRecoveryMode) ||
                     CollectionUtils.Contains(destinationOrder.Procedures, p => p.DowntimeRecoveryMode))
            {
                failureReason = SR.MessageOrderCannotMergeDowntimeOrders;
            }

            return(string.IsNullOrEmpty(failureReason));
        }
Example #2
0
        /// <summary>
        /// Check to see if merge is possible.
        /// </summary>
        /// <param name="mergeInfo"></param>
        /// <param name="failureReason"></param>
        /// <returns>True if the merge operation is possible, false otherwise.</returns>
        public virtual bool CanMerge(OrderMergeInfo mergeInfo, out string failureReason)
        {
            var destinationOrder = mergeInfo.MergeDestinationOrder;

            failureReason = null;
            if (this.AccessionNumber == destinationOrder.AccessionNumber)
            {
                failureReason = "Orders with the same accession number cannot be merged.";
            }
            else if (this.Status != OrderStatus.SC || destinationOrder.Status != OrderStatus.SC)
            {
                failureReason = "Orders that have already been started cannot be merged.";
            }
            else if (this.Patient != destinationOrder.Patient)
            {
                failureReason = "Orders that belong to different patients cannot be merged.";
            }
            else if (this.OrderingFacility.InformationAuthority != destinationOrder.OrderingFacility.InformationAuthority)
            {
                failureReason = "Orders with different ordering facilities cannot be merged.";
            }
            else if (CollectionUtils.Contains(this.Procedures, p => p.DowntimeRecoveryMode) ||
                     CollectionUtils.Contains(destinationOrder.Procedures, p => p.DowntimeRecoveryMode))
            {
                failureReason = "Downtime orders cannot be merged.";
            }

            return(string.IsNullOrEmpty(failureReason));
        }
Example #3
0
        /// <summary>
        /// Merge the current order into the destination order specified in the mergeInfo.
        /// </summary>
        /// <param name="mergeInfo"></param>
        public virtual MergeResult Merge(OrderMergeInfo mergeInfo)
        {
            var destOrder = mergeInfo.MergeDestinationOrder;

            string failureReason;

            if (!CanMerge(mergeInfo, out failureReason))
            {
                throw new WorkflowException(failureReason);
            }

            _mergeInfo = mergeInfo;

            // copy all the result recipients to destination
            foreach (var rr in _resultRecipients)
            {
                var recipientAlreadyExist = CollectionUtils.Contains(
                    destOrder.ResultRecipients, recipients => recipients.PractitionerContactPoint.Equals(rr.PractitionerContactPoint));
                if (!recipientAlreadyExist)
                {
                    destOrder.ResultRecipients.Add((ResultRecipient)rr.Clone());
                }
            }

            // move all the attachments to destination, and replace with ghosts
            var ghostAttachments = CollectionUtils.Map(_attachments, (OrderAttachment a) => a.CreateGhostCopy());

            foreach (var a in _attachments)
            {
                destOrder.Attachments.Add(a);
            }
            _attachments.Clear();
            foreach (var ghost in ghostAttachments)
            {
                if (PersistenceScope.Current != null)
                {
                    PersistenceScope.CurrentContext.Lock(ghost.Document, DirtyState.New);
                }
                _attachments.Add(ghost);
            }

            // Move all the order notes to destination, and create ghosts of notes for this order
            var notes      = OrderNote.GetNotesForOrder(this);
            var ghostNotes = CollectionUtils.Map(notes, (OrderNote n) => n.CreateGhostCopy());

            foreach (var n in notes)
            {
                n.Order = destOrder;
            }
            foreach (var n in ghostNotes)
            {
                PersistenceScope.CurrentContext.Lock(n, DirtyState.New);
            }

            // Create ghost copies of the original procedures before it is added to the destinations
            // Theese ghost procedures are required for HL7 messages.
            var ghostProcedures = CollectionUtils.Map(_procedures, (Procedure p) => p.CreateGhostCopy());

            // Move all the procedures to the destination order.
            foreach (var p in _procedures)
            {
                destOrder.AddProcedure(p);
            }

            // update destination scheduling information
            destOrder.UpdateScheduling();

            // Add ghost procedures back to the source order.
            _procedures.AddAll(ghostProcedures);

            // Set source order to merged status
            SetStatus(OrderStatus.MG);

            return(new MergeResult {
                GhostProcedures = ghostProcedures
            });
        }
		private void MergeOrderHelper(Order destinationOrder, IEnumerable<Order> sourceOrders, OrderMergeInfo mergeInfo, bool validateOnly)
		{
			var sourceOrderAccessionNumbers = new List<string>();
			foreach (var sourceOrder in sourceOrders)
			{
				sourceOrderAccessionNumbers.Add(sourceOrder.AccessionNumber);

				string failureReason;
				if (!sourceOrder.CanMerge(mergeInfo, out failureReason))
					throw new RequestValidationException(failureReason);

				if (validateOnly)
					continue;

				// Merge the source order into the destination order.
				var result = sourceOrder.Merge(mergeInfo);

				// sync state so that ghost procedures get OIDs, prior to queuing ghost HL7 events
				PersistenceContext.SynchState();

				// create all necessary HL7 events
				foreach (var ghostProcedure in result.GhostProcedures)
				{
					LogicalHL7Event.ProcedureCancelled.EnqueueEvents(ghostProcedure);
					LogicalHL7Event.ProcedureCreated.EnqueueEvents(ghostProcedure.GhostOf);
				}
				LogicalHL7Event.OrderModified.EnqueueEvents(destinationOrder);
			}
		}
		public MergeOrderResponse MergeOrder(MergeOrderRequest request)
		{
			Platform.CheckForNullReference(request, "request");
			Platform.CheckMemberIsSet(request.SourceOrderRefs, "SourceOrderRefs");
			Platform.CheckTrue(request.SourceOrderRefs.Count > 0, "SourceOrderRefs.Count > 0");
			Platform.CheckMemberIsSet(request.DestinationOrderRef, "DestinationOrderRef");

			var response = new MergeOrderResponse();
			DryRunHelper(request.DryRun,
				delegate
				{
					var destinationOrder = this.PersistenceContext.Load<Order>(request.DestinationOrderRef);
					var sourceOrders = CollectionUtils.Map(request.SourceOrderRefs, (EntityRef r) => PersistenceContext.Load<Order>(r));
					var mergeInfo = new OrderMergeInfo(this.CurrentUserStaff, Platform.Time, destinationOrder);

					MergeOrderHelper(destinationOrder, sourceOrders, mergeInfo, request.ValidationOnly);

					if (request.DryRun)
					{
						var orderAssembler = new OrderAssembler();
						var orderDetail = orderAssembler.CreateOrderDetail(destinationOrder,
							OrderAssembler.CreateOrderDetailOptions.GetVerboseOptions(), PersistenceContext);
						response.DryRunMergedOrder = orderDetail;
					}
				});
			return response;
		}
Example #6
0
		/// <summary>
		/// Merge the current order into the destination order specified in the mergeInfo.
		/// </summary>
		/// <param name="mergeInfo"></param>
		public virtual MergeResult Merge(OrderMergeInfo mergeInfo)
		{
			var destOrder = mergeInfo.MergeDestinationOrder;

			string failureReason;
			if (!CanMerge(mergeInfo, out failureReason))
				throw new WorkflowException(failureReason);

			_mergeInfo = mergeInfo;

			// copy all the result recipients to destination
			foreach (var rr in _resultRecipients)
			{
				var rrr = rr;
				var recipientAlreadyExist = CollectionUtils.Contains(
					destOrder.ResultRecipients, recipients => recipients.PractitionerContactPoint.Equals(rrr.PractitionerContactPoint));
				if (!recipientAlreadyExist)
					destOrder.ResultRecipients.Add((ResultRecipient)rr.Clone());
			}

			// move all the attachments to destination, and replace with ghosts
			var ghostAttachments = CollectionUtils.Map(_attachments, (OrderAttachment a) => a.CreateGhostCopy());
			foreach (var a in _attachments)
			{
				destOrder.Attachments.Add(a);
			}
			_attachments.Clear();
			foreach (var ghost in ghostAttachments)
			{
				if(PersistenceScope.Current != null)
				{
					PersistenceScope.CurrentContext.Lock(ghost.Document, DirtyState.New);
				}
				_attachments.Add(ghost);
			}

			// Move all the order notes to destination, and create ghosts of notes for this order
			var notes = OrderNote.GetNotesForOrder(this);
			var ghostNotes = CollectionUtils.Map(notes, (OrderNote n) => n.CreateGhostCopy());
			foreach (var n in notes)
			{
				n.Order = destOrder;
			}
			foreach (var n in ghostNotes)
			{
				PersistenceScope.CurrentContext.Lock(n, DirtyState.New);
			}

			// Create ghost copies of the original procedures before it is added to the destinations
			// Theese ghost procedures are required for HL7 messages.
			var ghostProcedures = CollectionUtils.Map(_procedures, (Procedure p) => p.CreateGhostCopy());

			// Move all the procedures to the destination order.
			foreach (var p in _procedures)
			{
				destOrder.AddProcedure(p);
			}

			// update destination scheduling information
			destOrder.UpdateScheduling();

			// Add ghost procedures back to the source order.
			_procedures.AddAll(ghostProcedures);

			// Set source order to merged status
			SetStatus(OrderStatus.MG);

			return new MergeResult {GhostProcedures = ghostProcedures};
		}
Example #7
0
		/// <summary>
		/// Check to see if merge is possible.
		/// </summary>
		/// <param name="mergeInfo"></param>
		/// <param name="failureReason"></param>
		/// <returns>True if the merge operation is possible, false otherwise.</returns>
		public virtual bool CanMerge(OrderMergeInfo mergeInfo, out string failureReason)
		{
			var destinationOrder = mergeInfo.MergeDestinationOrder;

			failureReason = null;
			if (this.AccessionNumber == destinationOrder.AccessionNumber)
				failureReason = SR.MessageOrderCannotMergeSameAccessionNumber;
			else if (this.Status != OrderStatus.SC || destinationOrder.Status != OrderStatus.SC)
				failureReason = SR.MessageOrderCannotMergeOrderAlreadyStarted;
			else if (!Equals(this.Patient, destinationOrder.Patient))
				failureReason = SR.MessageOrderCannotMergeDifferentPatientOrders;
			else if (!Equals(this.OrderingFacility.InformationAuthority, destinationOrder.OrderingFacility.InformationAuthority))
				failureReason = SR.MessageOrderCannotMergeDifferentOrderingFacilityOrders;
			else if (CollectionUtils.Contains(this.Procedures, p => p.DowntimeRecoveryMode)
				|| CollectionUtils.Contains(destinationOrder.Procedures, p => p.DowntimeRecoveryMode))
				failureReason = SR.MessageOrderCannotMergeDowntimeOrders;

			return string.IsNullOrEmpty(failureReason);
		}
Example #8
0
File: Order.cs Project: nhannd/Xian
		/// <summary>
		/// Check to see if merge is possible.
		/// </summary>
		/// <param name="mergeInfo"></param>
		/// <param name="failureReason"></param>
		/// <returns>True if the merge operation is possible, false otherwise.</returns>
		public virtual bool CanMerge(OrderMergeInfo mergeInfo, out string failureReason)
		{
			var destinationOrder = mergeInfo.MergeDestinationOrder;

			failureReason = null;
			if (this.AccessionNumber == destinationOrder.AccessionNumber)
				failureReason = "Orders with the same accession number cannot be merged.";
			else if (this.Status != OrderStatus.SC || destinationOrder.Status != OrderStatus.SC)
				failureReason = "Orders that have already been started cannot be merged.";
			else if (this.Patient != destinationOrder.Patient)
				failureReason = "Orders that belong to different patients cannot be merged.";
			else if (this.OrderingFacility.InformationAuthority != destinationOrder.OrderingFacility.InformationAuthority)
				failureReason = "Orders with different ordering facilities cannot be merged.";
			else if (CollectionUtils.Contains(this.Procedures, p => p.DowntimeRecoveryMode)
				|| CollectionUtils.Contains(destinationOrder.Procedures, p => p.DowntimeRecoveryMode))
				failureReason = "Downtime orders cannot be merged.";

			return string.IsNullOrEmpty(failureReason);
		}