Esempio n. 1
0
        public static void Save_Patients_to_DB(Patient_Model_xls Parameter, bool create_consents, string connectionString, SessionSecurityTicket securityTicket)
        {
            DbConnection  Connection         = null;
            DbTransaction Transaction        = null;
            bool          cleanupConnection  = Connection == null;
            bool          cleanupTransaction = Transaction == null;
            Guid          patient_id         = Guid.NewGuid();

            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");

                ORM_HEC_Patient patients = new ORM_HEC_Patient();
                patients.HEC_PatientID                     = Guid.NewGuid();
                patients.Tenant_RefID                      = securityTicket.TenantID;
                patients.Creation_Timestamp                = DateTime.Now;
                patients.Modification_Timestamp            = DateTime.Now;
                patients.CMN_BPT_BusinessParticipant_RefID = Guid.NewGuid();
                patients.Save(Connection, Transaction);
                patient_id = patients.HEC_PatientID;

                ORM_CMN_BPT_BusinessParticipant businesParticipantPatient = new ORM_CMN_BPT_BusinessParticipant();
                businesParticipantPatient.CMN_BPT_BusinessParticipantID = patients.CMN_BPT_BusinessParticipant_RefID;
                businesParticipantPatient.Tenant_RefID           = securityTicket.TenantID;
                businesParticipantPatient.Creation_Timestamp     = DateTime.Now;
                businesParticipantPatient.Modification_Timestamp = DateTime.Now;
                businesParticipantPatient.IsNaturalPerson        = true;
                businesParticipantPatient.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                businesParticipantPatient.Save(Connection, Transaction);
                int PatientSex = 0;
                switch (Parameter.sex)
                {
                case "M":
                    PatientSex = 0;
                    break;

                case "W":
                    PatientSex = 1;
                    break;

                case "o.A.":
                    PatientSex = 2;
                    break;
                }

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID   = businesParticipantPatient.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Tenant_RefID           = securityTicket.TenantID;
                personInfo.Creation_Timestamp     = DateTime.Now;
                personInfo.Modification_Timestamp = DateTime.Now;
                personInfo.FirstName = Parameter.name;
                personInfo.LastName  = Parameter.LastName;
                personInfo.BirthDate = Parameter.birthday;
                personInfo.Gender    = PatientSex;
                personInfo.Save(Connection, Transaction);

                ORM_HEC_Patient_MedicalPractice medical_practice_to_patient = new ORM_HEC_Patient_MedicalPractice();
                medical_practice_to_patient.HEC_Patient_MedicalPracticeID = Guid.NewGuid();
                medical_practice_to_patient.HEC_Patient_RefID             = patients.HEC_PatientID;
                medical_practice_to_patient.HEC_MedicalPractices_RefID    = Guid.Parse(Parameter.practice_id);//
                medical_practice_to_patient.Tenant_RefID       = securityTicket.TenantID;
                medical_practice_to_patient.Creation_Timestamp = DateTime.Now;
                medical_practice_to_patient.Save(Connection, Transaction);


                var medicalPracticeQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();
                medicalPracticeQuery.IsDeleted    = false;
                medicalPracticeQuery.Tenant_RefID = securityTicket.TenantID;

                var HIPList = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, medicalPracticeQuery).ToList();

                if (Parameter.isPrivatelyInsured)
                {
                    Parameter.health_insurance_providerNumber = "000000000";
                }

                var GetHip = HIPList.Where(hp => hp.HealthInsurance_IKNumber == Parameter.health_insurance_providerNumber).SingleOrDefault();
                if (GetHip == null)
                {
                    var businessParticipantHIP = new ORM_CMN_BPT_BusinessParticipant();
                    businessParticipantHIP.IsCompany              = true;
                    businessParticipantHIP.Tenant_RefID           = securityTicket.TenantID;
                    businessParticipantHIP.Modification_Timestamp = DateTime.Now;
                    businessParticipantHIP.DisplayName            = Parameter.health_insurance_provider;

                    businessParticipantHIP.Save(Connection, Transaction);

                    GetHip = new ORM_HEC_HIS_HealthInsurance_Company();
                    GetHip.Tenant_RefID = securityTicket.TenantID;
                    GetHip.CMN_BPT_BusinessParticipant_RefID = businessParticipantHIP.CMN_BPT_BusinessParticipantID;
                    GetHip.HealthInsurance_IKNumber          = String.IsNullOrEmpty(Parameter.health_insurance_provider) ? "privat versichert" : Parameter.health_insurance_provider;

                    GetHip.Save(Connection, Transaction);
                }

                ORM_HEC_Patient_HealthInsurance patientHealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                patientHealthInsurance.HEC_Patient_HealthInsurancesID = Guid.NewGuid();
                patientHealthInsurance.Patient_RefID                     = patients.HEC_PatientID;
                patientHealthInsurance.HealthInsurance_Number            = Parameter.insurance_id;     //
                patientHealthInsurance.Tenant_RefID                      = securityTicket.TenantID;
                patientHealthInsurance.InsuranceStateCode                = Parameter.insurance_status; //
                patientHealthInsurance.HIS_HealthInsurance_Company_RefID = GetHip.HEC_HealthInsurance_CompanyID;
                patientHealthInsurance.Save(Connection, Transaction);

                #region import Patient to Elastic
                Patient_Model patientModel = new Patient_Model();


                patientModel.birthday                  = Parameter.birthday;
                patientModel.birthday_string           = Parameter.birthday.ToString("dd.MM.yyyy");
                patientModel.name                      = Parameter.LastName + ", " + Parameter.name;
                patientModel.health_insurance_provider = String.IsNullOrEmpty(Parameter.health_insurance_provider) ? "privat versichert" : Parameter.health_insurance_provider;
                patientModel.name_with_birthdate       = Parameter.name + " " + Parameter.LastName + " (" + Parameter.birthday.ToString("dd.MM.yyyy") + ")";
                patientModel.id               = patients.HEC_PatientID.ToString();
                patientModel.insurance_id     = String.IsNullOrEmpty(Parameter.insurance_id) ? "-" : Parameter.insurance_id;
                patientModel.insurance_status = String.IsNullOrEmpty(Parameter.insurance_status) ? "-" : Parameter.insurance_status;
                patientModel.practice_id      = Parameter.practice_id.ToString();

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

                Add_New_Patient.Import_Patients_to_ElasticDB(patientModel, securityTicket.TenantID.ToString());
                if (create_consents)
                {
                    #region Participation Consent
                    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)
                    {
                        var InsuranceToBrokerContractQuery = new ORM_HEC_CRT_InsuranceToBrokerContract.Query();
                        InsuranceToBrokerContractQuery.Tenant_RefID = securityTicket.TenantID;
                        InsuranceToBrokerContractQuery.IsDeleted    = false;
                        InsuranceToBrokerContractQuery.Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID;

                        ORM_HEC_CRT_InsuranceToBrokerContract InsuranceToBrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, InsuranceToBrokerContractQuery).Single();

                        List <DateTime> TimeFrom = new List <DateTime>();
                        DateTime        time1    = new DateTime(2013, 6, 15);
                        DateTime        time2    = new DateTime(2014, 6, 15);
                        DateTime        time3    = new DateTime(2015, 6, 15);

                        TimeFrom.Add(time1);
                        TimeFrom.Add(time2);
                        TimeFrom.Add(time3);
                        foreach (var date in TimeFrom)
                        {
                            ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient InsuranceToBrokerContract_ParticipatingPatient = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient();
                            InsuranceToBrokerContract_ParticipatingPatient.HEC_CRT_InsuranceToBrokerContract_ParticipatingPatientID = Guid.NewGuid();
                            InsuranceToBrokerContract_ParticipatingPatient.InsuranceToBrokerContract_RefID = InsuranceToBrokerContract.HEC_CRT_InsuranceToBrokerContractID;
                            InsuranceToBrokerContract_ParticipatingPatient.Creation_Timestamp     = DateTime.Now;
                            InsuranceToBrokerContract_ParticipatingPatient.Modification_Timestamp = DateTime.Now;
                            InsuranceToBrokerContract_ParticipatingPatient.Tenant_RefID           = securityTicket.TenantID;
                            InsuranceToBrokerContract_ParticipatingPatient.ValidFrom     = date;
                            InsuranceToBrokerContract_ParticipatingPatient.ValidThrough  = DateTime.MinValue;
                            InsuranceToBrokerContract_ParticipatingPatient.Patient_RefID = patient_id;
                            InsuranceToBrokerContract_ParticipatingPatient.Save(Connection, Transaction);

                            Patient_Model patientModel2 = new Patient_Model();
                            patientModel2 = Retrieve_Patients.Get_Patient_for_PatientID(patient_id.ToString(), securityTicket);

                            var InsuranceToBrokerContract_ParticipatingPatientQuery = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient.Query();
                            InsuranceToBrokerContract_ParticipatingPatientQuery.IsDeleted     = false;
                            InsuranceToBrokerContract_ParticipatingPatientQuery.Tenant_RefID  = securityTicket.TenantID;
                            InsuranceToBrokerContract_ParticipatingPatientQuery.Patient_RefID = patient_id;

                            var allInsuranceToBrokerContract_ParticipatingPatient = ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient.Query.Search(Connection, Transaction, InsuranceToBrokerContract_ParticipatingPatientQuery).ToList();
                            var latest_participation_date = allInsuranceToBrokerContract_ParticipatingPatient.OrderByDescending(m => m.ValidFrom).FirstOrDefault();

                            patientModel2.participation_consent_from = latest_participation_date.ValidFrom;
                            patientModel2.participation_consent_to   = latest_participation_date.ValidThrough;
                            patientModel2.has_participation_consent  = true;

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

                #endregion
                //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;
            }

            #endregion
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_SPHIaBD_1143 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            #region Save
            if (!Parameter.IsDeleted)
            {
                //ORM_HEC_Patient
                var patientQuery = new ORM_HEC_Patient.Query();
                patientQuery.IsDeleted     = false;
                patientQuery.Tenant_RefID  = securityTicket.TenantID;
                patientQuery.HEC_PatientID = Parameter.PatientID;

                var patient = ORM_HEC_Patient.Query.Search(Connection, Transaction, patientQuery).Single();

                var businessParticipantBank_2_accountQuery = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query();
                businessParticipantBank_2_accountQuery.CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID;
                businessParticipantBank_2_accountQuery.IsDeleted    = false;
                businessParticipantBank_2_accountQuery.Tenant_RefID = securityTicket.TenantID;

                var businessParticipantBank_2_account = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, businessParticipantBank_2_accountQuery).SingleOrDefault();

                if (businessParticipantBank_2_account == null)
                {
                    //ORM_CMN_BPT_BusinessParticipant_2_BankAccount
                    businessParticipantBank_2_account = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                    businessParticipantBank_2_account.CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID;
                    businessParticipantBank_2_account.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                    businessParticipantBank_2_account.AssignmentID       = Guid.NewGuid();
                    businessParticipantBank_2_account.Tenant_RefID       = securityTicket.TenantID;
                    businessParticipantBank_2_account.Creation_Timestamp = DateTime.Now;
                    businessParticipantBank_2_account.Save(Connection, Transaction);

                    //ORM_ACC_BNK_BankAccount
                    var bankAccount = new ORM_ACC_BNK_BankAccount();
                    bankAccount.ACC_BNK_BankAccountID = businessParticipantBank_2_account.ACC_BNK_BankAccount_RefID;
                    bankAccount.OwnerText             = Parameter.OwnerText;
                    bankAccount.AccountNumber         = Parameter.AccountNumber;
                    bankAccount.IBAN               = Parameter.IBAN;
                    bankAccount.Bank_RefID         = Guid.NewGuid();
                    bankAccount.Tenant_RefID       = securityTicket.TenantID;
                    bankAccount.Creation_Timestamp = DateTime.Now;
                    bankAccount.Save(Connection, Transaction);

                    //ORM_ACC_BNK_Bank
                    var bank = new ORM_ACC_BNK_Bank();
                    bank.ACC_BNK_BankID     = bankAccount.Bank_RefID;
                    bank.BankName           = Parameter.BankName;
                    bank.BICCode            = Parameter.BICCode;
                    bank.Tenant_RefID       = securityTicket.TenantID;
                    bank.Creation_Timestamp = DateTime.Now;
                    bank.Save(Connection, Transaction);

                    //ORM_HEC_Patient_HealthInsurance
                    var healthInsurance = new ORM_HEC_Patient_HealthInsurance();
                    healthInsurance.HEC_Patient_HealthInsurancesID = Guid.NewGuid();
                    healthInsurance.Patient_RefID                     = Parameter.PatientID;
                    healthInsurance.HealthInsurance_Number            = Parameter.HealthInsurance_Number;
                    healthInsurance.HIS_HealthInsurance_Company_RefID = Parameter.HEC_HealthInsurance_CompanyID;
                    healthInsurance.HealthInsurance_State_RefID       = Parameter.HEC_Patient_HealthInsurance_StateID;
                    healthInsurance.InsuranceValidFrom                = Parameter.InsuranceValidFrom;
                    healthInsurance.InsuranceValidThrough             = Parameter.InsuranceValidThrough;
                    healthInsurance.IsNotSelfInsured                  = Parameter.IsNotSelfInsured;

                    if (healthInsurance.IsNotSelfInsured)
                    {
                        healthInsurance.IsNotSelfInsured_InsuredPersonBirthday = Parameter.IsNotSelfInsured_InsuredPersonBirthday;
                        healthInsurance.IsNotSelfInsured_InsuredPersonName     = Parameter.IsNotSelfInsured_InsuredPersonName;
                    }
                    healthInsurance.Creation_Timestamp = DateTime.Now;
                    healthInsurance.Tenant_RefID       = securityTicket.TenantID;
                    healthInsurance.Save(Connection, Transaction);
                }
                else
                {
                    var bankAccountQuery = new ORM_ACC_BNK_BankAccount.Query();
                    bankAccountQuery.IsDeleted             = false;
                    bankAccountQuery.Tenant_RefID          = securityTicket.TenantID;
                    bankAccountQuery.ACC_BNK_BankAccountID = businessParticipantBank_2_account.ACC_BNK_BankAccount_RefID;

                    var bankAccount = ORM_ACC_BNK_BankAccount.Query.Search(Connection, Transaction, bankAccountQuery).Single();
                    bankAccount.OwnerText     = Parameter.OwnerText;
                    bankAccount.AccountNumber = Parameter.AccountNumber;
                    bankAccount.IBAN          = Parameter.IBAN;
                    bankAccount.Save(Connection, Transaction);

                    var bankQuery = new ORM_ACC_BNK_Bank.Query();
                    bankQuery.ACC_BNK_BankID = bankAccount.Bank_RefID;
                    bankQuery.IsDeleted      = false;
                    bankQuery.Tenant_RefID   = securityTicket.TenantID;

                    var bank = ORM_ACC_BNK_Bank.Query.Search(Connection, Transaction, bankQuery).Single();
                    bank.BankName = Parameter.BankName;
                    bank.BICCode  = Parameter.BICCode;
                    bank.Save(Connection, Transaction);

                    var healthInsuranceQuery = new ORM_HEC_Patient_HealthInsurance.Query();
                    healthInsuranceQuery.Patient_RefID = patient.HEC_PatientID;
                    healthInsuranceQuery.IsDeleted     = false;
                    healthInsuranceQuery.Tenant_RefID  = securityTicket.TenantID;

                    var healthInsurance = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, healthInsuranceQuery).Single();
                    healthInsurance.HealthInsurance_Number            = Parameter.HealthInsurance_Number;
                    healthInsurance.HIS_HealthInsurance_Company_RefID = Parameter.HEC_HealthInsurance_CompanyID;
                    healthInsurance.HealthInsurance_State_RefID       = Parameter.HEC_Patient_HealthInsurance_StateID;
                    healthInsurance.InsuranceValidFrom    = Parameter.InsuranceValidFrom;
                    healthInsurance.InsuranceValidThrough = Parameter.InsuranceValidThrough;
                    healthInsurance.IsNotSelfInsured      = Parameter.IsNotSelfInsured;
                    healthInsurance.IsNotSelfInsured_InsuredPersonBirthday = Parameter.IsNotSelfInsured_InsuredPersonBirthday;
                    healthInsurance.IsNotSelfInsured_InsuredPersonName     = Parameter.IsNotSelfInsured_InsuredPersonName;
                    healthInsurance.Save(Connection, Transaction);
                }
            }
            #endregion
            else
            {
                #region delete

                var patientQuery = new ORM_HEC_Patient.Query();
                patientQuery.IsDeleted     = false;
                patientQuery.Tenant_RefID  = securityTicket.TenantID;
                patientQuery.HEC_PatientID = Parameter.PatientID;

                var patient = ORM_HEC_Patient.Query.Search(Connection, Transaction, patientQuery).Single();
                patient.IsDeleted = true;
                patient.Save(Connection, Transaction);

                var businessParticipantBank_2_accountQuery = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query();
                businessParticipantBank_2_accountQuery.CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID;
                businessParticipantBank_2_accountQuery.IsDeleted    = false;
                businessParticipantBank_2_accountQuery.Tenant_RefID = securityTicket.TenantID;

                var businessParticipantBank_2_account = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, businessParticipantBank_2_accountQuery).Single();
                businessParticipantBank_2_account.IsDeleted = true;
                businessParticipantBank_2_account.Save(Connection, Transaction);

                var bankAccountQuery = new ORM_ACC_BNK_BankAccount.Query();
                bankAccountQuery.IsDeleted             = false;
                bankAccountQuery.Tenant_RefID          = securityTicket.TenantID;
                bankAccountQuery.ACC_BNK_BankAccountID = businessParticipantBank_2_account.ACC_BNK_BankAccount_RefID;

                var bankAccount = ORM_ACC_BNK_BankAccount.Query.Search(Connection, Transaction, bankAccountQuery).Single();
                bankAccount.IsDeleted = true;
                bankAccount.Save(Connection, Transaction);

                var bankQuery = new ORM_ACC_BNK_Bank.Query();
                bankQuery.ACC_BNK_BankID = bankAccount.Bank_RefID;
                bankQuery.IsDeleted      = false;
                bankQuery.Tenant_RefID   = securityTicket.TenantID;

                var bank = ORM_ACC_BNK_Bank.Query.Search(Connection, Transaction, bankQuery).Single();
                bank.IsDeleted = true;
                bank.Save(Connection, Transaction);

                var healthInsuranceQuery = new ORM_HEC_Patient_HealthInsurance.Query();
                healthInsuranceQuery.Patient_RefID = patient.HEC_PatientID;
                healthInsuranceQuery.IsDeleted     = false;
                healthInsuranceQuery.Tenant_RefID  = securityTicket.TenantID;

                var healthInsurance = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, healthInsuranceQuery).Single();
                healthInsurance.IsDeleted = true;
                healthInsurance.Save(Connection, Transaction);

                #endregion
            }

            return(returnValue);

            #endregion UserCode
        }
Esempio n. 3
0
        public static void ImportTestPatients(DbConnection Connection, DbTransaction Transaction, SessionSecurityTicket securityTicket, Guid medical_practice_id)
        {
            List <Patient_Model_xls> patientList        = new List <Patient_Model_xls>();
            List <Patient_Model>     elasticPatientList = new List <Patient_Model>();
            IFormatProvider          culture            = new System.Globalization.CultureInfo("de", true);

            string folder    = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
            string filePath  = Path.Combine(folder, "Excel\\german_names_sheet.xlsx");
            bool   hasHeader = true;

            System.Data.DataTable excelData = ExcelUtils.getDataFromExcelFile(filePath, hasHeader);

            foreach (System.Data.DataRow item in excelData.Rows)
            {
                if (item.ItemArray[0].ToString() == "")
                {
                    break;
                }
                Patient_Model_xls patientModel = new Patient_Model_xls();
                patientModel.name     = item.ItemArray[0].ToString();
                patientModel.LastName = item.ItemArray[1].ToString();
                patientModel.sex      = item.ItemArray[2].ToString();
                patientModel.birthday = DateTime.Parse(item.ItemArray[3].ToString(), culture, System.Globalization.DateTimeStyles.AssumeLocal);
                patientList.Add(patientModel);
            }

            List <string> StateCode_first_Caracter = new List <string>();

            StateCode_first_Caracter.Add("1");
            StateCode_first_Caracter.Add("3");
            StateCode_first_Caracter.Add("5");


            List <string> StateCode_fift_Caracter = new List <string>();

            StateCode_fift_Caracter.Add("1");
            StateCode_fift_Caracter.Add("4");
            StateCode_fift_Caracter.Add("6");
            StateCode_fift_Caracter.Add("7");
            StateCode_fift_Caracter.Add("8");
            StateCode_fift_Caracter.Add("9");
            StateCode_fift_Caracter.Add("D");
            StateCode_fift_Caracter.Add("F");
            StateCode_fift_Caracter.Add("A");
            StateCode_fift_Caracter.Add("C");
            StateCode_fift_Caracter.Add("S");
            StateCode_fift_Caracter.Add("P");
            StateCode_fift_Caracter.Add("E");
            StateCode_fift_Caracter.Add("N");
            StateCode_fift_Caracter.Add("M");
            StateCode_fift_Caracter.Add("X");
            StateCode_fift_Caracter.Add("L");
            StateCode_fift_Caracter.Add("K");

            int status_code_counter = 0;
            int status_fift_counter = 0;
            int counter             = 0;

            var medicalPracticeQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();

            medicalPracticeQuery.IsDeleted    = false;
            medicalPracticeQuery.Tenant_RefID = securityTicket.TenantID;

            var HIPList = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, medicalPracticeQuery).ToList();


            int i = 0;

            foreach (var item in patientList)
            {
                ORM_HEC_Patient patients = new ORM_HEC_Patient();
                patients.HEC_PatientID                     = Guid.NewGuid();
                patients.Tenant_RefID                      = securityTicket.TenantID;
                patients.Creation_Timestamp                = DateTime.Now;
                patients.Modification_Timestamp            = DateTime.Now;
                patients.CMN_BPT_BusinessParticipant_RefID = Guid.NewGuid();
                patients.Save(Connection, Transaction);

                ORM_CMN_BPT_BusinessParticipant businesParticipantPatient = new ORM_CMN_BPT_BusinessParticipant();
                businesParticipantPatient.CMN_BPT_BusinessParticipantID = patients.CMN_BPT_BusinessParticipant_RefID;
                businesParticipantPatient.Tenant_RefID           = securityTicket.TenantID;
                businesParticipantPatient.Creation_Timestamp     = DateTime.Now;
                businesParticipantPatient.Modification_Timestamp = DateTime.Now;
                businesParticipantPatient.IsNaturalPerson        = true;
                businesParticipantPatient.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                businesParticipantPatient.Save(Connection, Transaction);

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID   = businesParticipantPatient.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Tenant_RefID           = securityTicket.TenantID;
                personInfo.Creation_Timestamp     = DateTime.Now;
                personInfo.Modification_Timestamp = DateTime.Now;
                personInfo.FirstName = item.name;           //
                personInfo.LastName  = item.LastName;       //
                personInfo.BirthDate = item.birthday;       //
                personInfo.Gender    = int.Parse(item.sex); //
                personInfo.Save(Connection, Transaction);

                ORM_HEC_Patient_MedicalPractice medical_practice_to_patient = new ORM_HEC_Patient_MedicalPractice();
                medical_practice_to_patient.HEC_Patient_MedicalPracticeID = Guid.NewGuid();
                medical_practice_to_patient.HEC_Patient_RefID             = patients.HEC_PatientID;
                medical_practice_to_patient.HEC_MedicalPractices_RefID    = medical_practice_id;//
                medical_practice_to_patient.Tenant_RefID       = securityTicket.TenantID;
                medical_practice_to_patient.Creation_Timestamp = DateTime.Now;
                medical_practice_to_patient.Save(Connection, Transaction);


                ORM_HEC_Patient_HealthInsurance patientHealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                patientHealthInsurance.HEC_Patient_HealthInsurancesID = Guid.NewGuid();
                patientHealthInsurance.Patient_RefID = patients.HEC_PatientID;

                Random rnd = new Random();
                int    random_insurance_number = rnd.Next(10000000, 99999999);

                int genre = 0;
                switch (int.Parse(item.sex))
                {
                case 0:
                    genre = 2;
                    break;

                case 1:
                    genre = 1;
                    break;

                case 2:
                    genre = 0;
                    break;
                }

                var birth = item.birthday.Year.ToString().Substring(2);
                patientHealthInsurance.HealthInsurance_Number            = random_insurance_number.ToString();                                                                                      //
                patientHealthInsurance.Tenant_RefID                      = securityTicket.TenantID;
                patientHealthInsurance.InsuranceStateCode                = StateCode_first_Caracter[status_code_counter] + genre.ToString() + birth + StateCode_fift_Caracter[status_fift_counter]; //
                patientHealthInsurance.HIS_HealthInsurance_Company_RefID = HIPList[i].HEC_HealthInsurance_CompanyID;
                patientHealthInsurance.Save(Connection, Transaction);


                if (status_code_counter == 2)
                {
                    status_code_counter = 0;
                }
                else
                {
                    status_code_counter++;
                }

                if (status_fift_counter == 17)
                {
                    status_fift_counter = 0;
                }
                else
                {
                    status_fift_counter++;
                }

                if (i == HIPList.Count - 1)
                {
                    i = 0;
                }
                else
                {
                    i++;
                }


                var businesParticipantHIPQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                businesParticipantHIPQuery.IsDeleted    = false;
                businesParticipantHIPQuery.Tenant_RefID = securityTicket.TenantID;
                businesParticipantHIPQuery.CMN_BPT_BusinessParticipantID = HIPList[i].CMN_BPT_BusinessParticipant_RefID;

                var businesParticipantHIP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businesParticipantHIPQuery).Single();;

                Patient_Model patientModel = new Patient_Model();


                patientModel.birthday                  = DateTime.Parse(item.birthday.ToString("dd.MM.yyyy"), culture, System.Globalization.DateTimeStyles.AssumeLocal);
                patientModel.birthday_string           = item.birthday.ToString("dd.MM.yyyy");
                patientModel.name                      = item.LastName + ", " + item.name;
                patientModel.health_insurance_provider = businesParticipantHIP.DisplayName;
                patientModel.name_with_birthdate       = item.name + " " + item.LastName + " (" + item.birthday.ToString("dd.MM.yyyy") + ")";
                patientModel.id               = patients.HEC_PatientID.ToString();
                patientModel.insurance_id     = patientHealthInsurance.HealthInsurance_Number;
                patientModel.insurance_status = patientHealthInsurance.InsuranceStateCode;
                patientModel.practice_id      = medical_practice_id.ToString();

                if (int.Parse(item.sex) == 0)
                {
                    patientModel.sex = "M";
                }
                else if (int.Parse(item.sex) == 1)
                {
                    patientModel.sex = "W";
                }
                else if (int.Parse(item.sex) == 2)
                {
                    patientModel.sex = "o.A.";
                }


                elasticPatientList.Add(patientModel);



                counter++;
                Console.WriteLine(counter + "________________________" + patientList.Count);
            }



            string indexElastic = securityTicket.TenantID.ToString();
            var    serializer   = new JsonNetSerializer();
            var    connection   = Elastic_Utils.ElsaticConnection();

            bool checkIndex = Elastic_Utils.IfIndexOrTypeExists(indexElastic, connection);


            if (!checkIndex)
            {
                string settings = Elastic_Utils.BuildIndexSettings();
                connection.Put(indexElastic, settings);

                string jsonProductMapping   = Add_New_Patient.BuildPatientMapping();
                string resultProductMapping = connection.Put(new PutMappingCommand(indexElastic, "patient"), jsonProductMapping);
            }

            bool checkTupe = Elastic_Utils.IfIndexOrTypeExists(indexElastic + "/patient", connection);

            if (!checkTupe)
            {
                string jsonProductMapping   = Add_New_Patient.BuildPatientMapping();
                string resultProductMapping = connection.Put(new PutMappingCommand(indexElastic, "patient"), jsonProductMapping);
            }
            Elastic_Utils.BulkType_Generic <Patient_Model>(elasticPatientList, connection, serializer, indexElastic, "patient");
        }
Esempio n. 4
0
        protected static FR_L5PA_SP__1607 Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_SP__1607 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5PA_SP__1607();
            returnValue.Result = new L5PA_SP__1607();

            ORM_HEC_Patient item = new ORM_HEC_Patient();

            bool isOK = true;
            #region Save

            if (Parameter.IsEdit == false)
            {
                P_L5PA_CIPEIP_1213 healthInsuranceParam = new P_L5PA_CIPEIP_1213();
                healthInsuranceParam.PracticeID            = Parameter.PracticeID;
                healthInsuranceParam.HealthInsuranceNumber = Parameter.HealthInsuranceNumber;

                var hInsurance = cls_CheckIfPatientExistsInPractice.Invoke(Connection, Transaction, healthInsuranceParam, securityTicket).Result;

                //var healtInsuranceQuery = new ORM_HEC_Patient_HealthInsurance.Query();
                //healtInsuranceQuery.HealthInsurance_Number = Parameter.HealthInsuranceNumber;
                //healtInsuranceQuery.Tenant_RefID = securityTicket.TenantID;
                //healtInsuranceQuery.IsDeleted = false;

                //var hInsurance = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, healtInsuranceQuery).FirstOrDefault();

                if (hInsurance.numberofID == 0)
                {
                    Guid patientID = Parameter.PatientID;
                    Guid CMN_BPT_BusinessParticipantID = Guid.NewGuid();

                    item.HEC_PatientID = patientID;
                    item.CMN_BPT_BusinessParticipant_RefID = CMN_BPT_BusinessParticipantID;
                    item.Tenant_RefID = securityTicket.TenantID;


                    item.Save(Connection, Transaction);



                    #region save CMN_BPT_BusinessParticipant

                    ORM_CMN_BPT_BusinessParticipant bussinessParticipant = new ORM_CMN_BPT_BusinessParticipant();

                    bussinessParticipant.CMN_BPT_BusinessParticipantID = CMN_BPT_BusinessParticipantID;
                    bussinessParticipant.DisplayName     = Parameter.Name + Parameter.LastName;
                    bussinessParticipant.IsNaturalPerson = true;
                    bussinessParticipant.IsCompany       = false;
                    Guid NaturalPerson_CMN_PER_PersonInfoID = Guid.NewGuid();
                    bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = NaturalPerson_CMN_PER_PersonInfoID;
                    bussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID      = Guid.Empty;
                    bussinessParticipant.IsTenant = false;
                    bussinessParticipant.IfTenant_Tenant_RefID = Guid.Empty;
                    bussinessParticipant.Tenant_RefID          = securityTicket.TenantID;

                    bussinessParticipant.Save(Connection, Transaction);

                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();

                    personInfo.CMN_PER_PersonInfoID = NaturalPerson_CMN_PER_PersonInfoID;
                    personInfo.FirstName            = Parameter.Name;
                    personInfo.LastName             = Parameter.LastName;
                    personInfo.BirthDate            = Parameter.Birthdate;
                    personInfo.Gender = Parameter.Gender;
                    personInfo.ProfileImage_Document_RefID = Guid.Empty;
                    personInfo.Modification_Timestamp      = DateTime.Now;
                    personInfo.Tenant_RefID = securityTicket.TenantID;

                    personInfo.Save(Connection, Transaction);

                    ORM_HEC_Patient_MedicalPractice medicalPractice = new ORM_HEC_Patient_MedicalPractice();

                    medicalPractice.HEC_Patient_MedicalPracticeID = Guid.NewGuid();
                    medicalPractice.HEC_Patient_RefID             = patientID;
                    medicalPractice.HEC_MedicalPractices_RefID    = Parameter.PracticeID;
                    medicalPractice.Tenant_RefID = securityTicket.TenantID;

                    medicalPractice.Save(Connection, Transaction);

                    ORM_HEC_Patient_HealthInsurance healtInsurance = new ORM_HEC_Patient_HealthInsurance();

                    healtInsurance.HEC_Patient_HealthInsurancesID = Guid.NewGuid();
                    healtInsurance.HealthInsurance_Number         = Parameter.HealthInsuranceNumber;
                    healtInsurance.Patient_RefID = patientID;
                    healtInsurance.HealthInsurance_State_RefID = Guid.Empty;
                    healtInsurance.InsuranceStateCode          = Parameter.InsuranceStateCode;
                    healtInsurance.Tenant_RefID = securityTicket.TenantID;
                    //TODO
                    healtInsurance.HIS_HealthInsurance_Company_RefID = Parameter.HealthInsuranceCompanyID;
                    healtInsurance.Save(Connection, Transaction);

                    #endregion
                }
                else
                {
                    isOK = false;
                }
            }
            #endregion

            #region Edit


            else
            {
                var result = item.Load(Connection, Transaction, Parameter.PatientID);
                if (result.Status != FR_Status.Success || item.HEC_PatientID == Guid.Empty)
                {
                    //var error = new FR_Guid();
                    //error.ErrorMessage = "No Such ID";
                    //error.Status = FR_Status.Error_Internal;
                    //return error;
                }

                //bussinessParticipant
                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = item.CMN_BPT_BusinessParticipant_RefID;


                var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First();

                //personInfo
                var query2 = new ORM_CMN_PER_PersonInfo.Query();
                query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).FirstOrDefault();

                //medicalPractice
                var query3 = new ORM_HEC_Patient_MedicalPractice.Query();
                query3.HEC_Patient_RefID = Parameter.PatientID;

                var medicalPractice = ORM_HEC_Patient_MedicalPractice.Query.Search(Connection, Transaction, query3).First();

                //healthInsurance
                var query4 = new ORM_HEC_Patient_HealthInsurance.Query();
                query4.Patient_RefID = Parameter.PatientID;

                var healthInsurance = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, query4).First();

                #region Delete Patient

                if (Parameter.IsDeleted == true)
                {
                    item.IsDeleted = true;
                    item.Save(Connection, Transaction);
                }
                #endregion

                else
                {
                    //edit person info
                    personInfo.FirstName = Parameter.Name;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.BirthDate = Parameter.Birthdate;
                    personInfo.Gender    = Parameter.Gender;

                    personInfo.Save(Connection, Transaction);

                    //edit medical practise
                    medicalPractice.HEC_MedicalPractices_RefID = Parameter.PracticeID;
                    medicalPractice.Save(Connection, Transaction);

                    // health insurance
                    healthInsurance.HealthInsurance_State_RefID = Guid.Empty;
                    healthInsurance.InsuranceStateCode          = Parameter.InsuranceStateCode;
                    healthInsurance.HealthInsurance_Number      = Parameter.HealthInsuranceNumber;
                    //TODO
                    healthInsurance.HIS_HealthInsurance_Company_RefID = Parameter.HealthInsuranceCompanyID;
                    healthInsurance.Save(Connection, Transaction);



                    item.Save(Connection, Transaction);
                }
            }
            #endregion

            returnValue.Result.isOK = isOK;
            return(returnValue);

            #endregion UserCode
        }