Ejemplo n.º 1
0
        public MergeDuplicateContactPointResponse MergeDuplicateContactPoint(MergeDuplicateContactPointRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.RetainedContactPointRef, "RetainedContactPointRef");
            Platform.CheckMemberIsSet(request.ReplacedContactPointRef, "ReplacedContactPointRef");

            var dest = PersistenceContext.Load <ExternalPractitionerContactPoint>(request.RetainedContactPointRef, EntityLoadFlags.Proxy);
            var src  = PersistenceContext.Load <ExternalPractitionerContactPoint>(request.ReplacedContactPointRef, EntityLoadFlags.Proxy);

            // if we are only doing a cost estimate, exit here without modifying any data
            if (request.EstimateCostOnly)
            {
                // compute cost estimate.  Need to include affected records of both src and dest, because both will be merged and deactivated.
                var cost = EstimateAffectedRecords(dest, src);
                return(new MergeDuplicateContactPointResponse(cost));
            }

            // combine all phone numbers and addresses, expiring those from the src object
            var allPhoneNumbers = CollectionUtils.Concat(
                CloneAndExpire(dest.TelephoneNumbers, tn => tn.ValidRange, false),
                CloneAndExpire(src.TelephoneNumbers, tn => tn.ValidRange, true));
            var allAddresses = CollectionUtils.Concat(
                CloneAndExpire(dest.Addresses, tn => tn.ValidRange, false),
                CloneAndExpire(src.Addresses, tn => tn.ValidRange, true));
            var allEmailAddresses = CollectionUtils.Concat(
                CloneAndExpire(dest.EmailAddresses, tn => tn.ValidRange, false),
                CloneAndExpire(src.EmailAddresses, tn => tn.ValidRange, true));

            // merge contact points
            var result = ExternalPractitionerContactPoint.MergeContactPoints(
                dest,
                src,
                dest.Name,
                dest.Description,
                dest.PreferredResultCommunicationMode,
                dest.InformationAuthority,
                allPhoneNumbers,
                allAddresses,
                allEmailAddresses);

            PersistenceContext.Lock(result, DirtyState.New);

            // if user has verify permission, verify the practitioner
            if (Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.ExternalPractitionerVerification))
            {
                result.Practitioner.MarkVerified();
            }

            // queue work items to migrate orders
            foreach (var contactPoint in new[] { src, dest })
            {
                var queueItem = MergeWorkQueueItem.Create(contactPoint.GetRef());
                PersistenceContext.Lock(queueItem, DirtyState.New);
            }

            PersistenceContext.SynchState();

            var assembler = new ExternalPractitionerAssembler();

            return(new MergeDuplicateContactPointResponse(assembler.CreateExternalPractitionerContactPointSummary(result)));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Performs a simple merge of two contact points.
 /// </summary>
 /// <remarks>
 /// Destination is the primary contact point.  The result will have all info inherit from destination.
 /// The Merge operation should clone/copy all the value collections.
 /// </remarks>
 public static ExternalPractitionerContactPoint SimpleMerge(ExternalPractitionerContactPoint src, ExternalPractitionerContactPoint dest)
 {
     return(ExternalPractitionerContactPoint.MergeContactPoints(src, dest,
                                                                dest.Name, dest.Description, dest.PreferredResultCommunicationMode, dest.InformationAuthority,
                                                                null, null, null));
 }