Exemplo n.º 1
0
        public void SavePrimaryCarePhysician(PrimaryCarePhysicianEditModel pcpEditModel, long customerId, long orgRoleUserId = 0)
        {
            var pcp = _primaryCarePhysicianRepository.Get(customerId);

            if (pcp == null && pcpEditModel == null)
            {
                return;
            }

            if (pcp != null && pcpEditModel == null)
            {
                _primaryCarePhysicianRepository.DecativatePhysician(customerId, orgRoleUserId > 0 ? orgRoleUserId : customerId);
            }
            else
            {
                if (pcp == null)
                {
                    pcp = new PrimaryCarePhysician
                    {
                        Name                 = pcpEditModel.FullName,
                        Primary              = !string.IsNullOrEmpty(pcpEditModel.Phone) ? PhoneNumber.Create(pcpEditModel.Phone, PhoneNumberType.Unknown) : pcpEditModel.PhoneNumber,
                        Email                = string.IsNullOrEmpty(pcpEditModel.Email) ? new Email(string.Empty, string.Empty) : new Email(pcpEditModel.Email),
                        CustomerId           = customerId,
                        DataRecorderMetaData = new DataRecorderMetaData(orgRoleUserId > 0 ? orgRoleUserId : customerId, DateTime.Now, null)
                    };
                }
                else
                {
                    pcp.Name    = pcpEditModel.FullName;
                    pcp.Primary = !string.IsNullOrEmpty(pcpEditModel.Phone) ? PhoneNumber.Create(pcpEditModel.Phone, PhoneNumberType.Unknown) : pcpEditModel.PhoneNumber;
                    pcp.Email   = string.IsNullOrEmpty(pcpEditModel.Email) ? new Email(string.Empty, string.Empty) : new Email(pcpEditModel.Email);
                    pcp.DataRecorderMetaData.DataRecorderModifier = new OrganizationRoleUser(orgRoleUserId > 0 ? orgRoleUserId : customerId);
                    pcp.DataRecorderMetaData.DateModified         = DateTime.Now;
                }

                if (pcpEditModel.Address != null && !pcpEditModel.Address.IsEmpty())
                {
                    long addressId = 0;
                    if (pcp.Address != null)
                    {
                        addressId = pcp.Address.Id;
                    }
                    pcp.Address    = Mapper.Map <AddressEditModel, Address>(pcpEditModel.Address);
                    pcp.Address.Id = addressId;
                }
                else
                {
                    pcp.Address = null;
                }

                if (pcpEditModel.MailingAddress != null && !pcpEditModel.MailingAddress.IsEmpty() && !IsAddressSame(pcpEditModel))
                {
                    long addressId = 0;
                    if (pcp.MailingAddress != null && pcp.Address != null && pcp.MailingAddress.Id != pcp.Address.Id)
                    {
                        addressId = pcp.MailingAddress.Id;
                    }

                    pcp.MailingAddress    = Mapper.Map <AddressEditModel, Address>(pcpEditModel.MailingAddress);
                    pcp.MailingAddress.Id = addressId;
                }
                else
                {
                    pcp.MailingAddress = null;
                }

                _primaryCarePhysicianRepository.Save(pcp);
            }
        }