public EventCustomerPrimaryCarePhysician Save(EventCustomerPrimaryCarePhysician domain) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { DeleteEventCustomerPrimaryCarePhysician(domain.EventCustomerId); var entity = Mapper.Map <EventCustomerPrimaryCarePhysician, EventCustomerPrimaryCarePhysicianEntity>(domain); if (!adapter.SaveEntity(entity, true)) { throw new PersistenceFailureException(); } return(Mapper.Map <EventCustomerPrimaryCarePhysicianEntity, EventCustomerPrimaryCarePhysician>(entity)); } }
private bool SavePcpDetails() { if (rbtnYes.Checked) { try { var countryRepository = IoC.Resolve <ICountryRepository>(); var countryId = countryRepository.GetAll().First().Id; var primaryCarePhysicianRepository = IoC.Resolve <IPrimaryCarePhysicianRepository>(); PrimaryCarePhysician pcp = null; if (!chkPCPChange.Checked) { pcp = primaryCarePhysicianRepository.Get(CustomerId); } var currentOrganizationRole = IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole; var physicianMasterRepository = IoC.Resolve <IPhysicianMasterRepository>(); var newPcp = false; if (Convert.ToInt64(PhysicianMasterIdHiddenField.Value) > 0) { var physicianMaster = physicianMasterRepository.GetById(Convert.ToInt64(PhysicianMasterIdHiddenField.Value)); if (pcp == null) { pcp = new PrimaryCarePhysician { Name = new Name(physicianMaster.FirstName, physicianMaster.MiddleName, physicianMaster.LastName), Primary = physicianMaster.PracticePhone, Fax = physicianMaster.PracticeFax, PrefixText = physicianMaster.PrefixText, SuffixText = physicianMaster.SuffixText, CredentialText = physicianMaster.CredentialText, Npi = physicianMaster.Npi, PhysicianMasterId = physicianMaster.Id, CustomerId = CustomerId, DataRecorderMetaData = new DataRecorderMetaData(currentOrganizationRole.OrganizationRoleUserId, DateTime.Now, null), IsActive = true }; } else { pcp.Name = new Name(physicianMaster.FirstName, physicianMaster.MiddleName, physicianMaster.LastName); pcp.Primary = physicianMaster.PracticePhone; pcp.Fax = physicianMaster.PracticeFax; pcp.PrefixText = physicianMaster.PrefixText; pcp.SuffixText = physicianMaster.SuffixText; pcp.CredentialText = physicianMaster.CredentialText; pcp.Npi = physicianMaster.Npi; pcp.PhysicianMasterId = physicianMaster.Id; pcp.DataRecorderMetaData.DataRecorderModifier = new OrganizationRoleUser(currentOrganizationRole.OrganizationRoleUserId); pcp.DataRecorderMetaData.DateModified = DateTime.Now; pcp.IsActive = true; } pcp = UpdatePcpAddressesFromMaster(physicianMaster, pcp); } else { if (pcp == null) { newPcp = true; pcp = new PrimaryCarePhysician { Name = new Name(UCPCPInfo1.FirstName, UCPCPInfo1.MiddleName, UCPCPInfo1.LastName), Primary = string.IsNullOrEmpty(UCPCPInfo1.Phone) ? null : PhoneNumber.Create(UCPCPInfo1.Phone, PhoneNumberType.Home), Secondary = string.IsNullOrEmpty(UCPCPInfo1.AlternatePhone) ? null : PhoneNumber.Create(UCPCPInfo1.AlternatePhone, PhoneNumberType.Office), Fax = string.IsNullOrEmpty(UCPCPInfo1.Fax) ? null : PhoneNumber.Create(UCPCPInfo1.Fax, PhoneNumberType.Unknown), Email = string.IsNullOrEmpty(UCPCPInfo1.Email) ? new Email(string.Empty, string.Empty) : new Email(UCPCPInfo1.Email), SecondaryEmail = string.IsNullOrEmpty(UCPCPInfo1.AlternateEmail) ? new Email(string.Empty, string.Empty) : new Email(UCPCPInfo1.AlternateEmail), Website = UCPCPInfo1.WebsiteUrl, CustomerId = CustomerId, DataRecorderMetaData = new DataRecorderMetaData(currentOrganizationRole.OrganizationRoleUserId, DateTime.Now, null), IsActive = true, }; } else { pcp.Name = new Name(UCPCPInfo1.FirstName, UCPCPInfo1.MiddleName, UCPCPInfo1.LastName); pcp.Primary = string.IsNullOrEmpty(UCPCPInfo1.Phone) ? null : PhoneNumber.Create(UCPCPInfo1.Phone, PhoneNumberType.Home); pcp.Secondary = string.IsNullOrEmpty(UCPCPInfo1.AlternatePhone) ? null : PhoneNumber.Create(UCPCPInfo1.AlternatePhone, PhoneNumberType.Office); pcp.Fax = string.IsNullOrEmpty(UCPCPInfo1.Fax) ? null : PhoneNumber.Create(UCPCPInfo1.Fax, PhoneNumberType.Unknown); pcp.Email = string.IsNullOrEmpty(UCPCPInfo1.Email) ? new Email(string.Empty, string.Empty) : new Email(UCPCPInfo1.Email); pcp.SecondaryEmail = string.IsNullOrEmpty(UCPCPInfo1.AlternateEmail) ? new Email(string.Empty, string.Empty) : new Email(UCPCPInfo1.AlternateEmail); pcp.Website = UCPCPInfo1.WebsiteUrl; pcp.DataRecorderMetaData.DataRecorderModifier = new OrganizationRoleUser(currentOrganizationRole.OrganizationRoleUserId); pcp.DataRecorderMetaData.DateModified = DateTime.Now; pcp.IsActive = true; } if (UCPCPInfo1.Address1.Trim().Length > 0 && UCPCPInfo1.State != "0" && UCPCPInfo1.City.Trim().Length > 0 && UCPCPInfo1.Zip.Trim().Length > 0) { long addressId = 0; if (pcp.Address != null) { addressId = pcp.Address.Id; } pcp.Address = new Address(addressId) { StreetAddressLine1 = UCPCPInfo1.Address1, StreetAddressLine2 = UCPCPInfo1.Address2, City = UCPCPInfo1.City, StateId = Convert.ToInt64(UCPCPInfo1.State), ZipCode = new ZipCode(UCPCPInfo1.Zip), CountryId = countryId }; } else { pcp.Address = null; } SetPcpMaillingAddress(pcp, countryId); } var isPcpAddressVerified = false; if (Convert.ToInt64(PhysicianMasterIdHiddenField.Value) > 0) { isPcpAddressVerified = chkVerifiedPcpInfo.Checked; } else { isPcpAddressVerified = UCPCPInfo1.IsPcpAddressVerified; } pcp.IsPcpAddressVerified = isPcpAddressVerified; pcp.PcpAddressVerifiedBy = currentOrganizationRole.OrganizationRoleUserId; pcp.PcpAddressVerifiedOn = DateTime.Now; pcp = primaryCarePhysicianRepository.Save(pcp); var currentActivePcp = primaryCarePhysicianRepository.Get(CustomerId); var eventCustomerRepository = IoC.Resolve <IEventCustomerRepository>(); if (EventId > 0) { var eventCustomer = eventCustomerRepository.GetRegisteredEventForUser(CustomerId, EventId); if (eventCustomer != null && currentActivePcp != null) { var eventCustomerPrimaryCarePhysicianRepository = IoC.Resolve <IEventCustomerPrimaryCarePhysicianRepository>(); var eventCustomerPrimarycarePhysician = new EventCustomerPrimaryCarePhysician { EventCustomerId = eventCustomer.Id, PrimaryCarePhysicianId = currentActivePcp.Id, IsPcpAddressVerified = isPcpAddressVerified, PcpAddressVerifiedOn = DateTime.Now, PcpAddressVerifiedBy = currentOrganizationRole.OrganizationRoleUserId }; eventCustomerPrimaryCarePhysicianRepository.Save(eventCustomerPrimarycarePhysician); } } if (newPcp && pcp.PhysicianMasterId == null) { var physicianMaster = new PhysicianMaster() { LastName = pcp.Name.LastName, FirstName = pcp.Name.FirstName, MiddleName = pcp.Name.MiddleName, PracticePhone = pcp.Primary, PracticeFax = pcp.Fax, IsImported = false, IsActive = true, DateCreated = DateTime.Now, Npi = "" }; if (pcp.Address != null) { physicianMaster.PracticeAddress1 = pcp.Address.StreetAddressLine1; physicianMaster.PracticeAddress2 = pcp.Address.StreetAddressLine2; physicianMaster.PracticeCity = pcp.Address.City; physicianMaster.PracticeState = pcp.Address.StateCode; physicianMaster.PracticeZip = pcp.Address.ZipCode.Zip; } if (pcp.MailingAddress != null) { physicianMaster.MailingAddress1 = pcp.MailingAddress.StreetAddressLine1; physicianMaster.MailingAddress2 = pcp.MailingAddress.StreetAddressLine2; physicianMaster.MailingCity = pcp.MailingAddress.City; physicianMaster.MailingState = pcp.MailingAddress.StateCode; physicianMaster.MailingZip = pcp.MailingAddress.ZipCode.Zip; } if (pcp.Address != null && pcp.MailingAddress == null) { physicianMaster.MailingAddress1 = pcp.Address.StreetAddressLine1; physicianMaster.MailingAddress2 = pcp.Address.StreetAddressLine2; physicianMaster.MailingCity = pcp.Address.City; physicianMaster.MailingState = pcp.Address.StateCode; physicianMaster.MailingZip = pcp.Address.ZipCode.Zip; } physicianMaster = physicianMasterRepository.Save(physicianMaster); pcp.PhysicianMasterId = physicianMaster.Id; primaryCarePhysicianRepository.Save(pcp); } } catch (Exception ex) { this.Page.ClientScript.RegisterStartupScript(typeof(string), "jscodecityvalidate", "alert('" + ex.Message + "');", true); return(false); } } if (Request.QueryString["Call"] != null && Request.QueryString["Call"] == "No") { if (Request.QueryString["CustomerID"] != null) { Response.RedirectUser("../AddNotes.aspx?LbuttonVisible=no&CustomerID=" + Request.QueryString["CustomerID"] + "&Name=" + Request.QueryString["Name"] + "&Call=No&EventRegistered=Yes" + "&guid=" + GuId); } else { Response.RedirectUser("../AddNotes.aspx?LbuttonVisible=no&Call=No&EventRegistered=Yes" + "&guid=" + GuId); } } else { if (Request.QueryString["CustomerID"] != null) { Response.RedirectUser("../AddNotes.aspx?LbuttonVisible=yes &CustomerID=" + Request.QueryString["CustomerID"] + "&Name=" + Request.QueryString["Name"] + "&guid=" + GuId); } else { Response.RedirectUser("../AddNotes.aspx?LbuttonVisible=yes" + "&guid=" + GuId); } } return(true); }