protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_SP_1538 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var practice = new ORM_HEC_MedicalPractis() { HEC_MedicalPractiseID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, Ext_CompanyInfo_RefID = Guid.NewGuid() }; practice.Save(Connection, Transaction); var companyInfo = new ORM_CMN_COM_CompanyInfo() { CMN_COM_CompanyInfoID = practice.Ext_CompanyInfo_RefID, Tenant_RefID = securityTicket.TenantID, CompanyInfo_EstablishmentNumber = Parameter.Practice_BSNR }; companyInfo.Save(Connection, Transaction); var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, IsTenant = true }).Single(); bParticipant.IsCompany = true; bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; bParticipant.Save(Connection, Transaction); if (Parameter.Doctor != null) { var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_2_Account.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, USR_Account_RefID = Parameter.Doctor.AccountID }).Single(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID }).First(); personInfo.FirstName = Parameter.Doctor.FirstName; personInfo.LastName = Parameter.Doctor.LastName; personInfo.Title = Parameter.Doctor.Title; personInfo.Save(Connection, Transaction); var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant(); bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bussinessParticipantTable.IsNaturalPerson = true; bussinessParticipantTable.Tenant_RefID = securityTicket.TenantID; bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; bussinessParticipantTable.Save(Connection, Transaction); var doctor = new ORM_HEC_Doctor(); doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; doctor.Account_RefID = Parameter.Doctor.AccountID; doctor.DoctorIDNumber = Parameter.Doctor.LANR; doctor.Save(Connection, Transaction); var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); if (Parameter.Doctor.BankData != null) { ORM_CMN_BPT_BusinessParticipant_2_BankAccount bussiness_2_BankaAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); bussiness_2_BankaAccount.AssignmentID = Guid.NewGuid(); bussiness_2_BankaAccount.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID; bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID = Guid.NewGuid(); bussiness_2_BankaAccount.Tenant_RefID = securityTicket.TenantID; bussiness_2_BankaAccount.Save(Connection, Transaction); ORM_ACC_BNK_BankAccount bankAccount = new ORM_ACC_BNK_BankAccount(); bankAccount.ACC_BNK_BankAccountID = bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID; bankAccount.Tenant_RefID = securityTicket.TenantID; bankAccount.OwnerText = Parameter.Doctor.BankData.AccountHolder; bankAccount.AccountNumber = Parameter.Doctor.BankData.AccountNumber; bankAccount.IBAN = Parameter.Doctor.BankData.IBAN; bankAccount.Bank_RefID = Guid.NewGuid(); bankAccount.Save(Connection, Transaction); ORM_ACC_BNK_Bank bank = new ORM_ACC_BNK_Bank(); bank.ACC_BNK_BankID = bankAccount.Bank_RefID; bank.Tenant_RefID = securityTicket.TenantID; bank.BankName = Parameter.Doctor.BankData.BankName; bank.BICCode = Parameter.Doctor.BankData.BIC; bank.BankNumber = Parameter.Doctor.BankData.BankNumber; bank.Save(Connection, Transaction); } } return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_SDBI_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var doctor = new ORM_HEC_Doctor(); if (Parameter.DoctorID != Guid.Empty) { var result = doctor.Load(Connection, Transaction, Parameter.DoctorID); if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } #region Edit bool bopAccIsChenged = (doctor.Account_RefID == Parameter.Account_RefID) ? false : true; doctor.Account_RefID = Parameter.Account_RefID; if (Parameter.isLucentisSave) { doctor.DoctorIDNumber = Parameter.ifLucentis_LANR; } doctor.Save(Connection, Transaction); //bussinessParticipant var query1 = new ORM_CMN_BPT_BusinessParticipant.Query(); query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID; var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First(); if (!bopAccIsChenged) { //personInfo var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; if (Parameter.isOphthalSave) { personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General; personInfo.Salutation_Letter = Parameter.ifOphthal_Salutation_Letter; } if (Parameter.isLucentisSave) { personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail; } personInfo.Save(Connection, Transaction); var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); if (Parameter.Contacts != null) { foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID); if (communicationContacts != null) { communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Content = parContact.Content; communicationContacts.Save(Connection, Transaction); } else { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = parContact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } } } else { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; account2personInfoQuery.IsDeleted = false; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; personInfo.Save(Connection, Transaction); var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); if (communicationContactsList != null) { foreach (var c in communicationContactsList) { c.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; c.Save(Connection, Transaction); } } if (Parameter.Contacts != null) { foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID); if (communicationContacts != null) { communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Content = parContact.Content; communicationContacts.Save(Connection, Transaction); } else { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = parContact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } } bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; bussinessParticipant.Save(Connection, Transaction); } if (Parameter.isLucentisSave) { foreach (var practice in Parameter.Practices) { //if (practice.PracticeID != Guid.Empty) { var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = practice.PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var associatedbusinessparticipantsOriginal = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3).FirstOrDefault(); if (associatedbusinessparticipantsOriginal != null) { associatedbusinessparticipantsOriginal.IsDeleted = practice.isDeleted; associatedbusinessparticipantsOriginal.Save(Connection, Transaction); } else { var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName; associatedbusinessparticipants.Creation_Timestamp = DateTime.Now; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); // } } } } if (Parameter.isOphthalSave && Parameter.Practices.Length == 1) { var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var associatedbusinessparticipantsRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3); ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant firstPractice; var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = Parameter.Practices[0].PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); if (associatedbusinessparticipantsRes.Count > 0) { associatedbusinessparticipantsRes = associatedbusinessparticipantsRes.OrderBy(a => a.Creation_Timestamp).ToList(); firstPractice = associatedbusinessparticipantsRes.First(); foreach (var item in associatedbusinessparticipantsRes) { if (item != firstPractice && item.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == practiceBPT.CMN_BPT_BusinessParticipantID) { item.IsDeleted = true; item.Save(Connection, Transaction); } } } else { firstPractice = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); firstPractice.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); firstPractice.Tenant_RefID = securityTicket.TenantID; firstPractice.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; } firstPractice.AssociatedParticipant_FunctionName = Parameter.Practices[0].AssociatedParticipant_FunctionName; firstPractice.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; firstPractice.Save(Connection, Transaction); } #endregion } else { #region Save //personInfo Guid personInfoID; if (Parameter.Account_RefID == Guid.Empty) { var personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; if (Parameter.isLucentisSave) { personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail; } personInfo.Title = Parameter.Title; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; if (Parameter.isOphthalSave) { personInfo.Salutation_Letter = Parameter.ifOphthal_Salutation_Letter; personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General; } personInfo.Save(Connection, Transaction); personInfoID = personInfo.CMN_PER_PersonInfoID; } else { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; account2personInfoQuery.IsDeleted = false; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; personInfo.Save(Connection, Transaction); personInfoID = personInfo.CMN_PER_PersonInfoID; } //bussinessParticipants var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant(); bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bussinessParticipantTable.IsNaturalPerson = true; bussinessParticipantTable.IsTenant = false; bussinessParticipantTable.IsCompany = false; bussinessParticipantTable.IsDeleted = false; bussinessParticipantTable.Creation_Timestamp = DateTime.Now; bussinessParticipantTable.Tenant_RefID = securityTicket.TenantID; bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; bussinessParticipantTable.Save(Connection, Transaction); doctor.HEC_DoctorID = Guid.NewGuid(); if (Parameter.isLucentisSave) { doctor.DoctorIDNumber = Parameter.ifLucentis_LANR; } doctor.Creation_Timestamp = DateTime.Now; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; doctor.Account_RefID = Parameter.Account_RefID; doctor.Save(Connection, Transaction); if (Parameter.Contacts != null) { foreach (var contact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfoID; communicationContacts.Contact_Type = contact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = contact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } foreach (var practice in Parameter.Practices) { if (practice.isDeleted == true) { continue; } var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = practice.PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); //associatedbusinessparticipants var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName; associatedbusinessparticipants.Creation_Timestamp = DateTime.Now; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); } #endregion } returnValue.Result = doctor.HEC_DoctorID; return(returnValue); #endregion UserCode }
public static void Save_Doctors_to_DB(Doctor_model_from_xlsx Parameter, string connectionString, SessionSecurityTicket securityTicket) { DbConnection Connection = null; DbTransaction Transaction = null; bool cleanupConnection = Connection == null; bool cleanupTransaction = Transaction == null; if (cleanupConnection == true) { Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString); Connection.Open(); } if (cleanupTransaction == true) { Transaction = Connection.BeginTransaction(); } try { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE"); Guid BusinessParticipantID = Guid.NewGuid(); Guid personInfoID = Guid.NewGuid(); Guid PracticeCustomerID = Guid.NewGuid(); Guid PracticeBusinessParticipantID = Guid.NewGuid(); Guid PracticeCompanyInfoID = Guid.NewGuid(); String PracticeName = ""; Guid BankAccountID = Guid.Empty; Guid doctor_id = Parameter.DoctorID; var isOpPractice = false; if (!String.IsNullOrEmpty(Parameter.LoginEmail)) //uncomment this if you've created account // if (false) { string[] stringUser = Parameter.LoginEmail.Split('@'); string usernameStr = stringUser[0]; try { var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, AccountSignInEmailAddress = Parameter.LoginEmail, }).Single(); var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query(); accountGroupQuery.Tenant_RefID = securityTicket.TenantID; accountGroupQuery.IsDeleted = false; accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group"; var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault(); if (accountGroup == null) { accountGroup = new ORM_USR_Account_FunctionLevelRights_Group(); accountGroup.Tenant_RefID = securityTicket.TenantID; accountGroup.Label = "mm.docconect.doc.app.group"; accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group"; accountGroup.Creation_Timestamp = DateTime.Now; accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid(); accountGroup.Save(Connection, Transaction); } var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, HEC_MedicalPractice_RefID = Parameter.PracticeID }).ToList(); List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>(); foreach (var item in PracticeAccount2UniversalProperty) { var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID }).Single(); PracticeUniversalPropertyList.Add(PracticeUniversalProperty); } ; P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522(); practiceAccountIDParameter.PracticeID = Parameter.PracticeID; var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query(); practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID; practiceAccountToFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID; practiceAccountToFunctionLevelRightQ.IsDeleted = false; var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault(); if (practiceAccountToFunctionLevelRight != null) { var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query(); practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID; practiceAccountFunctionLevelRightQ.IsDeleted = false; practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID; var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault(); if (practiceAccountFunctionLevelRight != null) { isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice"); } } var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query(); functionLevelRightQ.Tenant_RefID = securityTicket.TenantID; functionLevelRightQ.IsDeleted = false; functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor"; var existingFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault(); var tempFunctionLevelRightID = Guid.Empty; if (existingFunctionLevelRight == null) { ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight(); functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid(); functionLevelRight.FunctionLevelRights_Group_RefID = accountGroup.USR_Account_FunctionLevelRights_GroupID; functionLevelRight.Tenant_RefID = securityTicket.TenantID; functionLevelRight.Creation_Timestamp = DateTime.Now; functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor"; functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor"; functionLevelRight.Save(Connection, Transaction); tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID; } else { tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID; } var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight(); accountToFunctionLevelRight.Tenant_RefID = securityTicket.TenantID; accountToFunctionLevelRight.Creation_Timestamp = DateTime.Now; accountToFunctionLevelRight.AssignmentID = Guid.NewGuid(); accountToFunctionLevelRight.Account_RefID = doctorAccountInfo.USR_AccountID; accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID; accountToFunctionLevelRight.Save(Connection, Transaction); var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQ.IsDeleted = false; businessParticipantQ.Tenant_RefID = securityTicket.TenantID; businessParticipantQ.CMN_BPT_BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID; BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID; var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single(); DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(); DoctorBusinessParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastNAme; DoctorBusinessParticipant.IsNaturalPerson = true; DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now; DoctorBusinessParticipant.Save(Connection, Transaction); personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var companyInfoPractice = new ORM_CMN_PER_PersonInfo(); companyInfoPractice.IsDeleted = false; companyInfoPractice.Tenant_RefID = securityTicket.TenantID; companyInfoPractice.CMN_PER_PersonInfoID = personInfoID; companyInfoPractice.FirstName = Parameter.FirstName; companyInfoPractice.LastName = Parameter.LastNAme; companyInfoPractice.Salutation_General = Parameter.Salutation; companyInfoPractice.Title = Parameter.Title; companyInfoPractice.Save(Connection, Transaction); var communicationContact = new ORM_CMN_PER_CommunicationContact(); communicationContact.IsDeleted = false; communicationContact.Contact_Type = Guid.NewGuid(); communicationContact.Tenant_RefID = securityTicket.TenantID; communicationContact.Modification_Timestamp = DateTime.Now; communicationContact.PersonInfo_RefID = personInfoID; communicationContact.Content = Parameter.Email; communicationContact.Save(Connection, Transaction); Guid CommunicationContactTypeID = communicationContact.Contact_Type; var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType.IsDeleted = false; communicationContactType.Tenant_RefID = securityTicket.TenantID; communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID; communicationContactType.Type = "Email"; communicationContactType.Save(Connection, Transaction); var communicationContact2 = new ORM_CMN_PER_CommunicationContact(); communicationContact2.IsDeleted = false; communicationContact2.Contact_Type = Guid.NewGuid(); communicationContact2.Tenant_RefID = securityTicket.TenantID; communicationContact2.Modification_Timestamp = DateTime.Now; communicationContact2.PersonInfo_RefID = personInfoID; communicationContact2.Content = Parameter.Phone; communicationContact2.Save(Connection, Transaction); Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type; var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType2.IsDeleted = false; communicationContactType2.Tenant_RefID = securityTicket.TenantID; communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2; communicationContactType2.Type = "Phone"; communicationContactType2.Save(Connection, Transaction); var doctor = new ORM_HEC_Doctor(); doctor.HEC_DoctorID = Guid.NewGuid(); doctor.IsDeleted = false; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = BusinessParticipantID; doctor.DoctorIDNumber = Parameter.LANR.ToString(); doctor.Account_RefID = Parameter.account_id; doctor.Save(Connection, Transaction); doctor_id = doctor.HEC_DoctorID; var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID }).Single(); var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff(); organizationalunit_Staff.IsDeleted = false; organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID; organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID; organizationalunit_Staff.OrganizationalUnit_RefID = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID; organizationalunit_Staff.Save(Connection, Transaction); var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID }).Single(); var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID }).Single(); PracticeName = PracticeBusinessParticipant.DisplayName; PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID; PracticeCompanyInfoID = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID; if (Parameter.IsUsePracticeBank) { var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID, }).Single(); var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; //end of save bank data if inherited from practice } else { if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank)) { var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = Guid.NewGuid(); business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); var bankAccountDoctor = new ORM_ACC_BNK_BankAccount(); bankAccountDoctor.IsDeleted = false; bankAccountDoctor.Tenant_RefID = securityTicket.TenantID; bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; bankAccountDoctor.OwnerText = Parameter.AccountHolder; bankAccountDoctor.IBAN = Parameter.IBAN; bankAccountDoctor.Bank_RefID = Guid.NewGuid(); bankAccountDoctor.Creation_Timestamp = DateTime.Now; bankAccountDoctor.Save(Connection, Transaction); if (!String.IsNullOrEmpty(Parameter.Bank)) { var bank = new ORM_ACC_BNK_Bank(); bank.IsDeleted = false; bank.Tenant_RefID = securityTicket.TenantID; bank.ACC_BNK_BankID = bankAccountDoctor.Bank_RefID; bank.BICCode = Parameter.Bic; bank.BankName = Parameter.Bank; bank.Creation_Timestamp = DateTime.Now; bank.Save(Connection, Transaction); } BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; // end save bank data } } } catch { throw new Exception(); } } else { var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant(); DoctorBusinessParticipant.IsDeleted = false; DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID; DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(); DoctorBusinessParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastNAme; DoctorBusinessParticipant.IsNaturalPerson = true; DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now; DoctorBusinessParticipant.Save(Connection, Transaction); personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID; var companyInfoPractice = new ORM_CMN_PER_PersonInfo(); companyInfoPractice.IsDeleted = false; companyInfoPractice.Tenant_RefID = securityTicket.TenantID; companyInfoPractice.CMN_PER_PersonInfoID = personInfoID; companyInfoPractice.FirstName = Parameter.FirstName; companyInfoPractice.LastName = Parameter.LastNAme; companyInfoPractice.Salutation_General = Parameter.Salutation; companyInfoPractice.Title = Parameter.Title; companyInfoPractice.Save(Connection, Transaction); var communicationContact = new ORM_CMN_PER_CommunicationContact(); communicationContact.IsDeleted = false; communicationContact.Contact_Type = Guid.NewGuid(); communicationContact.Tenant_RefID = securityTicket.TenantID; communicationContact.Modification_Timestamp = DateTime.Now; communicationContact.PersonInfo_RefID = personInfoID; communicationContact.Content = Parameter.Email; communicationContact.Save(Connection, Transaction); Guid CommunicationContactTypeID = communicationContact.Contact_Type; var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType.IsDeleted = false; communicationContactType.Tenant_RefID = securityTicket.TenantID; communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID; communicationContactType.Type = "Email"; communicationContactType.Save(Connection, Transaction); var communicationContact2 = new ORM_CMN_PER_CommunicationContact(); communicationContact2.IsDeleted = false; communicationContact2.Contact_Type = Guid.NewGuid(); communicationContact2.Tenant_RefID = securityTicket.TenantID; communicationContact2.Modification_Timestamp = DateTime.Now; communicationContact2.PersonInfo_RefID = personInfoID; communicationContact2.Content = Parameter.Phone; communicationContact2.Save(Connection, Transaction); Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type; var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType2.IsDeleted = false; communicationContactType2.Tenant_RefID = securityTicket.TenantID; communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2; communicationContactType2.Type = "Phone"; communicationContactType2.Save(Connection, Transaction); var doctor = new ORM_HEC_Doctor(); doctor.HEC_DoctorID = Guid.NewGuid(); doctor.IsDeleted = false; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = BusinessParticipantID; doctor.DoctorIDNumber = Parameter.LANR.ToString(); doctor.Account_RefID = Parameter.account_id; doctor.Save(Connection, Transaction); doctor_id = doctor.HEC_DoctorID; var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID }).Single(); var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff(); organizationalunit_Staff.IsDeleted = false; organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID; organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID; organizationalunit_Staff.OrganizationalUnit_RefID = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID; organizationalunit_Staff.Save(Connection, Transaction); var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID }).Single(); var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID }).Single(); PracticeName = PracticeBusinessParticipant.DisplayName; PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID; PracticeCompanyInfoID = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID; if (Parameter.IsUsePracticeBank == true) { var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID, }).Single(); var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; //end of save bank data if inherited from practice } else { if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank)) { var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = Guid.NewGuid(); business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); var bankAccountDoctor = new ORM_ACC_BNK_BankAccount(); bankAccountDoctor.IsDeleted = false; bankAccountDoctor.Tenant_RefID = securityTicket.TenantID; bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; bankAccountDoctor.OwnerText = Parameter.AccountHolder; bankAccountDoctor.IBAN = Parameter.IBAN; bankAccountDoctor.Bank_RefID = Guid.NewGuid(); bankAccountDoctor.Creation_Timestamp = DateTime.Now; bankAccountDoctor.Save(Connection, Transaction); if (!String.IsNullOrEmpty(Parameter.Bank)) { var bank = new ORM_ACC_BNK_Bank(); bank.IsDeleted = false; bank.Tenant_RefID = securityTicket.TenantID; bank.ACC_BNK_BankID = bankAccountDoctor.Bank_RefID; bank.BICCode = Parameter.Bic; bank.BankName = Parameter.Bank; bank.Creation_Timestamp = DateTime.Now; bank.Save(Connection, Transaction); } BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; // end save bank data } } } var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CompanyInfo_RefID = PracticeCompanyInfoID, Address_Description = "Standard address for billing, shipping", }).SingleOrDefault(); Practice_Doctors_Model DPModel = new Practice_Doctors_Model(); if (PracticeCompanyInfoAddress != null) { var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID, }).SingleOrDefault(); DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number; DPModel.zip = PracticeUCD.ZIP; DPModel.city = PracticeUCD.Town; } DPModel.account_status = "aktiv"; DPModel.id = doctor_id.ToString(); var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim(); DPModel.name = title + " " + Parameter.FirstName + " " + Parameter.LastNAme; DPModel.name_untouched = Parameter.FirstName + " " + Parameter.LastNAme; DPModel.bsnr_lanr = Parameter.LANR.ToString(); DPModel.autocomplete_name = title + " " + Parameter.FirstName + " " + Parameter.LastNAme; DPModel.salutation = title; DPModel.type = "Doctor"; DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank; DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank; DPModel.phone = Parameter.Phone; DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email; DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN; DPModel.bic = string.IsNullOrEmpty(Parameter.Bic) ? "" : Parameter.Bic; DPModel.bank_id = BankAccountID.ToString(); DPModel.bank_info_inherited = Parameter.IsUsePracticeBank; DPModel.aditional_info = ""; DPModel.contract = 0; DPModel.tenantid = securityTicket.TenantID.ToString(); DPModel.practice_name_for_doctor = PracticeName; DPModel.practice_for_doctor_id = Parameter.PracticeID.ToString(); DPModel.role = isOpPractice ? "op" : "ac"; List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>(); DPModelL.Add(DPModel); Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString()); #region Assignment to Contract var contractIvi = ORM_CMN_CTR_Contract.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, ContractName = "IVI-Vertrag" }).SingleOrDefault(); if (contractIvi != null) { Guid AssignmentID = Guid.NewGuid(); var insuranceTobrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract.Query() { Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false, }).SingleOrDefault(); if (insuranceTobrokerContract != null) { AssignmentID = insuranceTobrokerContract.HEC_CRT_InsuranceToBrokerContractID; } else { var insuranceTobrokerContractNew = new ORM_HEC_CRT_InsuranceToBrokerContract(); insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID = Guid.NewGuid(); insuranceTobrokerContractNew.Creation_Timestamp = DateTime.Now; insuranceTobrokerContractNew.IsDeleted = false; insuranceTobrokerContractNew.Tenant_RefID = securityTicket.TenantID; insuranceTobrokerContractNew.Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID; insuranceTobrokerContractNew.Save(Connection, Transaction); AssignmentID = insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID; } var insuranceTobrokerContract2doctor = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctor(); insuranceTobrokerContract2doctor.Creation_Timestamp = DateTime.Now; insuranceTobrokerContract2doctor.HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctorID = Guid.NewGuid(); insuranceTobrokerContract2doctor.InsuranceToBrokerContract_RefID = AssignmentID; insuranceTobrokerContract2doctor.Tenant_RefID = securityTicket.TenantID; insuranceTobrokerContract2doctor.IsDeleted = false; insuranceTobrokerContract2doctor.Doctor_RefID = doctor_id; insuranceTobrokerContract2doctor.ValidFrom = new DateTime(2013, 6, 15); insuranceTobrokerContract2doctor.ValidThrough = DateTime.MinValue; insuranceTobrokerContract2doctor.Save(Connection, Transaction); P_DO_CDCD_1505 ParameterDoctorID = new P_DO_CDCD_1505(); ParameterDoctorID.DoctorID = doctor_id; var data = cls_Get_Doctor_Contract_Numbers.Invoke(Connection, Transaction, ParameterDoctorID, securityTicket).Result; int DoctorContracts = data.Count(); Doctor_Contracts ParameterDoctor = new Doctor_Contracts(); ParameterDoctor.DocID = doctor_id; Practice_Doctors_Model DoctorFound = Get_Doctors_for_PracticeID.Set_Contract_Number_for_DoctorID(ParameterDoctor, securityTicket); if (DoctorFound != null) { List <Practice_Doctors_Model> DoctorFoundL = new List <Practice_Doctors_Model>(); DoctorFound.contract = DoctorContracts; DoctorFoundL.Add(DoctorFound); Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DoctorFoundL, securityTicket.TenantID.ToString()); } P_DO_GPIDfDID_1353 ParametarDocID = new P_DO_GPIDfDID_1353(); ParametarDocID.DoctorID = doctor_id; DO_GPIDfDID_1353[] data2 = cls_Get_PracticeID_for_DoctorID.Invoke(Connection, Transaction, ParametarDocID, securityTicket).Result; P_DO_GCfPID_1507 ParametarPractice = new P_DO_GCfPID_1507(); ParametarPractice.PracticeID = data2.First().HEC_MedicalPractiseID; DO_GCfPID_1507[] Contracts = cls_Get_all_Doctors_Contract_Assignment_for_PracticeID.Invoke(Connection, Transaction, ParametarPractice, securityTicket).Result; int NumberOfContractsForPractice = Contracts.Count(); Practice_Doctors_Model practice = new Practice_Doctors_Model(); practice.id = ParametarPractice.PracticeID.ToString(); Practice_Doctors_Model PracticeFound = Get_Doctors_for_PracticeID.Get_Practice_for_PracticeID(practice, securityTicket); List <Practice_Doctors_Model> practiceL = new List <Practice_Doctors_Model>(); PracticeFound.contract = NumberOfContractsForPractice; practiceL.Add(PracticeFound); Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(practiceL, securityTicket.TenantID.ToString()); } #endregion if (cleanupTransaction == true) { Transaction.Commit(); } //Close the connection if (cleanupConnection == true) { Connection.Close(); } } catch (Exception ex) { try { if (cleanupTransaction == true && Transaction != null) { Transaction.Rollback(); } } catch { } try { if (cleanupConnection == true && Connection != null) { Connection.Close(); } } catch { } throw ex; } }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_DO_SAHD_1815 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); //Put your code here #region EMAIL Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE"); string urlMM = System.Configuration.ConfigurationManager.AppSettings["mmdocconnect.dashboard.url"]; List <String> mailToL = new List <String>(); var accountMails = cls_Get_All_Account_LoginEmails_Who_Receive_Notifications.Invoke(Connection, Transaction, securityTicket).Result.ToList(); foreach (var mail in accountMails) { mailToL.Add(mail.LoginEmail); } string appName = WebConfigurationManager.AppSettings["mmAppUrl"]; var prefix = HttpContext.Current.Request.Url.AbsoluteUri.Contains("https") ? "https://" : "http://"; var imageUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("api")) + "Content/images/logo.png"; var email_template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/NewTemporaryDoctorEmailTemplate.html")); var subjectsJson = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailSubjects.json")); dynamic subjects = Newtonsoft.Json.JsonConvert.DeserializeObject(subjectsJson); var subjectMail = subjects["NewTemporaryDoctorSubject"].ToString(); email_template = EmailTemplater.SetTemplateData(email_template, new { name = Parameter.name, street = String.IsNullOrEmpty(Parameter.street) ? "-" : Parameter.street, house_number = String.IsNullOrEmpty(Parameter.house_number) ? "-" : Parameter.house_number, zip = String.IsNullOrEmpty(Parameter.zip) ? "-" : Parameter.zip, city = String.IsNullOrEmpty(Parameter.city) ? "-" : Parameter.city, phone = String.IsNullOrEmpty(Parameter.phone) ? "-" : Parameter.phone, fax = String.IsNullOrEmpty(Parameter.fax) ? "-" : Parameter.fax, email = String.IsNullOrEmpty(Parameter.email) ? "-" : Parameter.email, comment = String.IsNullOrEmpty(Parameter.comment) ? "-" : Parameter.comment, doc_app_url = prefix + HttpContext.Current.Request.Url.Authority + "/" + appName, medios_connect_logo_url = imageUrl }, "{{", "}}"); try { // string mailFrom = cls_Get_Company_Settings.Invoke(Connection, Transaction, securityTicket).Result.Email; string mailFrom = WebConfigurationManager.AppSettings["mailFrom"]; var mailsDistinct = mailToL.Distinct().ToList(); foreach (var mailTo in mailsDistinct) { EmailNotificationSenderUtil.SendEmail(mailFrom, mailTo, subjectMail, email_template); } } catch (Exception ex) { LogUtils.Logger.LogDocAppInfo(new LogUtils.LogEntry(System.Reflection.MethodInfo.GetCurrentMethod(), ex, null, "Temporary doctor creation: Email sending failed."), "EmailExceptions"); } #endregion #region PERSON INFO ORM_CMN_PER_PersonInfo temporary_doctor_person_info = new ORM_CMN_PER_PersonInfo(); temporary_doctor_person_info.LastName = Parameter.name; temporary_doctor_person_info.Modification_Timestamp = DateTime.Now; temporary_doctor_person_info.Tenant_RefID = securityTicket.TenantID; temporary_doctor_person_info.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact_Type temporary_doctor_communication_contact_type_email = new ORM_CMN_PER_CommunicationContact_Type(); temporary_doctor_communication_contact_type_email.Tenant_RefID = securityTicket.TenantID; temporary_doctor_communication_contact_type_email.Type = "Email"; temporary_doctor_communication_contact_type_email.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact temporary_doctor_communication_contact_email = new ORM_CMN_PER_CommunicationContact(); temporary_doctor_communication_contact_email.Tenant_RefID = securityTicket.TenantID; temporary_doctor_communication_contact_email.Modification_Timestamp = DateTime.Now; temporary_doctor_communication_contact_email.PersonInfo_RefID = temporary_doctor_person_info.CMN_PER_PersonInfoID; temporary_doctor_communication_contact_email.Content = Parameter.email; temporary_doctor_communication_contact_email.Contact_Type = temporary_doctor_communication_contact_type_email.CMN_PER_CommunicationContact_TypeID; temporary_doctor_communication_contact_email.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact_Type temporary_doctor_communication_contact_type_phone = new ORM_CMN_PER_CommunicationContact_Type(); temporary_doctor_communication_contact_type_phone.Tenant_RefID = securityTicket.TenantID; temporary_doctor_communication_contact_type_phone.Type = "Phone"; temporary_doctor_communication_contact_type_phone.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact temporary_doctor_communication_contact_phone = new ORM_CMN_PER_CommunicationContact(); temporary_doctor_communication_contact_phone.Tenant_RefID = securityTicket.TenantID; temporary_doctor_communication_contact_phone.Modification_Timestamp = DateTime.Now; temporary_doctor_communication_contact_phone.PersonInfo_RefID = temporary_doctor_person_info.CMN_PER_PersonInfoID; temporary_doctor_communication_contact_phone.Content = Parameter.phone; temporary_doctor_communication_contact_phone.Contact_Type = temporary_doctor_communication_contact_type_phone.CMN_PER_CommunicationContact_TypeID; temporary_doctor_communication_contact_phone.Save(Connection, Transaction); #endregion #region BPT ORM_CMN_BPT_BusinessParticipant temporary_doctor_bpt = new ORM_CMN_BPT_BusinessParticipant(); temporary_doctor_bpt.IfNaturalPerson_CMN_PER_PersonInfo_RefID = temporary_doctor_person_info.CMN_PER_PersonInfoID; temporary_doctor_bpt.IsNaturalPerson = true; temporary_doctor_bpt.Modification_Timestamp = DateTime.Now; temporary_doctor_bpt.Tenant_RefID = securityTicket.TenantID; temporary_doctor_bpt.Save(Connection, Transaction); #endregion #region DOCTOR ORM_HEC_Doctor temporary_doctor = new ORM_HEC_Doctor(); // account ref. id = guid empty means that this is a temporary doctor with no account temporary_doctor.Account_RefID = Guid.Empty; temporary_doctor.BusinessParticipant_RefID = temporary_doctor_bpt.CMN_BPT_BusinessParticipantID; temporary_doctor.DoctorIDNumber = ""; temporary_doctor.IsDoctorForFollowupTreatmentsOnly = true; temporary_doctor.Tenant_RefID = securityTicket.TenantID; temporary_doctor.Save(Connection, Transaction); ORM_HEC_Doctor_UniversalProperty temporary_doctor_universal_property = new ORM_HEC_Doctor_UniversalProperty(); temporary_doctor_universal_property.GlobalPropertyMatchingID = "mm.docconnect.temporary.aftercare.doctor.comment"; temporary_doctor_universal_property.IsValue_String = true; temporary_doctor_universal_property.Modification_Timestamp = DateTime.Now; temporary_doctor_universal_property.PropertyName = "Comment"; temporary_doctor_universal_property.Tenant_RefID = securityTicket.TenantID; temporary_doctor_universal_property.Save(Connection, Transaction); ORM_HEC_Doctor_UniversalPropertyValue temporary_doctor_universal_property_value = new ORM_HEC_Doctor_UniversalPropertyValue(); temporary_doctor_universal_property_value.HEC_Doctor_RefID = temporary_doctor.HEC_DoctorID; temporary_doctor_universal_property_value.Modification_Timestamp = DateTime.Now; temporary_doctor_universal_property_value.Value_String = Parameter.comment; temporary_doctor_universal_property_value.UniversalProperty_RefID = temporary_doctor_universal_property.HEC_Doctor_UniversalPropertyID; temporary_doctor_universal_property_value.Tenant_RefID = securityTicket.TenantID; temporary_doctor_universal_property_value.Save(Connection, Transaction); #endregion #region IMPORT TO ELASTIC Practice_Doctors_Model temporary_doctor_elastic_model = new Practice_Doctors_Model(); temporary_doctor_elastic_model.autocomplete_name = Parameter.name; temporary_doctor_elastic_model.name = Parameter.name; temporary_doctor_elastic_model.name_untouched = Parameter.name; temporary_doctor_elastic_model.address = Parameter.street + " " + Parameter.house_number; temporary_doctor_elastic_model.zip = Parameter.zip; temporary_doctor_elastic_model.city = Parameter.city; temporary_doctor_elastic_model.email = Parameter.email; temporary_doctor_elastic_model.phone = Parameter.phone; temporary_doctor_elastic_model.account_status = "temp"; temporary_doctor_elastic_model.id = temporary_doctor.HEC_DoctorID.ToString(); temporary_doctor_elastic_model.practice_for_doctor_id = Parameter.practice_id.ToString(); temporary_doctor_elastic_model.tenantid = securityTicket.TenantID.ToString(); temporary_doctor_elastic_model.type = "Doctor"; Add_New_Practice.Import_Practice_Data_to_ElasticDB(new List <Practice_Doctors_Model>() { temporary_doctor_elastic_model }, securityTicket.TenantID.ToString()); #endregion returnValue.Result = temporary_doctor.HEC_DoctorID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_DO_SD_1517 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); //Put your code here Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE"); Guid BusinessParticipantID = Guid.NewGuid(); Guid personInfoID = Guid.NewGuid(); Guid PracticeCustomerID = Guid.NewGuid(); Guid PracticeBusinessParticipantID = Guid.NewGuid(); Guid PracticeCompanyInfoID = Guid.NewGuid(); String PracticeName = ""; Guid BankAccountID = Guid.Empty; Guid doctor_id = Parameter.DoctorID; var isOpPractice = false; //if (!String.IsNullOrEmpty(Parameter.Login_Email)) //uncomment this if you've created account if (false) { string[] stringUser = Parameter.Login_Email.Split('@'); string usernameStr = stringUser[0]; try { var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, AccountSignInEmailAddress = Parameter.Login_Email, }).Single(); var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query(); accountGroupQuery.Tenant_RefID = securityTicket.TenantID; accountGroupQuery.IsDeleted = false; accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group"; var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault(); if (accountGroup == null) { accountGroup = new ORM_USR_Account_FunctionLevelRights_Group(); accountGroup.Tenant_RefID = securityTicket.TenantID; accountGroup.Label = "mm.docconect.doc.app.group"; accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group"; accountGroup.Creation_Timestamp = DateTime.Now; accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid(); accountGroup.Save(Connection, Transaction); } var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, HEC_MedicalPractice_RefID = Parameter.PracticeID }).ToList(); List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>(); foreach (var item in PracticeAccount2UniversalProperty) { var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID }).Single(); PracticeUniversalPropertyList.Add(PracticeUniversalProperty); } ; P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522(); practiceAccountIDParameter.PracticeID = Parameter.PracticeID; var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query(); practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID; practiceAccountToFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID; practiceAccountToFunctionLevelRightQ.IsDeleted = false; var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault(); if (practiceAccountToFunctionLevelRight != null) { var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query(); practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID; practiceAccountFunctionLevelRightQ.IsDeleted = false; practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID; var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault(); if (practiceAccountFunctionLevelRight != null) { isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice"); } } var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query(); functionLevelRightQ.Tenant_RefID = securityTicket.TenantID; functionLevelRightQ.IsDeleted = false; functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor"; var existingFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault(); var tempFunctionLevelRightID = Guid.Empty; if (existingFunctionLevelRight == null) { ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight(); functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid(); functionLevelRight.FunctionLevelRights_Group_RefID = accountGroup.USR_Account_FunctionLevelRights_GroupID; functionLevelRight.Tenant_RefID = securityTicket.TenantID; functionLevelRight.Creation_Timestamp = DateTime.Now; functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor"; functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor"; functionLevelRight.Save(Connection, Transaction); tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID; } else { tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID; } var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight(); accountToFunctionLevelRight.Tenant_RefID = securityTicket.TenantID; accountToFunctionLevelRight.Creation_Timestamp = DateTime.Now; accountToFunctionLevelRight.AssignmentID = Guid.NewGuid(); accountToFunctionLevelRight.Account_RefID = doctorAccountInfo.USR_AccountID; accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID; accountToFunctionLevelRight.Save(Connection, Transaction); var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQ.IsDeleted = false; businessParticipantQ.Tenant_RefID = securityTicket.TenantID; businessParticipantQ.CMN_BPT_BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID; BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID; var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single(); DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(); DoctorBusinessParticipant.DisplayName = Parameter.First_Name + " " + Parameter.Last_Name; DoctorBusinessParticipant.IsNaturalPerson = true; DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now; DoctorBusinessParticipant.Save(Connection, Transaction); personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var companyInfoPractice = new ORM_CMN_PER_PersonInfo(); companyInfoPractice.IsDeleted = false; companyInfoPractice.Tenant_RefID = securityTicket.TenantID; companyInfoPractice.CMN_PER_PersonInfoID = personInfoID; companyInfoPractice.FirstName = Parameter.First_Name; companyInfoPractice.LastName = Parameter.Last_Name; companyInfoPractice.Salutation_General = Parameter.Salutation; companyInfoPractice.Title = Parameter.Title; companyInfoPractice.Save(Connection, Transaction); var communicationContact = new ORM_CMN_PER_CommunicationContact(); communicationContact.IsDeleted = false; communicationContact.Contact_Type = Guid.NewGuid(); communicationContact.Tenant_RefID = securityTicket.TenantID; communicationContact.Modification_Timestamp = DateTime.Now; communicationContact.PersonInfo_RefID = personInfoID; communicationContact.Content = Parameter.Email; communicationContact.Save(Connection, Transaction); Guid CommunicationContactTypeID = communicationContact.Contact_Type; var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType.IsDeleted = false; communicationContactType.Tenant_RefID = securityTicket.TenantID; communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID; communicationContactType.Type = "Email"; communicationContactType.Save(Connection, Transaction); var communicationContact2 = new ORM_CMN_PER_CommunicationContact(); communicationContact2.IsDeleted = false; communicationContact2.Contact_Type = Guid.NewGuid(); communicationContact2.Tenant_RefID = securityTicket.TenantID; communicationContact2.Modification_Timestamp = DateTime.Now; communicationContact2.PersonInfo_RefID = personInfoID; communicationContact2.Content = Parameter.Phone; communicationContact2.Save(Connection, Transaction); Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type; var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType2.IsDeleted = false; communicationContactType2.Tenant_RefID = securityTicket.TenantID; communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2; communicationContactType2.Type = "Phone"; communicationContactType2.Save(Connection, Transaction); var doctor = new ORM_HEC_Doctor(); doctor.HEC_DoctorID = Guid.NewGuid(); doctor.IsDeleted = false; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = BusinessParticipantID; doctor.DoctorIDNumber = Parameter.LANR.ToString(); doctor.Save(Connection, Transaction); doctor_id = doctor.HEC_DoctorID; var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID }).Single(); var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff(); organizationalunit_Staff.IsDeleted = false; organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID; organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID; organizationalunit_Staff.OrganizationalUnit_RefID = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID; organizationalunit_Staff.Save(Connection, Transaction); var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID }).Single(); var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID }).Single(); PracticeName = PracticeBusinessParticipant.DisplayName; PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID; PracticeCompanyInfoID = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID; if (Parameter.From_Practice_Bank) { var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID, }).Single(); var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; //end of save bank data if inherited from practice } else { if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank)) { var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = Guid.NewGuid(); business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); var bankAccountDoctor = new ORM_ACC_BNK_BankAccount(); bankAccountDoctor.IsDeleted = false; bankAccountDoctor.Tenant_RefID = securityTicket.TenantID; bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; bankAccountDoctor.OwnerText = Parameter.Account_Holder; bankAccountDoctor.IBAN = Parameter.IBAN; bankAccountDoctor.Bank_RefID = Guid.NewGuid(); bankAccountDoctor.Creation_Timestamp = DateTime.Now; bankAccountDoctor.Save(Connection, Transaction); if (!String.IsNullOrEmpty(Parameter.Bank)) { var bank = new ORM_ACC_BNK_Bank(); bank.IsDeleted = false; bank.Tenant_RefID = securityTicket.TenantID; bank.ACC_BNK_BankID = bankAccountDoctor.Bank_RefID; bank.BICCode = Parameter.BIC; bank.BankName = Parameter.Bank; bank.Creation_Timestamp = DateTime.Now; bank.Save(Connection, Transaction); } BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; // end save bank data } } } catch { throw new Exception(); } } else { var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant(); DoctorBusinessParticipant.IsDeleted = false; DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID; DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(); DoctorBusinessParticipant.DisplayName = Parameter.First_Name + " " + Parameter.Last_Name; DoctorBusinessParticipant.IsNaturalPerson = true; DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now; DoctorBusinessParticipant.Save(Connection, Transaction); personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID; var companyInfoPractice = new ORM_CMN_PER_PersonInfo(); companyInfoPractice.IsDeleted = false; companyInfoPractice.Tenant_RefID = securityTicket.TenantID; companyInfoPractice.CMN_PER_PersonInfoID = personInfoID; companyInfoPractice.FirstName = Parameter.First_Name; companyInfoPractice.LastName = Parameter.Last_Name; companyInfoPractice.Salutation_General = Parameter.Salutation; companyInfoPractice.Title = Parameter.Title; companyInfoPractice.Save(Connection, Transaction); var communicationContact = new ORM_CMN_PER_CommunicationContact(); communicationContact.IsDeleted = false; communicationContact.Contact_Type = Guid.NewGuid(); communicationContact.Tenant_RefID = securityTicket.TenantID; communicationContact.Modification_Timestamp = DateTime.Now; communicationContact.PersonInfo_RefID = personInfoID; communicationContact.Content = Parameter.Email; communicationContact.Save(Connection, Transaction); Guid CommunicationContactTypeID = communicationContact.Contact_Type; var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType.IsDeleted = false; communicationContactType.Tenant_RefID = securityTicket.TenantID; communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID; communicationContactType.Type = "Email"; communicationContactType.Save(Connection, Transaction); var communicationContact2 = new ORM_CMN_PER_CommunicationContact(); communicationContact2.IsDeleted = false; communicationContact2.Contact_Type = Guid.NewGuid(); communicationContact2.Tenant_RefID = securityTicket.TenantID; communicationContact2.Modification_Timestamp = DateTime.Now; communicationContact2.PersonInfo_RefID = personInfoID; communicationContact2.Content = Parameter.Phone; communicationContact2.Save(Connection, Transaction); Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type; var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type(); communicationContactType2.IsDeleted = false; communicationContactType2.Tenant_RefID = securityTicket.TenantID; communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2; communicationContactType2.Type = "Phone"; communicationContactType2.Save(Connection, Transaction); var doctor = new ORM_HEC_Doctor(); doctor.HEC_DoctorID = Guid.NewGuid(); doctor.IsDeleted = false; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = BusinessParticipantID; doctor.DoctorIDNumber = Parameter.LANR.ToString(); doctor.Save(Connection, Transaction); doctor_id = doctor.HEC_DoctorID; var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID }).Single(); var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff(); organizationalunit_Staff.IsDeleted = false; organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID; organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID; organizationalunit_Staff.OrganizationalUnit_RefID = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID; organizationalunit_Staff.Save(Connection, Transaction); var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID }).Single(); var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID }).Single(); PracticeName = PracticeBusinessParticipant.DisplayName; PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID; PracticeCompanyInfoID = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID; if (Parameter.From_Practice_Bank == true) { var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID, }).Single(); var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID; //end of save bank data if inherited from practice } else { if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank)) { var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = Guid.NewGuid(); business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); var bankAccountDoctor = new ORM_ACC_BNK_BankAccount(); bankAccountDoctor.IsDeleted = false; bankAccountDoctor.Tenant_RefID = securityTicket.TenantID; bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; bankAccountDoctor.OwnerText = Parameter.Account_Holder; bankAccountDoctor.IBAN = Parameter.IBAN; bankAccountDoctor.Bank_RefID = Guid.NewGuid(); bankAccountDoctor.Creation_Timestamp = DateTime.Now; bankAccountDoctor.Save(Connection, Transaction); if (!String.IsNullOrEmpty(Parameter.Bank)) { var bank = new ORM_ACC_BNK_Bank(); bank.IsDeleted = false; bank.Tenant_RefID = securityTicket.TenantID; bank.ACC_BNK_BankID = bankAccountDoctor.Bank_RefID; bank.BICCode = Parameter.BIC; bank.BankName = Parameter.Bank; bank.Creation_Timestamp = DateTime.Now; bank.Save(Connection, Transaction); } BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; // end save bank data } } } var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CompanyInfo_RefID = PracticeCompanyInfoID, Address_Description = "Standard address for billing, shipping", }).SingleOrDefault(); Practice_Doctors_Model DPModel = new Practice_Doctors_Model(); if (PracticeCompanyInfoAddress != null) { var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID, }).SingleOrDefault(); DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number; DPModel.zip = PracticeUCD.ZIP; DPModel.city = PracticeUCD.Town; } DPModel.account_status = "aktiv"; DPModel.id = doctor_id.ToString(); var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim(); DPModel.name = title + " " + Parameter.Last_Name + " " + Parameter.First_Name; DPModel.name_untouched = Parameter.Last_Name + " " + Parameter.First_Name; DPModel.bsnr_lanr = Parameter.LANR.ToString(); DPModel.salutation = title; DPModel.type = "Doctor"; DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank; DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank; DPModel.phone = Parameter.Phone; DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email; DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN; DPModel.bic = string.IsNullOrEmpty(Parameter.BIC) ? "" : Parameter.BIC; DPModel.bank_id = BankAccountID.ToString(); DPModel.bank_info_inherited = Parameter.From_Practice_Bank; DPModel.aditional_info = ""; DPModel.contract = 0; DPModel.tenantid = securityTicket.TenantID.ToString(); DPModel.practice_name_for_doctor = PracticeName; DPModel.practice_for_doctor_id = Parameter.PracticeID.ToString(); DPModel.role = isOpPractice ? "op" : "ac"; List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>(); DPModelL.Add(DPModel); Add_New_Practice.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString()); return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_DDbID_1031 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); var doctor = new ORM_HEC_Doctor(); if (Parameter.DoctorID != Guid.Empty) { var result = doctor.Load(Connection, Transaction, Parameter.DoctorID); if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } doctor.IsDeleted = true; doctor.Save(Connection, Transaction); //bussinessParticipant var query1 = new ORM_CMN_BPT_BusinessParticipant.Query(); query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID; var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First(); bussinessParticipant.IsDeleted = true; bussinessParticipant.Save(Connection, Transaction); if (doctor.Account_RefID != Guid.Empty) { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = doctor.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).FirstOrDefault(); if (account2personInfo != null) { account2personInfo.IsDeleted = true; account2personInfo.Save(Connection, Transaction); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.IsDeleted = true; personInfo.Save(Connection, Transaction); } var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); foreach (var contact in communicationContactsList) { contact.IsDeleted = true; contact.Save(Connection, Transaction); } } var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var abpRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3); foreach (ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant assigned in abpRes) { assigned.IsDeleted = true; assigned.Save(Connection, Transaction); } #endregion ORM_CMN_BPT_CTM_Customer customer; ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative; var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.Ext_BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery); if (customerRes.Count != 0) { customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First(); var SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query(); SalesRepresentativeQuery.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; SalesRepresentative = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, SalesRepresentativeQuery).First(); customer.IsDeleted = true; customer.Save(Connection, Transaction); SalesRepresentative.IsDeleted = true; SalesRepresentative.Save(Connection, Transaction); } var accountQuery = new ORM_USR_Account.Query(); accountQuery.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; accountQuery.AccountType = 3; var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery); if (accountQueryRes.Count != 0) { var account = accountQueryRes.First(); account.IsDeleted = true; account.Save(Connection, Transaction); var codeQuery = new ORM_USR_Device_AccountCode.Query(); codeQuery.Account_RefID = account.USR_AccountID; var code = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, codeQuery).First(); code.IsDeleted = true; code.Save(Connection, Transaction); var codeStatusQuery = new ORM_USR_Device_AccountCode_StatusHistory.Query(); codeStatusQuery.Device_AccountCode_RefID = code.USR_Device_AccountCodeID; var codeStatus = ORM_USR_Device_AccountCode_StatusHistory.Query.Search(Connection, Transaction, codeStatusQuery).First(); codeStatus.IsDeleted = true; codeStatus.Save(Connection, Transaction); } } returnValue.Result = doctor.HEC_DoctorID; return(returnValue); }