protected static FR_L6PA_SPBDwDCaPHIwBD_1222 Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SPBDwDCaPHIwBD_1222 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6PA_SPBDwDCaPHIwBD_1222();
            //Put your code here
            P_L6PA_SPBDwDC_1323 BaseDataParam = new P_L6PA_SPBDwDC_1323();
            BaseDataParam.BaseData = Parameter.BaseData.BaseData;
            var res = cls_Save_PatientBaseData_withDeleteCheck.Invoke(Connection, Transaction, BaseDataParam, securityTicket).Result;
            returnValue.Result    = new L6PA_SPBDwDCaPHIwBD_1222();
            returnValue.Result.ID = res.ID;
            returnValue.Result.UsedInAppointment = res.UsedInAppointment;
            P_L5PA_SPHIaBD_1143 InsuranceDataParam = new P_L5PA_SPHIaBD_1143();
            InsuranceDataParam.AccountNumber                       = Parameter.InsuranceAndBankDataInfo.AccountNumber;
            InsuranceDataParam.BankName                            = Parameter.InsuranceAndBankDataInfo.BankName;
            InsuranceDataParam.BICCode                             = Parameter.InsuranceAndBankDataInfo.BICCode;
            InsuranceDataParam.CompanyName                         = Parameter.InsuranceAndBankDataInfo.CompanyName;
            InsuranceDataParam.HealthInsurance_Number              = Parameter.InsuranceAndBankDataInfo.HealthInsurance_Number;
            InsuranceDataParam.HEC_HealthInsurance_CompanyID       = Parameter.InsuranceAndBankDataInfo.HEC_HealthInsurance_CompanyID;
            InsuranceDataParam.HEC_Patient_HealthInsurance_StateID = Parameter.InsuranceAndBankDataInfo.HEC_Patient_HealthInsurance_StateID;
            InsuranceDataParam.IBAN = Parameter.InsuranceAndBankDataInfo.IBAN;
            InsuranceDataParam.InsuranceValidFrom    = Parameter.InsuranceAndBankDataInfo.InsuranceValidFrom;
            InsuranceDataParam.InsuranceValidThrough = Parameter.InsuranceAndBankDataInfo.InsuranceValidThrough;
            InsuranceDataParam.IsDeleted             = Parameter.InsuranceAndBankDataInfo.IsDeleted;
            InsuranceDataParam.IsNotSelfInsured      = Parameter.InsuranceAndBankDataInfo.IsNotSelfInsured;
            InsuranceDataParam.IsNotSelfInsured_InsuredPersonBirthday = Parameter.InsuranceAndBankDataInfo.IsNotSelfInsured_InsuredPersonBirthday;
            InsuranceDataParam.IsNotSelfInsured_InsuredPersonName     = Parameter.InsuranceAndBankDataInfo.IsNotSelfInsured_InsuredPersonName;
            InsuranceDataParam.OwnerText = Parameter.InsuranceAndBankDataInfo.OwnerText;
            InsuranceDataParam.PatientID = res.ID;
            cls_Save_PatienHealthInsurance_and_BankData.Invoke(Connection, Transaction, InsuranceDataParam, securityTicket);


            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L6PA_SPBDwDC_1323 Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SPBDwDC_1323 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L6PA_SPBDwDC_1323();
            //Put your code here

            returnValue.Result = new L6PA_SPBDwDC_1323();

            Guid PatientId = Guid.Empty;
            if (!Parameter.BaseData.isDeleted)
            {
                PatientId = cls_Save_PatientBaseData.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;

                cls_Create_EMRCreationRequest.Invoke(Connection, Transaction, new P_L5ME_CECRfPID_1520()
                {
                    PatientID = PatientId
                }, securityTicket);
            }
            else
            {
                List <ORM_HEC_ACT_PlannedAction> existingAppointment = ORM_HEC_ACT_PlannedAction.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PlannedAction.Query
                {
                    IsDeleted     = false,
                    Tenant_RefID  = securityTicket.TenantID,
                    Patient_RefID = Parameter.BaseData.ID
                }).ToList();

                if (existingAppointment.Count > 0) //cannot delete
                {
                    List <L6PA_SPBDwDC_1323_UsedInAppointment> usedAppointmentList = new List <L6PA_SPBDwDC_1323_UsedInAppointment>();

                    foreach (var appointment in existingAppointment)
                    {
                        ORM_HEC_APP_Appointment patientAppointment = ORM_HEC_APP_Appointment.Query.Search(Connection, Transaction, new ORM_HEC_APP_Appointment.Query
                        {
                            IsDeleted             = false,
                            Tenant_RefID          = securityTicket.TenantID,
                            HEC_APP_AppointmentID = appointment.Appointment_RefID
                        }).Single();

                        ORM_PPS_TSK_Task appointmentName = ORM_PPS_TSK_Task.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task.Query
                        {
                            IsDeleted      = false,
                            Tenant_RefID   = securityTicket.TenantID,
                            PPS_TSK_TaskID = patientAppointment.Ext_PPS_TSK_Task_RefID
                        }).Single();

                        usedAppointmentList.Add(new L6PA_SPBDwDC_1323_UsedInAppointment {
                            AppointmentName = appointmentName.DisplayName
                        });
                    }
                    returnValue.Result.UsedInAppointment = usedAppointmentList.ToArray();
                }

                if (existingAppointment.Count == 0)
                {
                    PatientId = cls_Save_PatientBaseData.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;
                }
            }
            returnValue.Result.ID = PatientId;

            return(returnValue);

            #endregion UserCode
        }
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L6PA_SPBDwDC_1323 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L6PA_SPBDwDC_1323 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L6PA_SPBDwDC_1323 functionReturn = new FR_L6PA_SPBDwDC_1323();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Save_PatientBaseData_withDeleteCheck", ex);
            }
            return(functionReturn);
        }
 ///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_L6PA_SPBDwDC_1323 Invoke(DbConnection Connection, DbTransaction Transaction, P_L6PA_SPBDwDC_1323 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_L6PA_SPBDwDC_1323 Invoke(string ConnectionString, P_L6PA_SPBDwDC_1323 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }