Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
		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);
			}
		}
Exemplo n.º 4
0
		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;
		}