protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_DMSP_1546 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); P_L6PA_GMSPfID_1538 getParam = new P_L6PA_GMSPfID_1538(); getParam.HEC_PatientID = Parameter.HEC_PatientID; var patient = cls_Get_MS_Patients_For_ID.Invoke(Connection, Transaction, getParam, securityTicket).Result; if (patient != null) { if (patient.Addresses != null) { foreach (var address in patient.Addresses) { P_L6PA_MSVAFP_1545 delAddressPar = new P_L6PA_MSVAFP_1545(); delAddressPar.CMN_AddressID = address.CMN_AddressID; cls_Delete_MS_AddressForPatient.Invoke(Connection, Transaction, delAddressPar, securityTicket); } } if (patient.Contacts != null) { foreach (var contact in patient.Contacts) { ORM_CMN_PER_CommunicationContact.Query cQuery = new ORM_CMN_PER_CommunicationContact.Query(); cQuery.CMN_PER_CommunicationContactID = contact.CMN_PER_CommunicationContactID; cQuery.IsDeleted = false; cQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, cQuery); } } ORM_CMN_PER_PersonInfo.Query ORM_CMN_PER_PersonInfoQuery = new ORM_CMN_PER_PersonInfo.Query(); ORM_CMN_PER_PersonInfoQuery.CMN_PER_PersonInfoID = patient.CMN_PER_PersonInfoID; ORM_CMN_PER_PersonInfoQuery.IsDeleted = false; ORM_CMN_PER_PersonInfoQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_PER_PersonInfo.Query.SoftDelete(Connection, Transaction, ORM_CMN_PER_PersonInfoQuery); ORM_CMN_BPT_BusinessParticipant.Query ORM_CMN_BPT_BusinessParticipantoQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); ORM_CMN_BPT_BusinessParticipantoQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipantID; ORM_CMN_BPT_BusinessParticipantoQuery.IsDeleted = false; ORM_CMN_BPT_BusinessParticipantoQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_BPT_BusinessParticipant.Query.SoftDelete(Connection, Transaction, ORM_CMN_BPT_BusinessParticipantoQuery); ORM_HEC_Patient.Query ORM_HEC_PatientQuery = new ORM_HEC_Patient.Query(); ORM_HEC_PatientQuery.HEC_PatientID = patient.HEC_PatientID; ORM_HEC_PatientQuery.IsDeleted = false; ORM_HEC_PatientQuery.Tenant_RefID = securityTicket.TenantID; ORM_HEC_Patient.Query.SoftDelete(Connection, Transaction, ORM_HEC_PatientQuery); ORM_HEC_Patient_HealthInsurance.Query ORM_HEC_Patient_HealthInsuranceoQuery = new ORM_HEC_Patient_HealthInsurance.Query(); ORM_HEC_Patient_HealthInsuranceoQuery.HEC_Patient_HealthInsurancesID = patient.HEC_Patient_HealthInsurancesID; ORM_HEC_Patient_HealthInsuranceoQuery.IsDeleted = false; ORM_HEC_Patient_HealthInsuranceoQuery.Tenant_RefID = securityTicket.TenantID; ORM_HEC_Patient_HealthInsurance.Query.SoftDelete(Connection, Transaction, ORM_HEC_Patient_HealthInsuranceoQuery); ORM_HEC_STU_Study_ParticipatingPatient.Query ORM_HEC_STU_Study_ParticipatingPatientQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query(); ORM_HEC_STU_Study_ParticipatingPatientQuery.HEC_STU_Study_ParticipatingPatientID = patient.HEC_STU_Study_ParticipatingPatientID; ORM_HEC_STU_Study_ParticipatingPatientQuery.IsDeleted = false; ORM_HEC_STU_Study_ParticipatingPatientQuery.Tenant_RefID = securityTicket.TenantID; ORM_HEC_STU_Study_ParticipatingPatient.Query.SoftDelete(Connection, Transaction, ORM_HEC_STU_Study_ParticipatingPatientQuery); ORM_USR_Account.Query ORM_USR_AccountQuery = new ORM_USR_Account.Query(); ORM_USR_AccountQuery.IsDeleted = false; ORM_USR_AccountQuery.Tenant_RefID = securityTicket.TenantID; ORM_USR_AccountQuery.BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipantID; ORM_USR_Account.Query.SoftDelete(Connection, Transaction, ORM_USR_AccountQuery); var accountRes = ORM_USR_Account.Query.Search(Connection, Transaction, ORM_USR_AccountQuery); if (accountRes.Count == 1) { ORM_USR_Device_AccountCode.Query ORM_USR_Device_AccountCodeQuery = new ORM_USR_Device_AccountCode.Query(); ORM_USR_Device_AccountCodeQuery.IsDeleted = false; ORM_USR_Device_AccountCodeQuery.Tenant_RefID = securityTicket.TenantID; ORM_USR_Device_AccountCodeQuery.Account_RefID = accountRes[0].USR_AccountID; } } return(returnValue); #endregion UserCode }
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 }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_GPBD_1613 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); returnValue.Result = new Guid(); var patient = new ORM_HEC_Patient(); //var serializer = new JsonNetSerializer(); //var connection = new ElasticConnection((String)HttpContext.GetGlobalResourceObject("Global", "ElasticConnection"), 9200); #region Save if (Parameter.ID == null || Parameter.ID == Guid.Empty) { //ORM_HEC_Patient patient.HEC_PatientID = Guid.NewGuid(); patient.Tenant_RefID = securityTicket.TenantID; patient.Creation_Timestamp = DateTime.Now; patient.CMN_BPT_BusinessParticipant_RefID = Guid.NewGuid(); patient.Save(Connection, Transaction); //ORM_CMN_BPT_BusinessParticipant var businessParticipant = new ORM_CMN_BPT_BusinessParticipant(); businessParticipant.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID; businessParticipant.IsNaturalPerson = true; businessParticipant.Tenant_RefID = securityTicket.TenantID; businessParticipant.Creation_Timestamp = DateTime.Now; businessParticipant.Modification_Timestamp = DateTime.Now; businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(); businessParticipant.Save(Connection, Transaction); //ORM_CMN_PER_PersonInfo var personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.PrimaryEmail = Parameter.PrimaryEmail; personInfo.Title = Parameter.Title; personInfo.ProfileImage_Document_RefID = Parameter.ProfileImage_Document_RefID; personInfo.BirthDate = Parameter.BirthDate; personInfo.Gender = Int32.Parse(Parameter.Gender); personInfo.Salutation_General = Parameter.AcademicTitle; personInfo.Address_RefID = Guid.NewGuid(); personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Modification_Timestamp = DateTime.Now; personInfo.AgeCalculation_YearOfBirth = DateTime.Now.Year - personInfo.BirthDate.Year; personInfo.Save(Connection, Transaction); //ORM_CMN_Address var address = new ORM_CMN_Address(); address.CMN_AddressID = personInfo.Address_RefID; address.Street_Name = Parameter.Street_Name; address.Street_Number = Parameter.Street_Number; address.City_Name = Parameter.City_Name; address.City_PostalCode = Parameter.City_PostalCode; address.Country_ISOCode = Parameter.Country_ISOCode; address.Tenant_RefID = securityTicket.TenantID; address.Creation_Timestamp = DateTime.Now; address.Save(Connection, Transaction); //ORM_CMN_PER_PersonInfo_SocialSecurityNumber var socialSecurityNumber = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber(); socialSecurityNumber.CMN_PER_PersonInfo_SocialSecurityNumberID = Guid.NewGuid(); socialSecurityNumber.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; socialSecurityNumber.SocialSecurityNumber = Parameter.SocialSecurityNumber; socialSecurityNumber.Tenant_RefID = securityTicket.TenantID; socialSecurityNumber.Creation_Timestamp = DateTime.Now; socialSecurityNumber.Save(Connection, Transaction); var TelephoneCompanyType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query() { Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).SingleOrDefault(); var MobileCompanyType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query() { Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var EmailType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query() { Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); //add into database //var UrlType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, // new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query() // { // Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.URL), // Tenant_RefID = securityTicket.TenantID, // IsDeleted = false // }).Single(); var FaxType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query() { Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Fax), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); ORM_CMN_PER_CommunicationContact communicationContactsPhone = new ORM_CMN_PER_CommunicationContact(); communicationContactsPhone.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContactsPhone.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContactsPhone.Contact_Type = TelephoneCompanyType.CMN_PER_CommunicationContact_TypeID; communicationContactsPhone.Content = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone)).Single().Content; communicationContactsPhone.Creation_Timestamp = DateTime.Now; communicationContactsPhone.Modification_Timestamp = DateTime.Now; communicationContactsPhone.Tenant_RefID = securityTicket.TenantID; communicationContactsPhone.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact communicationContactsMobile = new ORM_CMN_PER_CommunicationContact(); communicationContactsMobile.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContactsMobile.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContactsMobile.Contact_Type = MobileCompanyType.CMN_PER_CommunicationContact_TypeID; communicationContactsMobile.Content = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile)).Single().Content; communicationContactsMobile.Creation_Timestamp = DateTime.Now; communicationContactsMobile.Modification_Timestamp = DateTime.Now; communicationContactsMobile.Tenant_RefID = securityTicket.TenantID; communicationContactsMobile.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact communicationContactsEmail = new ORM_CMN_PER_CommunicationContact(); communicationContactsEmail.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContactsEmail.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContactsEmail.Contact_Type = EmailType.CMN_PER_CommunicationContact_TypeID; communicationContactsEmail.Content = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email)).Single().Content; communicationContactsEmail.Creation_Timestamp = DateTime.Now; communicationContactsEmail.Modification_Timestamp = DateTime.Now; communicationContactsEmail.Tenant_RefID = securityTicket.TenantID; communicationContactsEmail.Save(Connection, Transaction); //*******************Save languages to patient************************ if (Parameter.Languages != null && Parameter.Languages.Count() != 0) { foreach (var language in Parameter.Languages) { ORM_CMN_BPT_BusinessParticipant_SpokenLanguage bpLanguage = new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage(); bpLanguage.CMN_BPT_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID; bpLanguage.CMN_BPT_BusinessParticipant_SpokenLanguageID = Guid.NewGuid(); bpLanguage.CMN_Language_RefID = language.CMN_Language_RefID; bpLanguage.IsDeleted = false; bpLanguage.Tenant_RefID = securityTicket.TenantID; bpLanguage.Save(Connection, Transaction); } } //#region Upload To Elastic //bool indexExists = true; //#region set Mapping //string jsonPatientMapping = new MapBuilder<Patient>() // .RootObject("patient", ro => ro // .Properties(pr => pr // .MultiField("name", mfp => mfp.Fields(f => f // .String("name", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard)) // .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive")) // ) // ) // .MultiField("last_name", mfp => mfp.Fields(f => f // .String("last_name", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard)) // .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive")) // ) // ) // .MultiField("birthday", mfp => mfp.Fields(f => f // .String("birthday", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard)) // .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive")) // ) // ) // .MultiField("age", mfp => mfp.Fields(f => f // .String("age", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard)) // .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive")) // ) // ) // )).BuildBeautified(); //#endregion //try //{ // connection.Head(new IndexExistsCommand(securityTicket.TenantID.ToString())); //} //catch (OperationException ex) //{ // if (ex.HttpStatusCode == 404) // indexExists = false; //} //if (!indexExists) //{ // #region set index settings // string settings = new IndexSettingsBuilder() // .Analysis(anl => anl // .Filter(fil => fil // .EdgeNGram("autocomplete_filter", gr => gr.MinGram(1).MaxGram(20))) // .Analyzer(a => a // .Custom("caseinsensitive", custom => custom // .Tokenizer(DefaultTokenizers.keyword) // .Filter("lowercase") // ) // .Custom("autocomplete", custom => custom // .Tokenizer(DefaultTokenizers.standard) // .Filter("lowercase", "autocomplete_filter") // ) // ) // ) // .BuildBeautified(); // #endregion // connection.Put(securityTicket.TenantID.ToString(), settings); //} //#region check if type exists //bool typeExists = true; //try //{ // connection.Head(new IndexExistsCommand(securityTicket.TenantID.ToString() + "/patient")); //} //catch (OperationException ex) //{ // if (ex.HttpStatusCode == 404) // typeExists = false; //} //#endregion //if (!typeExists) // connection.Put(new PutMappingCommand(securityTicket.TenantID.ToString(), "patient"), jsonPatientMapping); //string bulkCommand = new BulkCommand(index: securityTicket.TenantID.ToString(), type: "patient").Refresh(); //List<Patient> patientList = new List<Patient>(); //Patient patient_elastic = new Patient(); //patient_elastic.id = patient.HEC_PatientID.ToString(); //patient_elastic.age = (DateTime.Today.Year - Parameter.BirthDate.Year).ToString(); //patient_elastic.birthday = Parameter.BirthDate.ToShortDateString(); //patient_elastic.last_name = Parameter.LastName; //patient_elastic.name = Parameter.FirstName; //patientList.Add(patient_elastic); //string bulkJson = new BulkBuilder(serializer) // .BuildCollection(patientList, (builder, pro) => builder.Index(data: pro, id: pro.id) // ); //connection.Post(bulkCommand, bulkJson); //#endregion } #endregion else { #region Delete if (Parameter.isDeleted) { var patientQuery = new ORM_HEC_Patient.Query(); patientQuery.HEC_PatientID = Parameter.ID; patientQuery.IsDeleted = false; patientQuery.Tenant_RefID = securityTicket.TenantID; patient = ORM_HEC_Patient.Query.Search(Connection, Transaction, patientQuery).Single(); patient.IsDeleted = true; patient.Save(Connection, Transaction); var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID; businessParticipantQuery.IsDeleted = false; businessParticipantQuery.Tenant_RefID = securityTicket.TenantID; var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single(); businessParticipant.IsDeleted = true; businessParticipant.Save(Connection, Transaction); var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query(); personInfoQuery.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; personInfoQuery.IsDeleted = false; personInfoQuery.Tenant_RefID = securityTicket.TenantID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single(); personInfo.IsDeleted = true; personInfo.Save(Connection, Transaction); var addressQuery = new ORM_CMN_Address.Query(); addressQuery.CMN_AddressID = personInfo.Address_RefID; addressQuery.IsDeleted = false; addressQuery.Tenant_RefID = securityTicket.TenantID; var address = ORM_CMN_Address.Query.Search(Connection, Transaction, addressQuery).Single(); address.IsDeleted = true; address.Save(Connection, Transaction); var socialSecurityNumberQuery = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query(); socialSecurityNumberQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; socialSecurityNumberQuery.IsDeleted = false; socialSecurityNumberQuery.Tenant_RefID = securityTicket.TenantID; var socialSecurityNumber = ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query.Search(Connection, Transaction, socialSecurityNumberQuery).Single(); socialSecurityNumber.IsDeleted = true; socialSecurityNumber.Save(Connection, Transaction); var communicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query(); communicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContactQuery.IsDeleted = false; communicationContactQuery.Tenant_RefID = securityTicket.TenantID; var communicationContactList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactQuery).ToList(); ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.SoftDelete(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query { CMN_BPT_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); //// delete on Elastic //connection.Delete(securityTicket.TenantID.ToString() + "/patient/" + Parameter.ID.ToString()); } #endregion #region Edit else { var patientQuery = new ORM_HEC_Patient.Query(); patientQuery.HEC_PatientID = Parameter.ID; patientQuery.IsDeleted = false; patientQuery.Tenant_RefID = securityTicket.TenantID; patient = ORM_HEC_Patient.Query.Search(Connection, Transaction, patientQuery).Single(); var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID; businessParticipantQuery.IsDeleted = false; businessParticipantQuery.Tenant_RefID = securityTicket.TenantID; var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single(); var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query(); personInfoQuery.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; personInfoQuery.IsDeleted = false; personInfoQuery.Tenant_RefID = securityTicket.TenantID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.PrimaryEmail = Parameter.PrimaryEmail; personInfo.Title = Parameter.Title; personInfo.Gender = Int32.Parse(Parameter.Gender); personInfo.ProfileImage_Document_RefID = Parameter.ProfileImage_Document_RefID; personInfo.BirthDate = Parameter.BirthDate; personInfo.Salutation_General = Parameter.AcademicTitle; personInfo.Modification_Timestamp = DateTime.Now; personInfo.AgeCalculation_YearOfBirth = DateTime.Now.Year - personInfo.BirthDate.Year; personInfo.Save(Connection, Transaction); if (personInfo.Address_RefID != Guid.Empty) { var addressQuery = new ORM_CMN_Address.Query(); addressQuery.CMN_AddressID = personInfo.Address_RefID; addressQuery.IsDeleted = false; addressQuery.Tenant_RefID = securityTicket.TenantID; var address = ORM_CMN_Address.Query.Search(Connection, Transaction, addressQuery).Single(); address.Street_Name = Parameter.Street_Name; address.Street_Number = Parameter.Street_Number; address.City_Name = Parameter.City_Name; address.City_PostalCode = Parameter.City_PostalCode; address.Country_ISOCode = Parameter.Country_ISOCode; address.Save(Connection, Transaction); } else { var address = new ORM_CMN_Address(); address.CMN_AddressID = Guid.NewGuid(); address.Street_Name = Parameter.Street_Name; address.Street_Number = Parameter.Street_Number; address.City_Name = Parameter.City_Name; address.City_PostalCode = Parameter.City_PostalCode; address.Country_ISOCode = Parameter.Country_ISOCode; address.Tenant_RefID = securityTicket.TenantID; address.Creation_Timestamp = DateTime.Now; address.Save(Connection, Transaction); personInfo.Address_RefID = address.CMN_AddressID; personInfo.Save(Connection, Transaction); } var socialSecurityNumberQuery = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query(); socialSecurityNumberQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; socialSecurityNumberQuery.IsDeleted = false; socialSecurityNumberQuery.Tenant_RefID = securityTicket.TenantID; var socialSecurityNumber = ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query.Search(Connection, Transaction, socialSecurityNumberQuery).SingleOrDefault(); if (socialSecurityNumber == null) { socialSecurityNumber = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber(); socialSecurityNumber.CMN_PER_PersonInfo_SocialSecurityNumberID = Guid.NewGuid(); socialSecurityNumber.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; socialSecurityNumber.Tenant_RefID = securityTicket.TenantID; } socialSecurityNumber.SocialSecurityNumber = Parameter.SocialSecurityNumber; socialSecurityNumber.Save(Connection, Transaction); var communicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query(); communicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContactQuery.IsDeleted = false; communicationContactQuery.Tenant_RefID = securityTicket.TenantID; var communicationContactList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactQuery).ToList(); List <string> unusedTypes = new List <string>() { DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.URL), DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile), DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone), DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email) }; foreach (var communicationContact in communicationContactList) { var communicationContact_TypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query(); communicationContact_TypeQuery.CMN_PER_CommunicationContact_TypeID = communicationContact.Contact_Type; communicationContact_TypeQuery.IsDeleted = false; communicationContact_TypeQuery.Tenant_RefID = securityTicket.TenantID; var communicationContact_Type = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, communicationContact_TypeQuery).Single(); var newType = Parameter.ContactTypes.Where(i => i.Type == communicationContact_Type.Type).Single(); communicationContact.Content = newType.Content; communicationContact.Modification_Timestamp = DateTime.Now; communicationContact.Save(Connection, Transaction); if (unusedTypes.Contains(communicationContact_Type.Type)) { unusedTypes.Remove(communicationContact_Type.Type); } } var contactTypes = cls_Get_AllComunicationContactTypes.Invoke(Connection, Transaction, securityTicket).Result.ToList(); foreach (var type in unusedTypes) { ORM_CMN_PER_CommunicationContact communicationContactsPhone = new ORM_CMN_PER_CommunicationContact(); communicationContactsPhone.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContactsPhone.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; P_L2CN_GCTIDfGPMID_1359 contantTypeParam = new P_L2CN_GCTIDfGPMID_1359(); contantTypeParam.Type = type; var contantTypeID = cls_Get_ContantTypeID_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, contantTypeParam, securityTicket).Result.ContactTypeID; communicationContactsPhone.Contact_Type = contantTypeID; communicationContactsPhone.Content = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone)).Single().Content; communicationContactsPhone.Creation_Timestamp = DateTime.Now; communicationContactsPhone.Modification_Timestamp = DateTime.Now; communicationContactsPhone.Tenant_RefID = securityTicket.TenantID; communicationContactsPhone.Save(Connection, Transaction); } //connection.Delete(securityTicket.TenantID.ToString() + "/patient/" + Parameter.ID.ToString()); //string bulkCommand = new BulkCommand(index: securityTicket.TenantID.ToString(), type: "patient").Refresh(); //List<Patient> patientList = new List<Patient>(); //Patient patient_elastic = new Patient(); //patient_elastic.id = patient.HEC_PatientID.ToString(); //patient_elastic.age = (DateTime.Today.Year - Parameter.BirthDate.Year).ToString(); //patient_elastic.birthday = Parameter.BirthDate.ToShortDateString(); //patient_elastic.last_name = Parameter.LastName; //patient_elastic.name = Parameter.FirstName; //patientList.Add(patient_elastic); //string bulkJson = new BulkBuilder(serializer) // .BuildCollection(patientList, (builder, pro) => builder.Index(data: pro, id: pro.id) // ); //connection.Post(bulkCommand, bulkJson); #region languages if (Parameter.Languages == null || Parameter.Languages.Count() == 0) { P_L5PA_GPBD_1613_Languages Languages = new P_L5PA_GPBD_1613_Languages(); Languages.CMN_Language_RefID = Guid.Empty; } else if (Parameter.Languages != null || Parameter.Languages.Count() != 0) { foreach (var language in Parameter.Languages) { var languageToPatient = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query { CMN_Language_RefID = language.CMN_Language_RefID, CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).FirstOrDefault(); if (languageToPatient == null) { ORM_CMN_BPT_BusinessParticipant_SpokenLanguage bpLanguage = new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage(); bpLanguage.CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID; bpLanguage.CMN_BPT_BusinessParticipant_SpokenLanguageID = Guid.NewGuid(); bpLanguage.CMN_Language_RefID = language.CMN_Language_RefID; bpLanguage.IsDeleted = false; bpLanguage.Tenant_RefID = securityTicket.TenantID; bpLanguage.Save(Connection, Transaction); } } // deleting languages to patient that were deleted during edit List <ORM_CMN_BPT_BusinessParticipant_SpokenLanguage> languageToDoctorList = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query { CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); foreach (var languageToDoctor in languageToDoctorList) { if (Parameter.Languages.FirstOrDefault(x => x.CMN_Language_RefID == languageToDoctor.CMN_Language_RefID) == null) { languageToDoctor.IsDeleted = true; languageToDoctor.Save(Connection, Transaction); } } } else { List <ORM_CMN_BPT_BusinessParticipant_SpokenLanguage> languageToDoctorList = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query { CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); if (languageToDoctorList != null || languageToDoctorList.Count() != 0) { foreach (var language in languageToDoctorList) { language.IsDeleted = true; language.Save(Connection, Transaction); } } } #endregion } #endregion } returnValue.Result = patient.HEC_PatientID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_DBBVP_1711 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); P_L6PA_GBBVPfID_1714 getParam = new P_L6PA_GBBVPfID_1714(); getParam.HEC_PatientID = Parameter.HEC_PatientID; var patient = cls_Get_BBV_Patients_For_ID.Invoke(Connection, Transaction, getParam, securityTicket).Result; if (patient != null) { if (patient.Addresses != null) { foreach (var address in patient.Addresses) { P_L6PA_DBBVAFP_1703 delAddressPar = new P_L6PA_DBBVAFP_1703(); delAddressPar.CMN_AddressID = address.CMN_AddressID; cls_Delete_BBV_AddressForPatient.Invoke(Connection, Transaction, delAddressPar, securityTicket); } } if (patient.Contacts != null) { foreach (var contact in patient.Contacts) { ORM_CMN_PER_CommunicationContact.Query cQuery = new ORM_CMN_PER_CommunicationContact.Query(); cQuery.CMN_PER_CommunicationContactID = contact.CMN_PER_CommunicationContactID; cQuery.IsDeleted = false; cQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, cQuery); } } ORM_CMN_PER_PersonInfo.Query ORM_CMN_PER_PersonInfoQuery = new ORM_CMN_PER_PersonInfo.Query(); ORM_CMN_PER_PersonInfoQuery.CMN_PER_PersonInfoID = patient.CMN_PER_PersonInfoID; ORM_CMN_PER_PersonInfoQuery.IsDeleted = false; ORM_CMN_PER_PersonInfoQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_PER_PersonInfo.Query.SoftDelete(Connection, Transaction, ORM_CMN_PER_PersonInfoQuery); ORM_CMN_BPT_BusinessParticipant.Query ORM_CMN_BPT_BusinessParticipantoQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); ORM_CMN_BPT_BusinessParticipantoQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipantID; ORM_CMN_BPT_BusinessParticipantoQuery.IsDeleted = false; ORM_CMN_BPT_BusinessParticipantoQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_BPT_BusinessParticipant.Query.SoftDelete(Connection, Transaction, ORM_CMN_BPT_BusinessParticipantoQuery); ORM_HEC_Patient.Query ORM_HEC_PatientQuery = new ORM_HEC_Patient.Query(); ORM_HEC_PatientQuery.HEC_PatientID = patient.HEC_PatientID; ORM_HEC_PatientQuery.IsDeleted = false; ORM_HEC_PatientQuery.Tenant_RefID = securityTicket.TenantID; ORM_HEC_Patient.Query.SoftDelete(Connection, Transaction, ORM_HEC_PatientQuery); ORM_HEC_Patient_HealthInsurance.Query ORM_HEC_Patient_HealthInsuranceoQuery = new ORM_HEC_Patient_HealthInsurance.Query(); ORM_HEC_Patient_HealthInsuranceoQuery.HEC_Patient_HealthInsurancesID = patient.HEC_Patient_HealthInsurancesID; ORM_HEC_Patient_HealthInsuranceoQuery.IsDeleted = false; ORM_HEC_Patient_HealthInsuranceoQuery.Tenant_RefID = securityTicket.TenantID; ORM_HEC_Patient_HealthInsurance.Query.SoftDelete(Connection, Transaction, ORM_HEC_Patient_HealthInsuranceoQuery); ORM_HEC_STU_Study_ParticipatingPatient.Query ORM_HEC_STU_Study_ParticipatingPatientQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query(); ORM_HEC_STU_Study_ParticipatingPatientQuery.HEC_STU_Study_ParticipatingPatientID = patient.HEC_STU_Study_ParticipatingPatientID; ORM_HEC_STU_Study_ParticipatingPatientQuery.IsDeleted = false; ORM_HEC_STU_Study_ParticipatingPatientQuery.Tenant_RefID = securityTicket.TenantID; ORM_HEC_STU_Study_ParticipatingPatient.Query.SoftDelete(Connection, Transaction, ORM_HEC_STU_Study_ParticipatingPatientQuery); var transactionsQuery = new ORM_HEC_Patient_Prescription_Transaction.Query(); transactionsQuery.PrescriptionTransaction_Patient_RefID = patient.HEC_PatientID; transactionsQuery.IsDeleted = false; ORM_HEC_Patient_Prescription_Transaction.Query.SoftDelete(Connection, Transaction, transactionsQuery); } return(returnValue); #endregion UserCode }