public void UpdateOrderFromRequisition(Order order, OrderRequisition requisition, Staff currentStaff, IPersistenceContext context)
		{
			// only certain properties of an order may be updated from a requisition
			// Patient cannot not be updated
			// DiagnosticService cannot be updated
			// OrderingFacility cannot be updated

			// do not update the individual procedures, as this is done separately - see UpdateProcedureFromRequisition

			// Some properties cannot be updated if the procedure is terminated
			if (!order.IsTerminated)
			{
				order.Visit = context.Load<Visit>(requisition.Visit.VisitRef, EntityLoadFlags.Proxy);

				order.SchedulingRequestTime = requisition.SchedulingRequestTime;
				order.OrderingPractitioner = context.Load<ExternalPractitioner>(
					requisition.OrderingPractitioner.PractitionerRef, EntityLoadFlags.Proxy);
				order.ReasonForStudy = requisition.ReasonForStudy;
				order.Priority = EnumUtils.GetEnumValue<OrderPriority>(requisition.Priority);

				// wipe out and reset the result recipients
				order.ResultRecipients.Clear();

				CollectionUtils.Map<ResultRecipientDetail, ResultRecipient>(
					requisition.ResultRecipients,
					s => new ResultRecipient(
							context.Load<ExternalPractitionerContactPoint>(s.ContactPoint.ContactPointRef, EntityLoadFlags.Proxy),
							EnumUtils.GetEnumValue<ResultCommunicationMode>(s.PreferredCommunicationMode))).ForEach(r => order.ResultRecipients.Add(r));
			}

			// synchronize Order.Attachments from order requisition
			var attachmentAssembler = new OrderAttachmentAssembler();
			attachmentAssembler.Synchronize(order.Attachments, requisition.Attachments, currentStaff, context);

			// synchronize Order.Notes from order requisition
			var noteAssembler = new OrderNoteAssembler();
			noteAssembler.SynchronizeOrderNotes(order, requisition.Notes, currentStaff, context);

			if (requisition.ExtendedProperties != null)
			{
				ExtendedPropertyUtils.Update(order.ExtendedProperties, requisition.ExtendedProperties);
			}
		}
		public OrderRequisition CreateOrderRequisition(Order order, IPersistenceContext context)
		{
			var patientProfileAssembler = new PatientProfileAssembler();
			var visitAssembler = new VisitAssembler();
			var pracAssembler = new ExternalPractitionerAssembler();
			var facilityAssembler = new FacilityAssembler();
			var dsAssembler = new DiagnosticServiceAssembler();
			var attachmentAssembler = new OrderAttachmentAssembler();
			var noteAssembler = new OrderNoteAssembler();
			var resultRecipientAssembler = new ResultRecipientAssembler();

			var requisition = new OrderRequisition
								{
									OrderRef = order.GetRef(),
									Patient =
										patientProfileAssembler.CreatePatientProfileSummary(
											CollectionUtils.FirstElement(order.Procedures).PatientProfile, context),
									Visit = visitAssembler.CreateVisitSummary(order.Visit, context),
									DiagnosticService = dsAssembler.CreateSummary(order.DiagnosticService),
									SchedulingRequestTime = order.SchedulingRequestTime,
									OrderingPractitioner =
										pracAssembler.CreateExternalPractitionerSummary(order.OrderingPractitioner, context),
									OrderingFacility = facilityAssembler.CreateFacilitySummary(order.OrderingFacility),
									ReasonForStudy = order.ReasonForStudy,
									Priority = EnumUtils.GetEnumValueInfo(order.Priority, context),
									ResultRecipients = CollectionUtils.Map<ResultRecipient, ResultRecipientDetail>(
										order.ResultRecipients,
										r => resultRecipientAssembler.CreateResultRecipientDetail(r, context)),
									Procedures = CollectionUtils.Map<Procedure, ProcedureRequisition>(
										order.Procedures,
										procedure => CreateProcedureRequisition(procedure, context)),
									Attachments = CollectionUtils.Map<OrderAttachment, AttachmentSummary>(
										order.Attachments,
										attachment => attachmentAssembler.CreateOrderAttachmentSummary(attachment, context)),
									Notes = CollectionUtils.Map<OrderNote, OrderNoteDetail>(
										OrderNote.GetNotesForOrder(order),
										note => noteAssembler.CreateOrderNoteDetail(note, context)),
									ExtendedProperties = ExtendedPropertyUtils.Copy(order.ExtendedProperties),
									CanModify = !order.IsTerminated
								};

			return requisition;
		}
			internal override EntityRef Submit(OrderRequisition requisition, OrderEditorComponent component)
			{
				ModifyOrderResponse response = null;
				requisition.OrderRef = component.OrderRef;
				Platform.GetService<IOrderEntryService>(service =>
				{
					response = service.ModifyOrder(new ModifyOrderRequest(requisition));
				});
				return response.Order.OrderRef;
			}
			internal override EntityRef Submit(OrderRequisition requisition, OrderEditorComponent component)
			{
				PlaceOrderResponse response = null;
				Platform.GetService<IOrderEntryService>(
					service => response = service.PlaceOrder(new PlaceOrderRequest(requisition))
				);

				return response.Order.OrderRef;
			}
			/// <summary>
			/// Submit the specified order requisition to the server.
			/// </summary>
			/// <param name="requisition"></param>
			/// <param name="component"></param>
			/// <returns></returns>
			internal abstract EntityRef Submit(OrderRequisition requisition, OrderEditorComponent component);
Beispiel #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="requisition"></param>
 public PlaceOrderRequest(OrderRequisition requisition)
 {
     this.Requisition = requisition;
 }
Beispiel #7
0
 public ReplaceOrderRequest(EntityRef orderRef, EnumValueInfo cancelReason, OrderRequisition newRequisition)
 {
     this.OrderRef = orderRef;
     this.CancelReason = cancelReason;
     this.Requisition = newRequisition;
 }
		public GetOrderRequisitionForEditResponse(OrderRequisition requisition)
		{
			this.Requisition = requisition;
		}
 public ModifyOrderRequest(OrderRequisition requisition)
 {
     this.Requisition = requisition;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="requisition"></param>
 public PlaceOrderRequest(OrderRequisition requisition)
 {
     this.Requisition = requisition;
 }
Beispiel #11
0
 public ModifyOrderRequest(OrderRequisition requisition)
 {
     this.Requisition = requisition;
 }
		/// <summary>
		/// Finds the visit specified in the requisition, or if no visit is specified, auto-generates a visit.
		/// </summary>
		/// <param name="requisition"></param>
		/// <param name="patient"></param>
		/// <param name="orderingFacility"></param>
		/// <returns></returns>
		private Visit FindOrCreateVisit(OrderRequisition requisition, Patient patient, Facility orderingFacility, string accessionNumber)
		{
			if (requisition.Visit != null && requisition.Visit.VisitRef != null)
			{
				return this.PersistenceContext.Load<Visit>(requisition.Visit.VisitRef, EntityLoadFlags.Proxy);
			}

			// if Visit Workflow is disabled, then we must auto-generate a "dummy" visit in order to keep the system happy
			// the user will never see this dummy visit
			if (!new WorkflowConfigurationReader().EnableVisitWorkflow)
			{
				var patientClasses = PersistenceContext.GetBroker<IEnumBroker>().Load<PatientClassEnum>(false);

				// create a visit using the minimum possible amount of information
				var visit = new Visit
								{
									Patient = patient,
									VisitNumber = new VisitNumber(accessionNumber, orderingFacility.InformationAuthority),
									Status = VisitStatus.AA,
									AdmitTime = Platform.Time,
									Facility = orderingFacility,
									PatientClass = CollectionUtils.FirstElement(patientClasses)
								};

				this.PersistenceContext.Lock(visit, DirtyState.New);
				return visit;
			}

			throw new RequestValidationException("A visit is required.");
		}
		/// <summary>
		/// Creates duplicates of any attached documents in the order that also appear in the
		/// requisition, and then replaces the references in the requisition to refer to the
		/// duplicates.
		/// </summary>
		/// <param name="order"></param>
		/// <param name="requisition"></param>
		private void DuplicateAttachmentsForOrderReplace(Order order, OrderRequisition requisition)
		{
			foreach (var attachment in order.Attachments)
			{
				var summary = CollectionUtils.SelectFirst(requisition.Attachments,
								  s => s.Document.DocumentRef.Equals(attachment.Document.GetRef(), true));

				if (summary != null)
				{
					var dup = attachment.Document.Duplicate(true);
					PersistenceContext.Lock(dup, DirtyState.New);
					summary.Document.DocumentRef = dup.GetRef();
				}
			}
		}
		private string GetAccessionNumberForOrder(OrderRequisition requisition)
		{
			// if this is a downtime requisition, validate the downtime A#, otherwise obtain a new A#
			var accessionBroker = this.PersistenceContext.GetBroker<IAccessionNumberBroker>();
			if (requisition.IsDowntimeOrder)
			{
				// validate that the downtime A# is less than then current sequence position
				var currentMaxAccession = accessionBroker.PeekNext();
				if (requisition.DowntimeAccessionNumber.CompareTo(currentMaxAccession) > -1)
					throw new RequestValidationException("Invalid downtime accession number.");

				return requisition.DowntimeAccessionNumber;
			}

			// get new A#
			return this.PersistenceContext.GetBroker<IAccessionNumberBroker>().GetNext();
		}
		private Order PlaceOrderHelper(OrderRequisition requisition)
		{
			// get appropriate A# for this order
			var accNum = GetAccessionNumberForOrder(requisition);

			var patient = this.PersistenceContext.Load<Patient>(requisition.Patient.PatientRef, EntityLoadFlags.Proxy);
			var orderingFacility = this.PersistenceContext.Load<Facility>(requisition.OrderingFacility.FacilityRef, EntityLoadFlags.Proxy);
			var visit = FindOrCreateVisit(requisition, patient, orderingFacility, accNum);
			var orderingPhysician = this.PersistenceContext.Load<ExternalPractitioner>(requisition.OrderingPractitioner.PractitionerRef, EntityLoadFlags.Proxy);
			var diagnosticService = this.PersistenceContext.Load<DiagnosticService>(requisition.DiagnosticService.DiagnosticServiceRef);
			var priority = EnumUtils.GetEnumValue<OrderPriority>(requisition.Priority);


			var resultRecipients = CollectionUtils.Map(
				requisition.ResultRecipients ?? new List<ResultRecipientDetail>(),
				(ResultRecipientDetail s) => new ResultRecipient(
												this.PersistenceContext.Load<ExternalPractitionerContactPoint>(s.ContactPoint.ContactPointRef, EntityLoadFlags.Proxy),
												EnumUtils.GetEnumValue<ResultCommunicationMode>(s.PreferredCommunicationMode)));

			// generate set of procedures
			// create a temp map from procedure back to its requisition, this will be needed later
			var orderAssembler = new OrderEntryAssembler();
			var mapProcToReq = new Dictionary<Procedure, ProcedureRequisition>();
			var procedureNumberBroker = PersistenceContext.GetBroker<IProcedureNumberBroker>();
			var dicomUidBroker = PersistenceContext.GetBroker<IDicomUidBroker>();
			var procedures = CollectionUtils.Map(
				requisition.Procedures ?? new List<ProcedureRequisition>(),
				delegate(ProcedureRequisition req)
				{
					var rpt = this.PersistenceContext.Load<ProcedureType>(req.ProcedureType.ProcedureTypeRef);
					var rp = new Procedure(rpt, procedureNumberBroker.GetNext(), dicomUidBroker.GetNewUid());
					mapProcToReq.Add(rp, req);

					// important to set this flag prior to creating the procedure steps, because it may affect
					// which procedure steps are created
					rp.DowntimeRecoveryMode = requisition.IsDowntimeOrder;
					return rp;
				});


			// generate a new order with the default set of procedures
			var order = Order.NewOrder(
				new OrderCreationArgs(
					Platform.Time,
					this.CurrentUserStaff,
					null,
					accNum,
					patient,
					visit,
					diagnosticService,
					requisition.ReasonForStudy,
					priority,
					orderingFacility,
					requisition.SchedulingRequestTime,
					orderingPhysician,
					resultRecipients,
					procedures),
				procedureNumberBroker,
				dicomUidBroker);

			// note: need to lock the new order now, prior to creating the procedure steps
			// otherwise may get exceptions saying the Procedure is a transient object
			this.PersistenceContext.Lock(order, DirtyState.New);

			// create procedure steps and update from requisition
			foreach (var procedure in order.Procedures)
			{
				procedure.CreateProcedureSteps();
				if(mapProcToReq.ContainsKey(procedure))
				{
					orderAssembler.UpdateProcedureFromRequisition(procedure, mapProcToReq[procedure], this.CurrentUserStaff, this.PersistenceContext);
				}
			}

			// add order notes
			if (requisition.Notes != null)
			{
				var noteAssembler = new OrderNoteAssembler();
				noteAssembler.SynchronizeOrderNotes(order, requisition.Notes, this.CurrentUserStaff, this.PersistenceContext);
			}

			// add attachments
			if(requisition.Attachments != null)
			{
				var attachmentAssembler = new OrderAttachmentAssembler();
				attachmentAssembler.Synchronize(order.Attachments, requisition.Attachments, this.CurrentUserStaff, this.PersistenceContext);
			}

			if (requisition.ExtendedProperties != null)
			{
				ExtendedPropertyUtils.Update(order.ExtendedProperties, requisition.ExtendedProperties);
			}

			return order;
		}
			internal override EntityRef Submit(OrderRequisition requisition, OrderEditorComponent component)
			{
				ReplaceOrderResponse response = null;
				Platform.GetService<IOrderEntryService>(
					service => response = service.ReplaceOrder(new ReplaceOrderRequest(this.OrderRef, component.SelectedCancelReason, requisition))
				);

				return response.Order.OrderRef;
			}
 public GetOrderRequisitionForEditResponse(OrderRequisition requisition)
 {
     this.Requisition = requisition;
 }
Beispiel #18
0
 public ReplaceOrderRequest(EntityRef orderRef, EnumValueInfo cancelReason, OrderRequisition newRequisition)
 {
     this.OrderRef     = orderRef;
     this.CancelReason = cancelReason;
     this.Requisition  = newRequisition;
 }