Exemplo n.º 1
0
        /// <summary>
        /// Factory method to create a new order.
        /// </summary>
        public static Order NewOrder(OrderCreationArgs args, IProcedureNumberBroker procedureNumberBroker, IDicomUidBroker dicomUidBroker)
        {
            // validate required members are set
            Platform.CheckMemberIsSet(args.Patient, "Patient");
            Platform.CheckMemberIsSet(args.Visit, "Visit");
            Platform.CheckMemberIsSet(args.AccessionNumber, "AccessionNumber");
            Platform.CheckMemberIsSet(args.DiagnosticService, "DiagnosticService");
            Platform.CheckMemberIsSet(args.ReasonForStudy, "ReasonForStudy");
            Platform.CheckMemberIsSet(args.OrderingFacility, "OrderingFacility");
            Platform.CheckMemberIsSet(args.OrderingPractitioner, "OrderingPractitioner");


            // create the order
            var order = new Order
            {
                Patient               = args.Patient,
                Visit                 = args.Visit,
                AccessionNumber       = args.AccessionNumber,
                DiagnosticService     = args.DiagnosticService,
                ReasonForStudy        = args.ReasonForStudy,
                OrderingFacility      = args.OrderingFacility,
                OrderingPractitioner  = args.OrderingPractitioner,
                Priority              = args.Priority,
                SchedulingRequestTime = args.SchedulingRequestTime,
                EnteredTime           = args.EnteredTime,
                EnteredBy             = args.EnteredBy,
                EnteredComment        = args.EnteredComment
            };

            if (args.Procedures == null || args.Procedures.Count == 0)
            {
                // create procedures according to the diagnostic service plan
                args.Procedures = CollectionUtils.Map <ProcedureType, Procedure>(
                    args.DiagnosticService.ProcedureTypes,
                    type => new Procedure(type, procedureNumberBroker.GetNext(), dicomUidBroker.GetNewUid())
                {
                    PerformingFacility = args.PerformingFacility ?? args.OrderingFacility
                });
            }


            // associate all procedures with the order
            foreach (var procedure in args.Procedures)
            {
                order.AddProcedure(procedure);
            }

            // add recipients
            if (args.ResultRecipients != null)
            {
                foreach (var recipient in args.ResultRecipients)
                {
                    order.ResultRecipients.Add(recipient);
                }
            }

            var recipientsContainsOrderingPractitioner = CollectionUtils.Contains(
                order.ResultRecipients,
                r => r.PractitionerContactPoint.Practitioner.Equals(args.OrderingPractitioner));

            // if the result recipients collection does not contain the ordering practitioner, add it by force
            if (!recipientsContainsOrderingPractitioner)
            {
                var orderingPractitionerContactPoint =
                    // use the contact point associated to the ordering facility's information authority
                    CollectionUtils.SelectFirst(args.OrderingPractitioner.ContactPoints,
                                                cp => args.OrderingFacility.InformationAuthority.Equals(cp.InformationAuthority) && cp.Deactivated == false)
                    // or, use the default contact point
                    ?? CollectionUtils.SelectFirst(args.OrderingPractitioner.ContactPoints, cp => cp.IsDefaultContactPoint)
                    // or, if no default, use first available active CP (should never happen)
                    ?? CollectionUtils.SelectFirst(args.OrderingPractitioner.ContactPoints, cp => !cp.Deactivated)
                    // or, if no active CPs, use first in the collection (should never happen)
                    ?? CollectionUtils.FirstElement(args.OrderingPractitioner.ContactPoints);

                if (orderingPractitionerContactPoint != null)
                {
                    order.ResultRecipients.Add(new ResultRecipient(orderingPractitionerContactPoint, ResultCommunicationMode.ANY));
                }
            }

            return(order);
        }
Exemplo n.º 2
0
		/// <summary>
		/// Factory method to create a new order.
		/// </summary>
		public static Order NewOrder(OrderCreationArgs args, IProcedureNumberBroker procedureNumberBroker, IDicomUidBroker dicomUidBroker)
		{
			// validate required members are set
			Platform.CheckMemberIsSet(args.Patient, "Patient");
			Platform.CheckMemberIsSet(args.Visit, "Visit");
			Platform.CheckMemberIsSet(args.AccessionNumber, "AccessionNumber");
			Platform.CheckMemberIsSet(args.DiagnosticService, "DiagnosticService");
			Platform.CheckMemberIsSet(args.ReasonForStudy, "ReasonForStudy");
			Platform.CheckMemberIsSet(args.OrderingFacility, "OrderingFacility");
			Platform.CheckMemberIsSet(args.OrderingPractitioner, "OrderingPractitioner");


			// create the order
			var order = new Order
			{
				Patient = args.Patient,
				Visit = args.Visit,
				AccessionNumber = args.AccessionNumber,
				DiagnosticService = args.DiagnosticService,
				ReasonForStudy = args.ReasonForStudy,
				OrderingFacility = args.OrderingFacility,
				OrderingPractitioner = args.OrderingPractitioner,
				Priority = args.Priority,
				SchedulingRequestTime = args.SchedulingRequestTime,
				EnteredTime = args.EnteredTime,
				EnteredBy = args.EnteredBy,
				EnteredComment = args.EnteredComment
			};

			if (args.Procedures == null || args.Procedures.Count == 0)
			{
				// create procedures according to the diagnostic service plan
				args.Procedures = CollectionUtils.Map<ProcedureType, Procedure>(
					args.DiagnosticService.ProcedureTypes,
					type => new Procedure(type, procedureNumberBroker.GetNext(), dicomUidBroker.GetNewUid())
								{
									PerformingFacility = args.PerformingFacility ?? args.OrderingFacility
								});
			}


			// associate all procedures with the order
			foreach (var procedure in args.Procedures)
			{
				order.AddProcedure(procedure);
			}

			// add recipients
			if (args.ResultRecipients != null)
			{
				foreach (var recipient in args.ResultRecipients)
				{
					order.ResultRecipients.Add(recipient);
				}
			}

			var recipientsContainsOrderingPractitioner = CollectionUtils.Contains(
				order.ResultRecipients,
				r => r.PractitionerContactPoint.Practitioner.Equals(args.OrderingPractitioner));

			// if the result recipients collection does not contain the ordering practitioner, add it by force
			if (!recipientsContainsOrderingPractitioner)
			{
				var orderingPractitionerContactPoint =
					// use the contact point associated to the ordering facility's information authority
					CollectionUtils.SelectFirst(args.OrderingPractitioner.ContactPoints,
						cp => args.OrderingFacility.InformationAuthority.Equals(cp.InformationAuthority) && cp.Deactivated == false)
					// or, use the default contact point
					?? CollectionUtils.SelectFirst(args.OrderingPractitioner.ContactPoints, cp => cp.IsDefaultContactPoint)
					// or, if no default, use first available active CP (should never happen)
					?? CollectionUtils.SelectFirst(args.OrderingPractitioner.ContactPoints, cp => !cp.Deactivated)
					// or, if no active CPs, use first in the collection (should never happen)
					?? CollectionUtils.FirstElement(args.OrderingPractitioner.ContactPoints);

				if (orderingPractitionerContactPoint != null)
				{
					order.ResultRecipients.Add(new ResultRecipient(orderingPractitionerContactPoint, ResultCommunicationMode.ANY));
				}
			}

			return order;
		}