예제 #1
0
		public ExternalPractitionerDetail CreateExternalPractitionerDetail(ExternalPractitioner prac, IPersistenceContext context)
		{
			var assembler = new PersonNameAssembler();

			var sortedContactPoints = CollectionUtils.Sort(prac.ContactPoints, (x, y) =>
				{
					if (ReferenceEquals(x, y)) return 0;
					if (x.IsDefaultContactPoint) return -1;
					if (y.IsDefaultContactPoint) return 1;
					return string.Compare(x.Name, y.Name);
				});

			var contactPointDetails = CollectionUtils.Map(
				sortedContactPoints,
				(ExternalPractitionerContactPoint cp) => CreateExternalPractitionerContactPointDetail(cp, context));

			var detail = new ExternalPractitionerDetail(
				prac.GetRef(),
				assembler.CreatePersonNameDetail(prac.Name),
				prac.LicenseNumber,
				prac.BillingNumber,
				prac.IsVerified,
				prac.LastVerifiedTime,
				prac.LastEditedTime,
				contactPointDetails,
				ExtendedPropertyUtils.Copy(prac.ExtendedProperties),
				CreateExternalPractitionerSummary(prac.GetUltimateMergeDestination(), context),
				prac.IsMerged,
				prac.Deactivated);

			return detail;
		}
예제 #2
0
		public void UpdateExternalPractitioner(ExternalPractitionerDetail detail, ExternalPractitioner prac, IPersistenceContext context)
		{
			// validate that only one contact point is specified as default
			var defaultPoints = CollectionUtils.Select(detail.ContactPoints, cp => cp.IsDefaultContactPoint);
			if(defaultPoints.Count > 1)
				throw new RequestValidationException(SR.ExceptionOneDefaultContactPoint);

			var assembler = new PersonNameAssembler();
			assembler.UpdatePersonName(detail.Name, prac.Name);

			prac.LicenseNumber = detail.LicenseNumber;
			prac.BillingNumber = detail.BillingNumber;
			prac.MarkDeactivated(detail.Deactivated);

			// update contact points collection
			var syncHelper = new CollectionSynchronizeHelper<ExternalPractitionerContactPoint, ExternalPractitionerContactPointDetail>(
					delegate (ExternalPractitionerContactPoint cp, ExternalPractitionerContactPointDetail cpDetail)
					{
						// ignore version in this comparison - deal with this issue in the update delegate
						return cp.GetRef().Equals(cpDetail.ContactPointRef, true);
					},
					delegate (ExternalPractitionerContactPointDetail cpDetail, ICollection<ExternalPractitionerContactPoint> cps)
					{
						// create a new contact point
						var cp = new ExternalPractitionerContactPoint(prac);
						UpdateExternalPractitionerContactPoint(cpDetail, cp, context);
						cps.Add(cp);
					},
					(cp, cpDetail, cps) => UpdateExternalPractitionerContactPoint(cpDetail, cp, context),
					(cp, cps) => cps.Remove(cp));

			syncHelper.Synchronize(prac.ContactPoints, detail.ContactPoints);

			ExtendedPropertyUtils.Update(prac.ExtendedProperties, detail.ExtendedProperties);
		}
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="practitioner"></param>
        public ExternalPractitionerContactPoint(ExternalPractitioner practitioner)
        {
            _practitioner = practitioner;
            _practitioner.ContactPoints.Add(this);

            _telephoneNumbers = new List <TelephoneNumber>();
            _addresses        = new List <Address>();
            _emailAddresses   = new List <EmailAddress>();
        }
예제 #4
0
		public ExternalPractitionerSummary CreateExternalPractitionerSummary(ExternalPractitioner prac, IPersistenceContext context)
		{
			var summary = new ExternalPractitionerSummary(
				prac.GetRef(),
				new PersonNameAssembler().CreatePersonNameDetail(prac.Name),
				prac.LicenseNumber,
				prac.BillingNumber,
				prac.IsVerified,
				prac.LastVerifiedTime,
				prac.LastEditedTime,
				prac.IsMerged,
				prac.Deactivated);

			return summary;
		}
        /// <summary>
        /// Creates a copy of this contact point, assigning it to the specified owner.
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        public virtual ExternalPractitionerContactPoint CreateCopy(ExternalPractitioner owner)
        {
            var copy = new ExternalPractitionerContactPoint(
                owner,
                _name,
                _description,
                _preferredResultCommunicationMode,
                _informationAuthority,
                _isDefaultContactPoint,
                CollectionUtils.Map(_telephoneNumbers, (TelephoneNumber tn) => (TelephoneNumber)tn.Clone()),
                CollectionUtils.Map(_addresses, (Address a) => (Address)a.Clone()),
                CollectionUtils.Map(_emailAddresses, (EmailAddress e) => (EmailAddress)e.Clone()),
                null);

            copy.MarkDeactivated(_deactivated);

            owner.ContactPoints.Add(copy);
            return(copy);
        }
 /// <summary>
 /// Constructor that does not specify an explicit list of procedures.
 /// </summary>
 /// <param name="enteredTime"></param>
 /// <param name="enteredBy"></param>
 /// <param name="enteredComment"></param>
 /// <param name="accessionNumber"></param>
 /// <param name="patient"></param>
 /// <param name="visit"></param>
 /// <param name="diagnosticService"></param>
 /// <param name="reasonForStudy"></param>
 /// <param name="priority"></param>
 /// <param name="orderingFacility"></param>
 /// <param name="performingFacility"></param>
 /// <param name="schedulingRequestTime"></param>
 /// <param name="orderingPractitioner"></param>
 /// <param name="resultRecipients"></param>
 public OrderCreationArgs(DateTime enteredTime, Staff enteredBy, string enteredComment, string accessionNumber,
                          Patient patient, Visit visit, DiagnosticService diagnosticService, string reasonForStudy, OrderPriority priority,
                          Facility orderingFacility, Facility performingFacility, DateTime?schedulingRequestTime, ExternalPractitioner orderingPractitioner,
                          IList <ResultRecipient> resultRecipients)
 {
     EnteredTime           = enteredTime;
     EnteredBy             = enteredBy;
     EnteredComment        = enteredComment;
     AccessionNumber       = accessionNumber;
     Patient               = patient;
     Visit                 = visit;
     DiagnosticService     = diagnosticService;
     ReasonForStudy        = reasonForStudy;
     Priority              = priority;
     OrderingFacility      = orderingFacility;
     PerformingFacility    = performingFacility;
     SchedulingRequestTime = schedulingRequestTime;
     OrderingPractitioner  = orderingPractitioner;
     ResultRecipients      = resultRecipients;
 }
예제 #7
0
		/// <summary>
		/// Constructor that does not specify an explicit list of procedures.
		/// </summary>
		/// <param name="enteredTime"></param>
		/// <param name="enteredBy"></param>
		/// <param name="enteredComment"></param>
		/// <param name="accessionNumber"></param>
		/// <param name="patient"></param>
		/// <param name="visit"></param>
		/// <param name="diagnosticService"></param>
		/// <param name="reasonForStudy"></param>
		/// <param name="priority"></param>
		/// <param name="orderingFacility"></param>
		/// <param name="performingFacility"></param>
		/// <param name="schedulingRequestTime"></param>
		/// <param name="orderingPractitioner"></param>
		/// <param name="resultRecipients"></param>
		public OrderCreationArgs(DateTime enteredTime, Staff enteredBy, string enteredComment, string accessionNumber,
			Patient patient, Visit visit, DiagnosticService diagnosticService, string reasonForStudy, OrderPriority priority,
			Facility orderingFacility, Facility performingFacility, DateTime? schedulingRequestTime, ExternalPractitioner orderingPractitioner,
			IList<ResultRecipient> resultRecipients)
		{
			EnteredTime = enteredTime;
			EnteredBy = enteredBy;
			EnteredComment = enteredComment;
			AccessionNumber = accessionNumber;
			Patient = patient;
			Visit = visit;
			DiagnosticService = diagnosticService;
			ReasonForStudy = reasonForStudy;
			Priority = priority;
			OrderingFacility = orderingFacility;
			PerformingFacility = performingFacility;
			SchedulingRequestTime = schedulingRequestTime;
			OrderingPractitioner = orderingPractitioner;
			ResultRecipients = resultRecipients;
		}
예제 #8
0
		/// <summary>
		/// Creates a new practitioner that is the result of merging the two specified practitioners.
		/// </summary>
		/// <param name="right"></param>
		/// <param name="left"></param>
		/// <param name="name"></param>
		/// <param name="licenseNumber"></param>
		/// <param name="billingNumber"></param>
		/// <param name="extendedProperties"></param>
		/// <param name="defaultContactPoint"></param>
		/// <param name="deactivatedContactPoints"></param>
		/// <param name="contactPointReplacements"></param>
		/// <returns></returns>
		public static ExternalPractitioner MergePractitioners(
			ExternalPractitioner right,
			ExternalPractitioner left,
			PersonName name,
			string licenseNumber,
			string billingNumber,
			IDictionary<string, string> extendedProperties,
			ExternalPractitionerContactPoint defaultContactPoint,
			ICollection<ExternalPractitionerContactPoint> deactivatedContactPoints,
			IDictionary<ExternalPractitionerContactPoint, ExternalPractitionerContactPoint> contactPointReplacements)
		{
			// sanity check
			if (Equals(right, left))
				throw new WorkflowException("Cannot merge a practitioner with itself.");
			if (right.Deactivated || left.Deactivated)
				throw new WorkflowException("Cannot merge a practitioner that is de-activated.");
			if (right.IsMerged || left.IsMerged)
				throw new WorkflowException("Cannot merge a practitioner that has already been merged.");
			if (defaultContactPoint != null && defaultContactPoint.IsMerged)
				throw new WorkflowException("Cannot assigned a merged contact point as default");

			// update properties on result record
			var result = new ExternalPractitioner { Name = name, LicenseNumber = licenseNumber, BillingNumber = billingNumber };

			ExtendedPropertyUtils.Update(result.ExtendedProperties, extendedProperties);

			// construct the set of retained contact points
			var retainedContactPoints = new HashedSet<ExternalPractitionerContactPoint>();
			retainedContactPoints.AddAll(contactPointReplacements.Values);

			// some of the replacement contact points are merged.  This should not be allowed.
			if (CollectionUtils.Contains(contactPointReplacements.Values, cp => cp.IsMerged))
				throw new WorkflowException("Cannot replace a contact point with another that has already been merged.");

			// add any existing contact point that was not in the replacement list (because it is implicitly being retained)
			foreach (var contactPoint in CollectionUtils.Concat(right.ContactPoints, left.ContactPoints))
			{
				// No need to retain a merged contact point.  Because its replacement would already be retained.
				if (!contactPointReplacements.ContainsKey(contactPoint) && !contactPoint.IsMerged)
					retainedContactPoints.Add(contactPoint);
			}

			// for all retained contact points, create a copy attached to the result practitioner,
			// and mark the original as having been merged into the copy
			foreach (var original in retainedContactPoints)
			{
				var copy = original.CreateCopy(result);
				result.ContactPoints.Add(copy);

				copy.IsDefaultContactPoint = original.Equals(defaultContactPoint);
				copy.MarkDeactivated(original.Deactivated || deactivatedContactPoints.Contains(original));
				original.SetMergedInto(copy);
			}

			// for all replaced contact points, mark the original as being merged into the 
			// copy of the replacement
			foreach (var kvp in contactPointReplacements)
			{
				kvp.Key.SetMergedInto(kvp.Value.MergedInto);
			}

			// mark both left and right as edited and merged
			foreach (var practitioner in new[] { right, left })
	{
				practitioner.MarkEdited();
				practitioner.SetMergedInto(result);
			}

			// mark the result as being edited
			result.MarkEdited();
			return result;
		}
예제 #9
0
		/// <summary>
		/// Marks this practitioner as being merged into the specified other.
		/// </summary>
		/// <param name="other"></param>
		protected internal virtual void SetMergedInto(ExternalPractitioner other)
		{
			_mergedInto = other;
			_deactivated = true;
		}
        /// <summary>
        /// Creates a new practitioner that is the result of merging the two specified practitioners.
        /// </summary>
        /// <param name="right"></param>
        /// <param name="left"></param>
        /// <param name="name"></param>
        /// <param name="licenseNumber"></param>
        /// <param name="billingNumber"></param>
        /// <param name="extendedProperties"></param>
        /// <param name="defaultContactPoint"></param>
        /// <param name="deactivatedContactPoints"></param>
        /// <param name="contactPointReplacements"></param>
        /// <returns></returns>
        public static ExternalPractitioner MergePractitioners(
            ExternalPractitioner right,
            ExternalPractitioner left,
            PersonName name,
            string licenseNumber,
            string billingNumber,
            IDictionary <string, string> extendedProperties,
            ExternalPractitionerContactPoint defaultContactPoint,
            ICollection <ExternalPractitionerContactPoint> deactivatedContactPoints,
            IDictionary <ExternalPractitionerContactPoint, ExternalPractitionerContactPoint> contactPointReplacements)
        {
            // sanity check
            if (Equals(right, left))
            {
                throw new WorkflowException("Cannot merge a practitioner with itself.");
            }
            if (right.Deactivated || left.Deactivated)
            {
                throw new WorkflowException("Cannot merge a practitioner that is de-activated.");
            }
            if (right.IsMerged || left.IsMerged)
            {
                throw new WorkflowException("Cannot merge a practitioner that has already been merged.");
            }
            if (defaultContactPoint != null && defaultContactPoint.IsMerged)
            {
                throw new WorkflowException("Cannot assigned a merged contact point as default");
            }

            // update properties on result record
            var result = new ExternalPractitioner {
                Name = name, LicenseNumber = licenseNumber, BillingNumber = billingNumber
            };

            ExtendedPropertyUtils.Update(result.ExtendedProperties, extendedProperties);

            // construct the set of retained contact points
            var retainedContactPoints = new HashedSet <ExternalPractitionerContactPoint>();

            retainedContactPoints.AddAll(contactPointReplacements.Values);

            // some of the replacement contact points are merged.  This should not be allowed.
            if (CollectionUtils.Contains(contactPointReplacements.Values, cp => cp.IsMerged))
            {
                throw new WorkflowException("Cannot replace a contact point with another that has already been merged.");
            }

            // add any existing contact point that was not in the replacement list (because it is implicitly being retained)
            foreach (var contactPoint in CollectionUtils.Concat(right.ContactPoints, left.ContactPoints))
            {
                // No need to retain a merged contact point.  Because its replacement would already be retained.
                if (!contactPointReplacements.ContainsKey(contactPoint) && !contactPoint.IsMerged)
                {
                    retainedContactPoints.Add(contactPoint);
                }
            }

            // for all retained contact points, create a copy attached to the result practitioner,
            // and mark the original as having been merged into the copy
            foreach (var original in retainedContactPoints)
            {
                var copy = original.CreateCopy(result);
                result.ContactPoints.Add(copy);

                copy.IsDefaultContactPoint = original.Equals(defaultContactPoint);
                copy.MarkDeactivated(original.Deactivated || deactivatedContactPoints.Contains(original));
                original.SetMergedInto(copy);
            }

            // for all replaced contact points, mark the original as being merged into the
            // copy of the replacement
            foreach (var kvp in contactPointReplacements)
            {
                kvp.Key.SetMergedInto(kvp.Value.MergedInto);
            }

            // mark both left and right as edited and merged
            foreach (var practitioner in new[] { right, left })
            {
                practitioner.MarkEdited();
                practitioner.SetMergedInto(result);
            }

            // mark the result as being edited
            result.MarkEdited();
            return(result);
        }
 /// <summary>
 /// Marks this practitioner as being merged into the specified other.
 /// </summary>
 /// <param name="other"></param>
 protected internal virtual void SetMergedInto(ExternalPractitioner other)
 {
     _mergedInto  = other;
     _deactivated = true;
 }