public static void Update_Doctors_add_Contract_Assignment(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
            {
                var allDoctors = ORM_HEC_Doctor.Query.Search(Connection, Transaction, new ORM_HEC_Doctor.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).ToList();
                foreach (var doctor in allDoctors)
                {
                    #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.HEC_DoctorID;
                        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.HEC_DoctorID;
                        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.HEC_DoctorID;

                        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.HEC_DoctorID;
                        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;
            }
        }
Beispiel #2
0
        public static void Import_Data_From_DB_To_Elastic(DbConnection Connection, DbTransaction Transaction, SessionSecurityTicket securityTicket)
        {
            #region add Practices and Doctors to Elastic
            List <Practice_Doctors_Model> LdoctorPracticeM = new List <Practice_Doctors_Model>();
            var dataPractice = cls_Get_All_Practices_from_DB.Invoke(Connection, Transaction, securityTicket).Result;
            IAccountServiceProvider accountService;
            var _providerFactory = ProviderFactory.Instance;
            accountService = _providerFactory.CreateAccountServiceProvider();

            if (dataPractice != null)
            {
                foreach (var practice in dataPractice)
                {
                    Practice_Doctors_Model doctorPracticeM = new Practice_Doctors_Model();

                    bool statusAcc = accountService.GetAccountStatusHistory(securityTicket.TenantID, practice.AccountID).OrderBy(st => st.CreationTimestamp).Reverse().FirstOrDefault().Status == EAccountStatus.BANNED;
                    doctorPracticeM.account_status = statusAcc ? "inaktiv" : "aktiv";
                    doctorPracticeM.id             = practice.PracticeID.ToString();
                    doctorPracticeM.name           = practice.Name;
                    doctorPracticeM.name_untouched = practice.Name;
                    doctorPracticeM.salutation     = "";
                    doctorPracticeM.type           = "Practice";
                    doctorPracticeM.address        = practice.Street_Name + " " + practice.Street_Number;
                    doctorPracticeM.zip            = practice.ZIP;
                    doctorPracticeM.city           = practice.City;
                    if (practice.Contact_Email != null)
                    {
                        doctorPracticeM.email = practice.Contact_Email;
                    }
                    doctorPracticeM.phone = doctorPracticeM.phone;

                    doctorPracticeM.bank_untouched = practice.BankName != null ? practice.BankName : "";
                    doctorPracticeM.bank           = practice.BankName != null ? practice.BankName : "";

                    if (practice.IBAN != null)
                    {
                        doctorPracticeM.iban = practice.IBAN;
                    }
                    if (practice.BICCode != null)
                    {
                        doctorPracticeM.bic = practice.BICCode;
                    }
                    doctorPracticeM.bsnr_lanr      = practice.BSNR;
                    doctorPracticeM.aditional_info = "";
                    doctorPracticeM.tenantid       = securityTicket.TenantID.ToString();
                    doctorPracticeM.role           = practice.IsSurgeryPractice ? "op" : "ac";
                    DO_GPCN_1133[] dataContract = cls_Get_Practice_Contract_Numbers.Invoke(Connection, Transaction, new P_DO_GPCN_1133()
                    {
                        PracticeID = practice.PracticeID
                    }, securityTicket).Result;
                    doctorPracticeM.contract = dataContract.Count();
                    LdoctorPracticeM.Add(doctorPracticeM);
                }
            }
            var dataDoc = cls_Get_All_Doctors_from_DB.Invoke(Connection, Transaction, securityTicket).Result;
            if (dataDoc != null)
            {
                foreach (var doctor in dataDoc)
                {
                    Practice_Doctors_Model doctorPracticeM = new Practice_Doctors_Model();
                    bool statusAcc = accountService.GetAccountStatusHistory(securityTicket.TenantID, doctor.AccountID).OrderBy(st => st.CreationTimestamp).Reverse().FirstOrDefault().Status == EAccountStatus.BANNED;
                    doctorPracticeM.account_status = statusAcc ? "inaktiv" : "aktiv";
                    doctorPracticeM.id             = doctor.Id.ToString();
                    var title = string.IsNullOrEmpty(doctor.Title) ? "" : doctor.Title.Trim();
                    doctorPracticeM.tenantid       = securityTicket.TenantID.ToString();
                    doctorPracticeM.name           = title + " " + doctor.LastName + " " + doctor.FirstName;
                    doctorPracticeM.name_untouched = doctor.LastName + " " + doctor.FirstName;
                    doctorPracticeM.bsnr_lanr      = doctor.Lanr.ToString();
                    doctorPracticeM.salutation     = title;
                    doctorPracticeM.type           = "Doctor";
                    doctorPracticeM.bank           = string.IsNullOrEmpty(doctor.BankName) ? "" : doctor.BankName;
                    doctorPracticeM.bank_untouched = string.IsNullOrEmpty(doctor.BankName) ? "" : doctor.BankName;
                    doctorPracticeM.phone          = doctor.Phone;
                    doctorPracticeM.email          = string.IsNullOrEmpty(doctor.Email) ? "" : doctor.Email;

                    doctorPracticeM.iban = string.IsNullOrEmpty(doctor.IBAN) ? "" : doctor.IBAN;

                    doctorPracticeM.bic = string.IsNullOrEmpty(doctor.BICCode) ? "" : doctor.BICCode;
                    var practice = dataPractice.Where(pr => pr.PracticeID == doctor.Practice_ID).SingleOrDefault();
                    doctorPracticeM.practice_for_doctor_id   = practice.PracticeID.ToString();
                    doctorPracticeM.practice_name_for_doctor = practice.Name;
                    doctorPracticeM.address = practice.Street_Name + " " + practice.Street_Number;
                    doctorPracticeM.zip     = practice.ZIP;
                    doctorPracticeM.city    = practice.City;
                    doctorPracticeM.role    = practice.IsSurgeryPractice ? "op" : "ac";

                    if (doctor.BankAccountID == practice.BankAccountID)
                    {
                        doctorPracticeM.bank_id             = practice.BankAccountID.ToString();
                        doctorPracticeM.bank_info_inherited = true;
                        doctorPracticeM.bank_untouched      = practice.BankName != null ? practice.BankName : "";
                        doctorPracticeM.bank = practice.BankName != null ? practice.BankName : "";

                        if (practice.IBAN != null)
                        {
                            doctorPracticeM.iban = practice.IBAN;
                        }
                        if (practice.BICCode != null)
                        {
                            doctorPracticeM.bic = practice.BICCode;
                        }
                    }
                    else
                    {
                        doctorPracticeM.bank_id             = doctor.BankAccountID.ToString();
                        doctorPracticeM.bank_info_inherited = false;
                        doctorPracticeM.bank_untouched      = doctor.BankName != null ? doctor.BankName : "";
                        doctorPracticeM.bank = doctor.BankName != null ? doctor.BankName : "";

                        if (doctor.IBAN != null)
                        {
                            doctorPracticeM.iban = doctor.IBAN;
                        }
                        if (doctor.BICCode != null)
                        {
                            doctorPracticeM.bic = doctor.BICCode;
                        }
                    }

                    var docContracts = cls_Get_Doctor_Contract_Numbers.Invoke(Connection, Transaction, new P_DO_CDCD_1505()
                    {
                        DoctorID = doctor.Id
                    }, securityTicket).Result;
                    doctorPracticeM.contract = docContracts.Count();
                    LdoctorPracticeM.Add(doctorPracticeM);
                }
            }
            //first delete Tenant index
            try
            {
                Add_Practice_Doctors_to_Elastic.Delete_index_on_Elastic(securityTicket.TenantID.ToString());
                //  Add_Practice_Doctors_to_Elastic.Delete_index_on_Elastic(securityTicket.TenantID.ToString() + "/" + "user");
                Console.Write("Type Doctors_Practices deleted");
            }
            catch
            {
                Console.Write("Type Doctors_Practices do not exsists");
            }

            //import items to Elastic
            if (dataDoc != null | dataPractice != null)
            {
                Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(LdoctorPracticeM, securityTicket.TenantID.ToString());
            }
            #endregion


            #region add Patients to Elastic
            var dataPatients = cls_Get_All_Patients_from_DB.Invoke(Connection, Transaction, securityTicket).Result;



            if (dataPatients != null)
            {
                try
                {
                    //     Add_Practice_Doctors_to_Elastic.Delete_index_on_Elastic(securityTicket.TenantID.ToString() + "/" + "patient");
                    Console.Write("Type Patients deleted");
                }
                catch
                {
                    Console.Write("Type Patients do not exsists");
                }

                foreach (var patient in dataPatients)
                {
                    Patient_Model   patientModel = new Patient_Model();
                    var             HIPLIst      = cls_Get_All_HIPs.Invoke(Connection, Transaction, securityTicket).Result.ToList();
                    string          HIP          = HIPLIst.Where(i => i.id == patient.HIPID).Single().name;
                    IFormatProvider culture      = new System.Globalization.CultureInfo("de", true);
                    patientModel.birthday                  = DateTime.Parse(patient.BirthDate.ToString("dd.MM.yyyy"), culture, System.Globalization.DateTimeStyles.AssumeLocal);
                    patientModel.birthday_string           = patient.BirthDate.ToString("dd.MM.yyyy");
                    patientModel.name                      = patient.LastName + ", " + patient.FirstName;
                    patientModel.health_insurance_provider = HIP;
                    patientModel.name_with_birthdate       = patient.FirstName + " " + patient.LastName + " (" + patient.BirthDate.ToString("dd.MM.yyyy") + ")";
                    patientModel.id               = patient.Id.ToString();
                    patientModel.insurance_id     = patient.HipNumber;
                    patientModel.insurance_status = patient.InsuranceStatus;
                    patientModel.practice_id      = patient.PracticeID.ToString();

                    if (patient.Gender == 0)
                    {
                        patientModel.sex = "M";
                    }
                    else if (patient.Gender == 1)
                    {
                        patientModel.sex = "W";
                    }
                    else if (patient.Gender == 2)
                    {
                        patientModel.sex = "o.A.";
                    }

                    //Add patient participation consent
                    if (patient.ValidFrom != DateTime.MinValue)
                    {
                        patientModel.participation_consent_from = patient.ValidFrom;
                        patientModel.has_participation_consent  = true;
                    }

                    if (patient.ValidThrough != DateTime.MinValue)
                    {
                        patientModel.participation_consent_to = patient.ValidThrough;
                    }

                    Add_New_Patient.Import_Patients_to_ElasticDB(patientModel, securityTicket.TenantID.ToString());
                }

                Console.Write("Patients imported to elastic");
            }

            #endregion

            #region Add Cases to Elastic
            List <Case_Model>  cases       = new List <Case_Model>();
            List <Order_Model> OrderModelL = new List <Order_Model>();
            var dataCases = cls_Get_All_Cases_from_DB.Invoke(Connection, Transaction, securityTicket).Result;
            if (dataCases != null)
            {
                foreach (var Case in dataCases)
                {
                    if (Case.case_status == null)
                    {
                        var diagnose_details = cls_Get_Diagnose_Details_for_DiagnoseID.Invoke(Connection, Transaction, new P_CAS_GDDfDID_1357()
                        {
                            DiagnoseID = Case.diagnose_id
                        }, securityTicket).Result;
                        var drug_details = cls_Get_Drug_Details_for_DrugID.Invoke(Connection, Transaction, new P_CAS_GDDfDID_1614()
                        {
                            DrugID = Case.drug_id
                        }, securityTicket).Result;

                        Case_Model case_model_elastic = new Case_Model();
                        case_model_elastic.diagnose          = diagnose_details != null ? diagnose_details.diagnose_name + " (" + diagnose_details.catalog_display_name + ": " + diagnose_details.diagnose_icd_10 + ")" : "";
                        case_model_elastic.drug              = drug_details != null ? drug_details.drug_name : "";
                        case_model_elastic.id                = Case.case_id.ToString();
                        case_model_elastic.localization      = Case.localization;
                        case_model_elastic.status_drug_order = Case.order_id != Guid.Empty ? "MO1" : "";

                        case_model_elastic.status_treatment         = Case.diagnose_id != Guid.Empty ? "OP1" : "";
                        case_model_elastic.patient_name             = Case.patient_id != Guid.Empty ? Case.Patient_LastName + ", " + Case.Patient_FirstName : "";
                        case_model_elastic.patient_birthdate_string = Case.Patient_BirthDate.ToString("dd.MM.yyyy");
                        case_model_elastic.patient_birthdate        = Case.Patient_BirthDate;
                        if (Case.is_aftercare_practice)
                        {
                            case_model_elastic.aftercare_name = Case.aftercare_practice_display_name;
                        }
                        else if (Case.is_aftercare_doctor)
                        {
                            case_model_elastic.aftercare_name = Case.aftercare_doctor_display_name;
                        }
                        else
                        {
                            case_model_elastic.aftercare_name = "-";
                        }
                        var aftercare_doctor_details = cls_Get_Doctor_Details_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDDfDID_0823()
                        {
                            DoctorID = Case.ac_doctor_id
                        }, securityTicket).Result.SingleOrDefault();

                        if (aftercare_doctor_details != null)
                        {
                            case_model_elastic.aftercare_name = aftercare_doctor_details.title + " " + aftercare_doctor_details.last_name + " " + aftercare_doctor_details.first_name;
                            case_model_elastic.aftercare_doctors_practice_name = aftercare_doctor_details.practice;
                        }


                        case_model_elastic.is_aftercare_doctor       = Case.is_aftercare_doctor;
                        case_model_elastic.treatment_date_day_month  = Case.treatment_date.ToString("dd.MM.");
                        case_model_elastic.treatment_date_month_year = Case.treatment_date.ToString("MMMM yyyy", new System.Globalization.CultureInfo("de", true));
                        var treatment_doctor_details = cls_Get_Doctor_Details_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDDfDID_0823()
                        {
                            DoctorID = Case.treatment_doctor_id
                        }, securityTicket).Result.SingleOrDefault();
                        case_model_elastic.treatment_doctor_name = treatment_doctor_details != null ? treatment_doctor_details.title + " " + treatment_doctor_details.last_name + " " + treatment_doctor_details.first_name : "-";
                        case_model_elastic.practice_id           = Case.practice_id.ToString();

                        case_model_elastic.order_modification_timestamp        = Case.order_modification_timestamp;
                        case_model_elastic.order_modification_timestamp_string = Case.order_modification_timestamp.ToString("dd.MM.yyyy");
                        case_model_elastic.delivery_time_from   = Case.order_id != Guid.Empty ? Case.alternative_delivery_date_from : Case.treatment_date;
                        case_model_elastic.delivery_time_to     = Case.order_id != Guid.Empty ? Case.alternative_delivery_date_to : Case.treatment_date.AddHours(23).AddMinutes(59);
                        case_model_elastic.delivery_time_string = case_model_elastic.delivery_time_from.ToString("HH:mm") + " - " + case_model_elastic.delivery_time_to.ToString("HH:mm");


                        Order_Model orderM = new Order_Model();

                        if (Case.order_id != Guid.Empty)
                        {
                            case_model_elastic.is_orders_drug = true;
                            OR_GOSfCID_0858[] OrderCtatusList = cls_Get_Order_Status_for_CaseID.Invoke(Connection, Transaction, new P_OR_GOSfCID_0858()
                            {
                                CaseID = Case.case_id
                            }, securityTicket).Result;
                            OrderCtatusList = OrderCtatusList.OrderBy(tmp => tmp.StatusCreated).Reverse().ToArray();
                            case_model_elastic.status_drug_order = OrderCtatusList.Count() > 0 ? "MO" + OrderCtatusList.First().StatusCode : "MO1";
                            if (OrderCtatusList.Count() > 1)
                            {
                                case_model_elastic.previous_status_drug_order = "MO" + OrderCtatusList[1].StatusCode;
                            }
                            else
                            {
                                case_model_elastic.previous_status_drug_order = "MO1";
                            }
                            orderM.status_drug_order = OrderCtatusList.Count() > 0 ? "MO" + OrderCtatusList.First().StatusCode : "MO1";
                        }
                        else
                        {
                            case_model_elastic.is_orders_drug = false;
                        }
                        cases.Add(case_model_elastic);

                        if (Case.order_id != Guid.Empty)
                        {
                            orderM.case_id = case_model_elastic.id;
                            orderM.id      = Case.OrderHeaderID.ToString();

                            orderM.delivery_time_from                  = Case.alternative_delivery_date_from != null ? Case.alternative_delivery_date_from : Case.treatment_date;
                            orderM.delivery_time_to                    = Case.alternative_delivery_date_from != null ? Case.alternative_delivery_date_to : Case.treatment_date.AddHours(23).AddMinutes(59);
                            orderM.delivery_time_string                = case_model_elastic.delivery_time_from.ToString("HH:mm") + " - " + case_model_elastic.delivery_time_to.ToString("HH:mm");
                            orderM.practice_id                         = Case.practice_id.ToString();
                            orderM.order_modification_timestamp        = DateTime.Now;
                            orderM.order_modification_timestamp_string = DateTime.Now.ToString("dd.MM.yyyy");
                            orderM.is_orders_drug                      = true;
                            orderM.treatment_date                      = Case.treatment_date;
                            orderM.treatment_date_day_month            = Case.treatment_date.ToString("dd.MM.");
                            orderM.treatment_date_month_year           = Case.treatment_date.ToString("MMMM yyyy", new System.Globalization.CultureInfo("de", true));
                            orderM.treatment_doctor_name               = treatment_doctor_details != null ? treatment_doctor_details.title + " " + treatment_doctor_details.last_name + " " + treatment_doctor_details.first_name : "-";
                            orderM.treatment_doctor_practice_name      = treatment_doctor_details != null ? treatment_doctor_details.practice : "-";
                            orderM.localization                        = Case.diagnose_id != Guid.Empty ? Case.localization : "-";
                            orderM.diagnose                 = diagnose_details != null ? diagnose_details.diagnose_name + " (" + diagnose_details.catalog_display_name + ": " + diagnose_details.diagnose_icd_10 + ")" : "-";
                            orderM.drug                     = drug_details != null ? drug_details.drug_name : "";
                            orderM.patient_name             = Case.patient_id != Guid.Empty ? Case.Patient_LastName + ", " + Case.Patient_FirstName : "";
                            orderM.patient_birthdate_string = Case.Patient_BirthDate.ToString("dd.MM.yyyy");
                            orderM.patient_birthdate        = Case.Patient_BirthDate;


                            OrderModelL.Add(orderM);
                        }
                    }
                }
                try
                {
                    Add_Practice_Doctors_to_Elastic.Delete_index_on_Elastic(securityTicket.TenantID.ToString() + "/" + "case");

                    Console.Write("Type Case deleted");
                }
                catch
                {
                    Console.Write("Type do not exsists");
                }
                Add_New_Case.Import_Case_Data_to_ElasticDB(cases, securityTicket.TenantID.ToString());
                Add_New_Order.Import_Order_Data_to_ElasticDB(OrderModelL, securityTicket.TenantID.ToString());
                Console.Write("Cases and Orders imported to Elastic");
            }
            #endregion
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
        public static void Save_practices_to_DB(Practice_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");

                var  returnValue           = new FR_Guid();
                Guid companyInfoID         = Guid.NewGuid();
                Guid BusinessParticipantID = Guid.NewGuid();
                Guid PracticeAddressID     = Guid.NewGuid();
                Guid practice_id           = Guid.NewGuid();

                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 practiceAccountInfo = 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 functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                        functionLevelRightQ.IsDeleted                = false;
                        functionLevelRightQ.GlobalPropertyMatchingID = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice";

                        var existingunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault();

                        Guid tempFunctionLevelRightID = Guid.Empty;

                        if (existingunctionLevelRight == 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 = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice";
                            functionLevelRight.GlobalPropertyMatchingID = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice";

                            functionLevelRight.Save(Connection, Transaction);

                            tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                        }
                        else
                        {
                            tempFunctionLevelRightID = existingunctionLevelRight.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            = practiceAccountInfo.USR_AccountID;
                        accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID; // USR_Account_FunctionLevelRightID
                        accountToFunctionLevelRight.Save(Connection, Transaction);

                        var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

                        businessParticipantQ.IsDeleted    = false;
                        businessParticipantQ.Tenant_RefID = securityTicket.TenantID;
                        businessParticipantQ.CMN_BPT_BusinessParticipantID = practiceAccountInfo.BusinessParticipant_RefID;
                        BusinessParticipantID = practiceAccountInfo.BusinessParticipant_RefID;

                        var practiceinfoinBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();

                        practiceinfoinBusinessParticipant.DisplayName            = Parameter.PracticeName;
                        practiceinfoinBusinessParticipant.IsCompany              = true;
                        practiceinfoinBusinessParticipant.Modification_Timestamp = DateTime.Now;
                        practiceinfoinBusinessParticipant.Save(Connection, Transaction);
                        companyInfoID = practiceinfoinBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                        var companyInfo = new ORM_CMN_COM_CompanyInfo.Query();

                        companyInfo.IsDeleted             = false;
                        companyInfo.Tenant_RefID          = securityTicket.TenantID;
                        companyInfo.CMN_COM_CompanyInfoID = companyInfoID;

                        var companyInfoPractice = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfo).Single();
                        companyInfoPractice.CompanyInfo_EstablishmentNumber = Parameter.BSNR;
                        companyInfoPractice.Save(Connection, Transaction);

                        var companyInfoAddressPractice = new ORM_CMN_COM_CompanyInfo_Address();
                        companyInfoAddressPractice.CompanyInfo_RefID   = companyInfoID;
                        companyInfoAddressPractice.IsDefault           = true;
                        companyInfoAddressPractice.IsShipping          = true;
                        companyInfoAddressPractice.IsBilling           = true;
                        companyInfoAddressPractice.Tenant_RefID        = securityTicket.TenantID;
                        companyInfoAddressPractice.Address_UCD_RefID   = Guid.NewGuid();
                        companyInfoAddressPractice.Address_Description = "Standard address for billing, shipping";
                        companyInfoAddressPractice.Save(Connection, Transaction);
                        PracticeAddressID = companyInfoAddressPractice.Address_UCD_RefID;

                        var universlContactPractice = new ORM_CMN_UniversalContactDetail();
                        universlContactPractice.IsDeleted    = false;
                        universlContactPractice.Tenant_RefID = securityTicket.TenantID;
                        universlContactPractice.CMN_UniversalContactDetailID = PracticeAddressID;
                        universlContactPractice.CompanyName_Line1            = Parameter.PracticeName;
                        universlContactPractice.IsCompany              = true;
                        universlContactPractice.Street_Name            = Parameter.Street;
                        universlContactPractice.Street_Number          = Parameter.No;
                        universlContactPractice.ZIP                    = Parameter.Zip;
                        universlContactPractice.Town                   = Parameter.City;
                        universlContactPractice.Contact_Email          = Parameter.MainEmail;
                        universlContactPractice.Contact_Telephone      = Parameter.MainPhone;
                        universlContactPractice.Contact_Fax            = Parameter.Fax;
                        universlContactPractice.Creation_Timestamp     = DateTime.Now;
                        universlContactPractice.Modification_Timestamp = DateTime.Now;
                        universlContactPractice.Save(Connection, Transaction);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Exception occured durng data retrieval in method cls_Save_Practice", ex);
                        //Log the error (uncomment dex variable name and add a line here to write a log.
                    }
                }
                //  else{
                var companyInfoAddress2 = new ORM_CMN_COM_CompanyInfo_Address();
                companyInfoAddress2.IsDeleted           = false;
                companyInfoAddress2.Tenant_RefID        = securityTicket.TenantID;
                companyInfoAddress2.CompanyInfo_RefID   = companyInfoID;
                companyInfoAddress2.IsDefault           = true;
                companyInfoAddress2.IsContact           = true;
                companyInfoAddress2.Address_UCD_RefID   = Guid.NewGuid();
                companyInfoAddress2.Address_Description = "Standard contact person data";
                companyInfoAddress2.Creation_Timestamp  = DateTime.Now;
                companyInfoAddress2.Save(Connection, Transaction);

                string personInfo      = Parameter.ContactPerson;
                string PersonFirstName = "";
                string PersonLastName  = "";
                int    i = personInfo.IndexOf(' ');
                if (i > 1)
                {
                    PersonFirstName = personInfo.Substring(0, i);
                    PersonLastName  = personInfo.Substring(i + 1);
                }
                else
                {
                    PersonFirstName = Parameter.ContactPerson;
                    PersonLastName  = " ";
                }

                var universlContactPractice2 = new ORM_CMN_UniversalContactDetail();
                universlContactPractice2.CMN_UniversalContactDetailID = companyInfoAddress2.Address_UCD_RefID;
                universlContactPractice2.IsDeleted              = false;
                universlContactPractice2.Tenant_RefID           = securityTicket.TenantID;
                universlContactPractice2.IsCompany              = false;
                universlContactPractice2.First_Name             = PersonFirstName;
                universlContactPractice2.Last_Name              = PersonLastName;
                universlContactPractice2.Contact_Email          = Parameter.Email;
                universlContactPractice2.Contact_Telephone      = Parameter.Phone;
                universlContactPractice2.Creation_Timestamp     = DateTime.Now;
                universlContactPractice2.Modification_Timestamp = DateTime.Now;
                universlContactPractice2.Save(Connection, Transaction);

                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 bankAccountPractice = new ORM_ACC_BNK_BankAccount();
                bankAccountPractice.IsDeleted             = false;
                bankAccountPractice.Tenant_RefID          = securityTicket.TenantID;
                bankAccountPractice.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                bankAccountPractice.OwnerText             = Parameter.AccountHolder;
                bankAccountPractice.IBAN               = Parameter.IBAN;
                bankAccountPractice.Bank_RefID         = Guid.NewGuid();
                bankAccountPractice.Creation_Timestamp = DateTime.Now;
                bankAccountPractice.Save(Connection, Transaction);

                var bank = new ORM_ACC_BNK_Bank();
                bank.IsDeleted          = false;
                bank.Tenant_RefID       = securityTicket.TenantID;
                bank.ACC_BNK_BankID     = bankAccountPractice.Bank_RefID;
                bank.BICCode            = Parameter.Bic;
                bank.BankName           = Parameter.Bank;
                bank.Creation_Timestamp = DateTime.Now;
                bank.Save(Connection, Transaction);

                var customer = new ORM_CMN_BPT_CTM_Customer();
                customer.IsDeleted    = false;
                customer.Tenant_RefID = securityTicket.TenantID;
                customer.Ext_BusinessParticipant_RefID = BusinessParticipantID;
                customer.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                customer.Creation_Timestamp            = DateTime.Now;
                customer.Save(Connection, Transaction);

                var organizationalUnit = new ORM_CMN_BPT_CTM_OrganizationalUnit();
                organizationalUnit.IsDeleted         = false;
                organizationalUnit.Tenant_RefID      = securityTicket.TenantID;
                organizationalUnit.Customer_RefID    = customer.CMN_BPT_CTM_CustomerID;
                organizationalUnit.IsMedicalPractice = true;
                organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID = Guid.NewGuid();
                organizationalUnit.Creation_Timestamp     = DateTime.Now;
                organizationalUnit.Modification_Timestamp = DateTime.Now;
                organizationalUnit.Save(Connection, Transaction);

                var medicalPractice = new ORM_HEC_MedicalPractis();

                medicalPractice.IsDeleted              = false;
                medicalPractice.Tenant_RefID           = securityTicket.TenantID;
                medicalPractice.HEC_MedicalPractiseID  = organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID;
                medicalPractice.Creation_Timestamp     = DateTime.Now;
                medicalPractice.Modification_Timestamp = DateTime.Now;
                medicalPractice.Save(Connection, Transaction);

                practice_id = medicalPractice.HEC_MedicalPractiseID;

                var medicalPRactice2Universal = new ORM_HEC_MedicalPractice_2_UniversalProperty();

                medicalPRactice2Universal.IsDeleted    = false;
                medicalPRactice2Universal.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal.Value_Boolean          = Parameter.IsSurgeryPractice;
                medicalPRactice2Universal.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal.Save(Connection, Transaction);

                var practiceUniversal = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal.IsDeleted    = false;
                practiceUniversal.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal.PropertyName           = "Surgery Practice";
                practiceUniversal.IsValue_Boolean        = true;
                practiceUniversal.Creation_Timestamp     = DateTime.Now;
                practiceUniversal.Modification_Timestamp = DateTime.Now;
                practiceUniversal.Save(Connection, Transaction);


                var medicalPRactice2Universal2 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal2.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal2.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal2.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal2.Value_Boolean          = Parameter.IsOrderDrugs;
                medicalPRactice2Universal2.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal2.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal2.Save(Connection, Transaction);

                var practiceUniversal2 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal2.IsDeleted    = false;
                practiceUniversal2.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal2.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal2.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal2.PropertyName           = "Order Drugs";
                practiceUniversal2.IsValue_Boolean        = true;
                practiceUniversal2.Creation_Timestamp     = DateTime.Now;
                practiceUniversal2.Modification_Timestamp = DateTime.Now;
                practiceUniversal2.Save(Connection, Transaction);


                // default shipping date offset

                var medicalPRactice2Universal3 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal3.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal3.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal3.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal3.Value_Number           = double.Parse(Parameter.DefaultShippingDateOffset);
                medicalPRactice2Universal3.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal3.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal3.Save(Connection, Transaction);

                var practiceUniversal3 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal3.IsDeleted    = false;
                practiceUniversal3.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal3.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal3.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal3.PropertyName           = "Default Shipping Date Offset";
                practiceUniversal3.IsValue_Number         = true;
                practiceUniversal3.Creation_Timestamp     = DateTime.Now;
                practiceUniversal3.Modification_Timestamp = DateTime.Now;
                practiceUniversal3.Save(Connection, Transaction);

                var medicalPRactice2Universal4 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal4.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal4.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal4.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal4.Value_Boolean          = Parameter.IsOnlyLabelRequired;
                medicalPRactice2Universal4.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal4.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal4.Save(Connection, Transaction);

                var practiceUniversal4 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal4.IsDeleted    = false;
                practiceUniversal4.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal4.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal4.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal4.PropertyName           = "Only Label Required";
                practiceUniversal4.IsValue_Boolean        = true;
                practiceUniversal4.Creation_Timestamp     = DateTime.Now;
                practiceUniversal4.Modification_Timestamp = DateTime.Now;
                practiceUniversal4.Save(Connection, Transaction);

                var medicalPRactice2Universal5 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal5.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal5.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal5.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal5.Value_Boolean          = Parameter.isWaiveServiceFee;
                medicalPRactice2Universal5.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal5.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal5.Save(Connection, Transaction);

                var practiceUniversal5 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal5.IsDeleted    = false;
                practiceUniversal5.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal5.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal5.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal5.PropertyName           = "Waive Service Fee";
                practiceUniversal5.IsValue_Boolean        = true;
                practiceUniversal5.Creation_Timestamp     = DateTime.Now;
                practiceUniversal5.Modification_Timestamp = DateTime.Now;
                practiceUniversal5.Save(Connection, Transaction);

                //   }



                Practice_Doctors_Model DPModel = new Practice_Doctors_Model();
                DPModel.account_status    = "aktiv";
                DPModel.id                = practice_id.ToString();
                DPModel.name              = Parameter.PracticeName;
                DPModel.name_untouched    = Parameter.PracticeName;
                DPModel.salutation        = "";
                DPModel.type              = "Practice";
                DPModel.autocomplete_name = Parameter.PracticeName;
                DPModel.address           = Parameter.Street + " " + Parameter.No;
                DPModel.zip               = Parameter.Zip;
                DPModel.city              = Parameter.City;


                DPModel.bank_untouched = Parameter.Bank != null ? Parameter.Bank : "";
                DPModel.bank           = Parameter.Bank != null ? Parameter.Bank : "";

                if (Parameter.Email != null)
                {
                    DPModel.email = Parameter.MainEmail;
                }

                DPModel.phone = Parameter.MainPhone;
                if (Parameter.IBAN != null)
                {
                    DPModel.iban = Parameter.IBAN;
                }
                if (Parameter.Bic != null)
                {
                    DPModel.bic = Parameter.Bic;
                }

                DPModel.bsnr_lanr      = Parameter.BSNR;
                DPModel.aditional_info = "";
                DPModel.contract       = 0;
                DPModel.tenantid       = securityTicket.TenantID.ToString();
                DPModel.role           = Parameter.IsSurgeryPractice ? "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());


                //Commit the transaction
                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;
            }
        }