protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_SDBI_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var doctor = new ORM_HEC_Doctor(); if (Parameter.DoctorID != Guid.Empty) { var result = doctor.Load(Connection, Transaction, Parameter.DoctorID); if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } #region Edit bool bopAccIsChenged = (doctor.Account_RefID == Parameter.Account_RefID) ? false : true; doctor.Account_RefID = Parameter.Account_RefID; if (Parameter.isLucentisSave) { doctor.DoctorIDNumber = Parameter.ifLucentis_LANR; } doctor.Save(Connection, Transaction); //bussinessParticipant var query1 = new ORM_CMN_BPT_BusinessParticipant.Query(); query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID; var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First(); if (!bopAccIsChenged) { //personInfo var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; if (Parameter.isOphthalSave) { personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General; personInfo.Salutation_Letter = Parameter.ifOphthal_Salutation_Letter; } if (Parameter.isLucentisSave) { personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail; } personInfo.Save(Connection, Transaction); var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); if (Parameter.Contacts != null) { foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID); if (communicationContacts != null) { communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Content = parContact.Content; communicationContacts.Save(Connection, Transaction); } else { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = parContact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } } } else { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; account2personInfoQuery.IsDeleted = false; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; personInfo.Save(Connection, Transaction); var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); if (communicationContactsList != null) { foreach (var c in communicationContactsList) { c.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; c.Save(Connection, Transaction); } } if (Parameter.Contacts != null) { foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID); if (communicationContacts != null) { communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Content = parContact.Content; communicationContacts.Save(Connection, Transaction); } else { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = parContact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } } bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; bussinessParticipant.Save(Connection, Transaction); } if (Parameter.isLucentisSave) { foreach (var practice in Parameter.Practices) { //if (practice.PracticeID != Guid.Empty) { var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = practice.PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var associatedbusinessparticipantsOriginal = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3).FirstOrDefault(); if (associatedbusinessparticipantsOriginal != null) { associatedbusinessparticipantsOriginal.IsDeleted = practice.isDeleted; associatedbusinessparticipantsOriginal.Save(Connection, Transaction); } else { var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName; associatedbusinessparticipants.Creation_Timestamp = DateTime.Now; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); // } } } } if (Parameter.isOphthalSave && Parameter.Practices.Length == 1) { var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var associatedbusinessparticipantsRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3); ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant firstPractice; var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = Parameter.Practices[0].PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); if (associatedbusinessparticipantsRes.Count > 0) { associatedbusinessparticipantsRes = associatedbusinessparticipantsRes.OrderBy(a => a.Creation_Timestamp).ToList(); firstPractice = associatedbusinessparticipantsRes.First(); foreach (var item in associatedbusinessparticipantsRes) { if (item != firstPractice && item.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == practiceBPT.CMN_BPT_BusinessParticipantID) { item.IsDeleted = true; item.Save(Connection, Transaction); } } } else { firstPractice = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); firstPractice.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); firstPractice.Tenant_RefID = securityTicket.TenantID; firstPractice.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; } firstPractice.AssociatedParticipant_FunctionName = Parameter.Practices[0].AssociatedParticipant_FunctionName; firstPractice.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; firstPractice.Save(Connection, Transaction); } #endregion } else { #region Save //personInfo Guid personInfoID; if (Parameter.Account_RefID == Guid.Empty) { var personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; if (Parameter.isLucentisSave) { personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail; } personInfo.Title = Parameter.Title; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; if (Parameter.isOphthalSave) { personInfo.Salutation_Letter = Parameter.ifOphthal_Salutation_Letter; personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General; } personInfo.Save(Connection, Transaction); personInfoID = personInfo.CMN_PER_PersonInfoID; } else { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; account2personInfoQuery.IsDeleted = false; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; personInfo.Save(Connection, Transaction); personInfoID = personInfo.CMN_PER_PersonInfoID; } //bussinessParticipants var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant(); bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bussinessParticipantTable.IsNaturalPerson = true; bussinessParticipantTable.IsTenant = false; bussinessParticipantTable.IsCompany = false; bussinessParticipantTable.IsDeleted = false; bussinessParticipantTable.Creation_Timestamp = DateTime.Now; bussinessParticipantTable.Tenant_RefID = securityTicket.TenantID; bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; bussinessParticipantTable.Save(Connection, Transaction); doctor.HEC_DoctorID = Guid.NewGuid(); if (Parameter.isLucentisSave) { doctor.DoctorIDNumber = Parameter.ifLucentis_LANR; } doctor.Creation_Timestamp = DateTime.Now; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; doctor.Account_RefID = Parameter.Account_RefID; doctor.Save(Connection, Transaction); if (Parameter.Contacts != null) { foreach (var contact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfoID; communicationContacts.Contact_Type = contact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = contact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } foreach (var practice in Parameter.Practices) { if (practice.isDeleted == true) { continue; } var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = practice.PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); //associatedbusinessparticipants var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName; associatedbusinessparticipants.Creation_Timestamp = DateTime.Now; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); } #endregion } returnValue.Result = doctor.HEC_DoctorID; return(returnValue); #endregion UserCode }
protected static FR_L6TR_BT_2204 Execute(DbConnection Connection, DbTransaction Transaction, P_L6TR_BT_2204 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6TR_BT_2204(); returnValue.Result = new L6TR_BT_2204(); ORM_BIL_BillHeader header = new ORM_BIL_BillHeader(); long previousMaxPositionIndex = Parameter.previousMaxPositionIndex; #region persistHeader if (Parameter.isNewBilling) { header.Tenant_RefID = securityTicket.TenantID; header.BIL_BillHeaderID = Guid.NewGuid(); var tenantHeaders = ORM_BIL_BillHeader.Query.Search(Connection, Transaction, new ORM_BIL_BillHeader.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).ToArray(); tenantHeaders = tenantHeaders.OrderBy(t => t.Creation_Timestamp).ToArray(); var headersForThisYear = tenantHeaders.Where(h => h.Creation_Timestamp.Year == DateTime.Now.Year).ToArray(); int prevMaxHeaderNumber = 0; if (headersForThisYear.Length > 0) { ORM_BIL_BillHeader prevHeader = null; foreach (var headerTY in headersForThisYear) { int hn = 0; if (int.TryParse(headerTY.BillNumber, out hn) && prevMaxHeaderNumber <= hn) { prevMaxHeaderNumber = hn; prevHeader = headerTY; } } if (prevHeader != null) { var positionQuery = new ORM_BIL_BillPosition.Query(); positionQuery.Tenant_RefID = securityTicket.TenantID; positionQuery.BIL_BilHeader_RefID = prevHeader.BIL_BillHeaderID; var prevPositions = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, positionQuery).ToArray(); if (prevPositions != null && prevPositions.Length > 0) { foreach (var prevPosition in prevPositions) { long number = 0; if (long.TryParse(prevPosition.External_PositionReferenceField, out number) && previousMaxPositionIndex < number) { previousMaxPositionIndex = number; } } } } } header.BillNumber = prevMaxHeaderNumber + 1 + ""; if (Parameter.billTreatments) { header.Save(Connection, Transaction); } } else { header.Tenant_RefID = securityTicket.TenantID; header.BIL_BillHeaderID = Parameter.ifOldBillingHeaderID; header.BillNumber = Parameter.ifOldBillingHeaderNumber; } //new edifact entry ORM_BIL_BillHeaderExtension_EDIFACT.Query edifactQuery = new ORM_BIL_BillHeaderExtension_EDIFACT.Query(); edifactQuery.Tenant_RefID = securityTicket.TenantID; var edifactRes = ORM_BIL_BillHeaderExtension_EDIFACT.Query.Search(Connection, Transaction, edifactQuery); edifactRes = edifactRes.Where(e => e.Creation_Timestamp.Year == DateTime.Now.Year).ToList(); ORM_BIL_BillHeaderExtension_EDIFACT edifact = new ORM_BIL_BillHeaderExtension_EDIFACT(); edifact.BIL_BillHeader_RefID = header.BIL_BillHeaderID; edifact.BIL_BillHeaderExtension_EDIFACTID = Guid.NewGuid(); edifact.EDIFACTCounter = edifactRes.Count + 1; edifact.Tenant_RefID = securityTicket.TenantID; if (Parameter.billTreatments) { edifact.Save(Connection, Transaction); } #endregion //positions List <L6TR_BT_2204_Position> positions = new List <L6TR_BT_2204_Position>(); List <Guid> patientsIDlist = new List <Guid>(); Dictionary <Guid, Guid> treatment2patient = new Dictionary <Guid, Guid>(); Dictionary <Guid, int> positionCountPerPatient = new Dictionary <Guid, int>(); foreach (var id in Parameter.TreatmentID_List) { var item = new ORM_HEC_Patient_Treatment(); item.Load(Connection, Transaction, id); if (item.IsTreatmentFollowup) { throw new Exception("This treatment, ID: " + id + ", is followup!"); } var patient2treatmentQuery = new ORM_HEC_Patient_2_PatientTreatment.Query(); patient2treatmentQuery.Tenant_RefID = securityTicket.TenantID; patient2treatmentQuery.HEC_Patient_Treatment_RefID = id; var patient2treatmentRes = ORM_HEC_Patient_2_PatientTreatment.Query.Search(Connection, Transaction, patient2treatmentQuery).First(); if (!patientsIDlist.Contains(patient2treatmentRes.HEC_Patient_RefID)) { patientsIDlist.Add(patient2treatmentRes.HEC_Patient_RefID); } treatment2patient.Add(id, patient2treatmentRes.HEC_Patient_RefID); if (!positionCountPerPatient.ContainsKey(patient2treatmentRes.HEC_Patient_RefID)) { positionCountPerPatient.Add(patient2treatmentRes.HEC_Patient_RefID, 0); } } //log.Debug("first loop finished after: " + sw.ElapsedMilliseconds); P_L6PA_GPBIfPID_1155 patParam = new P_L6PA_GPBIfPID_1155(); patParam.PatientID = patientsIDlist.ToArray(); var patients = cls_Get_PatientBillInfo_for_PatientID.Invoke(Connection, Transaction, patParam, securityTicket).Result; P_L6TR_GTaRDfBIbT_1204 tretParam = new P_L6TR_GTaRDfBIbT_1204(); tretParam.TreatmentID = Parameter.TreatmentID_List; var treatments = cls_Get_Treatment_and_RelevantDiagnosis_for_BillInfo_by_TreatmentID.Invoke(Connection, Transaction, tretParam, securityTicket).Result; List <Guid> followTretIDs = new List <Guid>(); if (treatments != null) { foreach (var t in treatments) { followTretIDs.Add(t.HEC_Patient_TreatmentID); } } P_L6TR_GFTfRbIDs_1646 followParam = new P_L6TR_GFTfRbIDs_1646(); followParam.TreatmentIDs = followTretIDs.ToArray(); var followups = cls_Get_Followups_for_Report_byIDs.Invoke(Connection, Transaction, followParam, securityTicket).Result; ///counter bill P_L5TR_GTCfPID_1152 tcParam = new P_L5TR_GTCfPID_1152(); tcParam.PatientID = patientsIDlist.ToArray(); var tretRes = cls_Get_TreatmentCount_for_PatientIDlist.Invoke(Connection, Transaction, tcParam, securityTicket).Result; int i = 1; foreach (var id in Parameter.TreatmentID_List) { #region collectPositionDataForReport var patient = patients.FirstOrDefault(p => p.HEC_PatientID == treatment2patient[id]); if (patient == null) { //throw new Exception("No patient for ID: " + treatment2patient[id]); } var treatment = treatments.FirstOrDefault(t => t.HEC_Patient_TreatmentID == id); if (treatment == null) { throw new Exception("No treatment for ID: " + id); } var followupsForThisThreatment = followups.Where(f => f.IfTreatmentFollowup_FromTreatment_RefID == treatment.HEC_Patient_TreatmentID).ToArray(); #region changeFlag if (Parameter.billTreatments) { var item = new ORM_HEC_Patient_Treatment(); item.Load(Connection, Transaction, id); item.IsTreatmentBilled = true; item.IfTreatmentBilled_Date = DateTime.Now; item.Save(Connection, Transaction); } #endregion #region persistPosition ORM_BIL_BillPosition position = new ORM_BIL_BillPosition(); position.Tenant_RefID = securityTicket.TenantID; position.PositionIndex = i; position.BIL_BilHeader_RefID = header.BIL_BillHeaderID; position.BIL_BillPositionID = Guid.NewGuid(); if (Parameter.billTreatments) { position.Save(Connection, Transaction); } ORM_BIL_BillPosition_2_PatientTreatment p2t = new ORM_BIL_BillPosition_2_PatientTreatment(); p2t.AssignmentID = Guid.NewGuid(); p2t.Tenant_RefID = securityTicket.TenantID; p2t.BIL_BillPosition_RefID = position.BIL_BillPositionID; p2t.HEC_Patient_Treatment_RefID = treatment.HEC_Patient_TreatmentID; if (Parameter.billTreatments) { p2t.Save(Connection, Transaction); } #endregion ORM_HEC_Doctor doctor = new ORM_HEC_Doctor(); if (treatment.IfTreatmentPerformed_ByDoctor_RefID != Guid.Empty) { var doctorQuery = new ORM_HEC_Doctor.Query(); doctorQuery.HEC_DoctorID = treatment.IfTreatmentPerformed_ByDoctor_RefID; doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).FirstOrDefault(); } var practiceQuery = new ORM_HEC_MedicalPractis.Query(); practiceQuery.HEC_MedicalPractiseID = treatment.TreatmentPractice_RefID; practiceQuery.Tenant_RefID = securityTicket.TenantID; var practice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practiceQuery).FirstOrDefault(); string BSNR = "x"; if (practice != null) { var practiceInfoQuery = new ORM_CMN_COM_CompanyInfo.Query(); practiceInfoQuery.CMN_COM_CompanyInfoID = practice.Ext_CompanyInfo_RefID; practiceInfoQuery.Tenant_RefID = securityTicket.TenantID; var practiceInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, practiceInfoQuery).First(); BSNR = practiceInfo.CompanyInfo_EstablishmentNumber; } L6TR_BT_2204_Position pos = new L6TR_BT_2204_Position(); pos.ORM_BIL_BillPositionID = position.BIL_BillPositionID; pos.strDoctorLANR = (doctor != null) ? doctor.DoctorIDNumber : "HEC_Doctor is null!!!!"; pos.TreatmentID = treatment.HEC_Patient_TreatmentID; pos.bTreatmentIsFollowup = treatment.IsTreatmentFollowup; pos.strPracticeBSNR = BSNR; pos.dtTreatment = treatment.IfTreatmentPerformed_Date; if (patient != null) { pos.iTreatmentNumber = tretRes.FirstOrDefault(t => t.HEC_PatientID == patient.HEC_PatientID).treatmentCount + positionCountPerPatient[treatment2patient[id]]; pos.iPatientSex = patient.Gender; pos.iPatientInsuranceState = (patient.InsuranceStateCode != null) ? patient.InsuranceStateCode : String.Empty; pos.dtPatientBirthDate = patient.Birthdate; pos.PatientFirstName = patient.FirstName; pos.PatientLastName = patient.LastName; pos.PatientInsuranceNumber = (patient.HealthInsurance_Number != null) ? patient.HealthInsurance_Number : String.Empty; } else { pos.iTreatmentNumber = -1; pos.iPatientSex = 0; pos.iPatientInsuranceState = "xxxxx"; pos.dtPatientBirthDate = DateTime.MinValue; pos.PatientFirstName = "x"; pos.PatientLastName = "x"; pos.PatientInsuranceNumber = "x"; } pos.cTreatmentLocalization = (treatment.IsTreatmentOfLeftEye) ? "L" : "R"; pos.strFollowupPractice = "-"; pos.strFollowupDoctor = "-"; pos.strFollowupStatus = "Keine Nachuntersuchung geplant."; if (followupsForThisThreatment != null && followupsForThisThreatment.Length > 0) { var performedF = followupsForThisThreatment.Where(f => f.IsTreatmentPerformed == true).ToArray(); if (performedF != null && performedF.Length > 0) { performedF = performedF.OrderBy(f => f.IfTreatmentPerformed_Date).ToArray(); var firstPF = performedF.First(); pos.strFollowupDoctor = firstPF.DoctorFirstName + " " + firstPF.DoctorLastname; pos.dtFollowup = firstPF.IfTreatmentPerformed_Date; pos.strFollowupPractice = firstPF.DisplayName; pos.strFollowupStatus = (firstPF.IsTreatmentPerformed) ? "durchgeführt" : "geplant"; } else { var scheduledF = followupsForThisThreatment.Where(f => f.IsScheduled == true).ToArray(); if (scheduledF != null && scheduledF.Length > 0) { scheduledF = scheduledF.OrderBy(f => f.IfSheduled_Date).ToArray(); var firstSF = scheduledF.First(); pos.strFollowupDoctor = firstSF.DoctorFirstName + " " + firstSF.DoctorLastname; pos.dtFollowup = firstSF.IfTreatmentPerformed_Date; pos.strFollowupPractice = firstSF.DisplayName; pos.strFollowupStatus = (firstSF.IsTreatmentPerformed) ? "durchgeführt" : "geplant"; } } } var articles = new List <L6TR_BT_2204_ArticleInfo>(); foreach (var art in treatment.Article) { var article = new L6TR_BT_2204_ArticleInfo(); article.ArticleID = art.CMN_PRO_ProductID; article.Name = art.Product_Name; article.PZN = art.Product_Number; article.Quantity = art.Quantity; articles.Add(article); } pos.ArticleInfo = articles.ToArray(); var diagnosies = new List <L6TR_BT_2204_DiagnosisInfo>(); foreach (var diag in treatment.RelevantDiagnosis) { var diagnose = new L6TR_BT_2204_DiagnosisInfo(); diagnose.cDiagnosisState = diag.DiagnosisState_Abbreviation; diagnose.DiagnosisID = diag.HEC_Patient_Treatment_RelevantDiagnosisID; diagnose.strDiagnosisICD10 = diag.ICD10_Code; diagnose.PatientInsuranceState = diag.DiagnosisState_Name; diagnosies.Add(diagnose); } pos.DiagnosisInfo = diagnosies.ToArray(); positions.Add(pos); #endregion positionCountPerPatient[treatment2patient[id]] = positionCountPerPatient[treatment2patient[id]] + 1; i++; } returnValue.Result.Positions = positions.ToArray(); returnValue.Result.EDIFACTCounter = edifact.EDIFACTCounter; returnValue.Result.HeaderNumber = header.BillNumber; returnValue.Result.HeaderID = header.BIL_BillHeaderID; returnValue.Result.previousMaxPositionIndex = previousMaxPositionIndex; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OM_SM_0951 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var doctorQuery = new ORM_HEC_Doctor.Query(); doctorQuery.HEC_DoctorID = Parameter.Doctor_ID; var doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First(); var practicesQuery = new ORM_HEC_MedicalPractis.Query(); practicesQuery.HEC_MedicalPractiseID = Parameter.Practice_ID; var practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First(); var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query(); companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First(); var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practice_bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).FirstOrDefault(); ORM_CMN_BPT_Memo memo = new ORM_CMN_BPT_Memo(); if (Parameter.CMN_BPT_MemoID != Guid.Empty) { var result = memo.Load(Connection, Transaction, Parameter.CMN_BPT_MemoID); if (result.Status != FR_Status.Success || memo.CMN_BPT_MemoID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } memo.UpdatedBy_Account_RefID = securityTicket.AccountID; memo.UpdatedOn = Parameter.Creation_Timestamp; } else { ORM_DOC_Structure_Header docHeader = new ORM_DOC_Structure_Header(); docHeader.Label = Parameter.Memo_Abbreviation + "_Header_Label"; docHeader.Tenant_RefID = securityTicket.TenantID; docHeader.Save(Connection, Transaction); ORM_DOC_Structure docStructure = new ORM_DOC_Structure(); docStructure.Label = Parameter.Memo_Abbreviation + "_Structure"; docStructure.Tenant_RefID = securityTicket.TenantID; docStructure.Structure_Header_RefID = docHeader.DOC_Structure_HeaderID; docStructure.Save(Connection, Transaction); memo.DocumentStructureHeader_RefID = docHeader.DOC_Structure_HeaderID; memo.CreatedBy_Account_RefID = securityTicket.AccountID; memo.Creation_Timestamp = Parameter.Creation_Timestamp; memo.UpdatedOn = memo.Creation_Timestamp; } memo.Memo_Text = Parameter.Memo_Text; memo.Memo_Title = Parameter.Memo_Title; memo.Memo_Abbreviation = Parameter.Memo_Abbreviation; memo.Tenant_RefID = securityTicket.TenantID; memo.Save(Connection, Transaction); if (Parameter.AdditionalFields != null) { foreach (var AdditionalField in Parameter.AdditionalFields) { ORM_CMN_BPT_Memo_AdditionalField addFieldItem = new ORM_CMN_BPT_Memo_AdditionalField(); if (AdditionalField.CMN_BPT_Memo_AdditionalFieldID != Guid.Empty) { var result = addFieldItem.Load(Connection, Transaction, AdditionalField.CMN_BPT_Memo_AdditionalFieldID); if (result.Status != FR_Status.Success || addFieldItem.CMN_BPT_Memo_AdditionalFieldID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } addFieldItem.Memo_RefID = memo.CMN_BPT_MemoID; addFieldItem.Field_Key = AdditionalField.Field_Key; addFieldItem.Field_Value = AdditionalField.Field_Value; addFieldItem.Tenant_RefID = securityTicket.TenantID; addFieldItem.Save(Connection, Transaction); } } var memo2DocQuery = new ORM_CMN_BPT_Memo_RelatedParticipant.Query(); memo2DocQuery.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID; memo2DocQuery.CMN_BPT_Memo_RelatedParticipantID = doctor.BusinessParticipant_RefID; var memo2DocQueryRes = ORM_CMN_BPT_Memo_RelatedParticipant.Query.Search(Connection, Transaction, memo2DocQuery).FirstOrDefault(); ORM_CMN_BPT_Memo_RelatedParticipant memo2Doc; if (memo2DocQueryRes != null) { memo2Doc = memo2DocQueryRes; } else { memo2Doc = new ORM_CMN_BPT_Memo_RelatedParticipant(); memo2Doc.CMN_BPT_Memo_RelatedParticipantID = Guid.NewGuid(); } memo2Doc.Tenant_RefID = securityTicket.TenantID; memo2Doc.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID; memo2Doc.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID; memo2Doc.Save(Connection, Transaction); var memo2PracticeQuery = new ORM_CMN_BPT_Memo_RelatedParticipant.Query(); memo2DocQuery.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID; memo2DocQuery.CMN_BPT_Memo_RelatedParticipantID = practice_bParticipant.CMN_BPT_BusinessParticipantID; var memo2PracticeQueryRes = ORM_CMN_BPT_Memo_RelatedParticipant.Query.Search(Connection, Transaction, memo2DocQuery).FirstOrDefault(); ORM_CMN_BPT_Memo_RelatedParticipant memo2Practice; if (memo2DocQueryRes != null) { memo2Practice = memo2DocQueryRes; } else { memo2Practice = new ORM_CMN_BPT_Memo_RelatedParticipant(); memo2Practice.CMN_BPT_Memo_RelatedParticipantID = Guid.NewGuid(); } memo2Practice.Tenant_RefID = securityTicket.TenantID; memo2Practice.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID; memo2Practice.CMN_BPT_BusinessParticipant_RefID = practice_bParticipant.CMN_BPT_BusinessParticipantID; memo2Practice.Save(Connection, Transaction); returnValue.Result = memo.CMN_BPT_MemoID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OP_SP_1602 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); P_L2LN_GALFTID_1530 langParam = new P_L2LN_GALFTID_1530(); langParam.Tenant_RefID = securityTicket.TenantID; var languages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, langParam, securityTicket).Result; P_L3MP_SPBI_1602 basePracticeParam = new P_L3MP_SPBI_1602(); basePracticeParam.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID; basePracticeParam.Contact_EmergencyPhoneNumber = Parameter.PhoneNumber; basePracticeParam.Contact_Website_URL = Parameter.HomepageURL; basePracticeParam.PracticeEmail = Parameter.ContactEmail; basePracticeParam.PracticeName = Parameter.DisplyName; basePracticeParam.Region_Name = Parameter.AddressRegion; basePracticeParam.Street_Name = Parameter.AddressStreetName; basePracticeParam.Street_Number = Parameter.AddressStreetNumber; basePracticeParam.Town = Parameter.AddressCity; basePracticeParam.ZIP = Parameter.AddressZipCode; var practiceID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, basePracticeParam, securityTicket).Result; var practicesQuery = new ORM_HEC_MedicalPractis.Query(); practicesQuery.HEC_MedicalPractiseID = practiceID; var practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First(); var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query(); companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First(); var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).First(); ORM_CMN_BPT_BusinessParticipant bpContctPerson; if (practices.ContactPerson_RefID != Guid.Empty) { var bpContctPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bpContctPersonQuery.CMN_BPT_BusinessParticipantID = practices.ContactPerson_RefID; bpContctPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bpContctPersonQuery).First(); } else { bpContctPerson = new ORM_CMN_BPT_BusinessParticipant(); bpContctPerson.Tenant_RefID = securityTicket.TenantID; bpContctPerson.IsNaturalPerson = true; } bpContctPerson.DisplayName = Parameter.ContactPerson_Name; bpContctPerson.Save(Connection, Transaction); practices.ContactPerson_RefID = bpContctPerson.CMN_BPT_BusinessParticipantID; ORM_CMN_CAL_WeeklyOfficeHours_Template officeHours; ORM_CMN_CAL_WeeklyOfficeHours_Template consultingHours; if (practices.WeeklyOfficeHours_Template_RefID != Guid.Empty && practices.WeeklySurgeryHours_Template_RefID != Guid.Empty) { var officeHoursQuery = new ORM_CMN_CAL_WeeklyOfficeHours_Template.Query(); officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = practices.WeeklyOfficeHours_Template_RefID; officeHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First(); officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = practices.WeeklySurgeryHours_Template_RefID; consultingHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First(); } else { officeHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template(); officeHours.CMN_CAL_WeeklyOfficeHours_TemplateID = Guid.NewGuid(); consultingHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template(); consultingHours.CMN_CAL_WeeklyOfficeHours_TemplateID = Guid.NewGuid(); practices.WeeklyOfficeHours_Template_RefID = officeHours.CMN_CAL_WeeklyOfficeHours_TemplateID; practices.WeeklySurgeryHours_Template_RefID = consultingHours.CMN_CAL_WeeklyOfficeHours_TemplateID; } consultingHours.Tenant_RefID = securityTicket.TenantID; officeHours.Tenant_RefID = securityTicket.TenantID; consultingHours.FormattedOfficeHours = Parameter.Consultation_FormattedOfficeHours; officeHours.FormattedOfficeHours = Parameter.Working_FormattedOfficeHours; consultingHours.Save(Connection, Transaction); officeHours.Save(Connection, Transaction); ORM_CMN_COM_CompanyInfo_Type companyType; var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query(); companyTypeQuery.IsDeleted = false; companyTypeQuery.CMN_COM_CompanyInfo_TypeID = Parameter.PracticeType_RefID; companyType = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery).FirstOrDefault(); if (companyType == null) { companyType = new ORM_CMN_COM_CompanyInfo_Type(); companyType.CMN_COM_CompanyInfo_TypeID = Parameter.PracticeType_RefID; companyType.CompanyType_Name = new Dict(); companyType.CompanyType_Name.DictionaryID = Guid.NewGuid(); if (languages != null) { foreach (var item in languages) { companyType.CompanyType_Name.AddEntry(item.CMN_LanguageID, STLD_PracticeType.typesItems.First(t => t.Value == Parameter.PracticeType_RefID).Text); } } } companyInfo.CompanyType_RefID = Parameter.PracticeType_RefID; ORM_HEC_PublicHealthcare_PhysitianAssociation pHealthcare; var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query(); pHealthcareQuery.HEC_PublicHealthcare_PhysitianAssociationID = Parameter.HealthAssociation_RefID; pHealthcare = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery).FirstOrDefault(); if (pHealthcare == null) { pHealthcare = new ORM_HEC_PublicHealthcare_PhysitianAssociation(); pHealthcare.HEC_PublicHealthcare_PhysitianAssociationID = Parameter.HealthAssociation_RefID; pHealthcare.HealthAssociation_Name = STLD_MedicalAssociation.associationItems.First(t => t.Value == Parameter.HealthAssociation_RefID).Text; pHealthcare.Save(Connection, Transaction); } practices.AssociatedWith_PhysitianAssociation_RefID = Parameter.HealthAssociation_RefID; ORM_CMN_BPT_CTM_Customer customer; var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery); if (customerRes.Count == 0) { customer = new ORM_CMN_BPT_CTM_Customer(); customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; } else { customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First(); } var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query(); affinityStatusQuery.CMN_BPT_CTM_AffinityStatusID = Parameter.AffinityStatus_RefID; var affinityStatus = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery).FirstOrDefault(); if (affinityStatus == null) { affinityStatus = new ORM_CMN_BPT_CTM_AffinityStatus(); affinityStatus.CMN_BPT_CTM_AffinityStatusID = Parameter.AffinityStatus_RefID; affinityStatus.AffinityStatus_Name = new Dict(); affinityStatus.AffinityStatus_Name.DictionaryID = Guid.NewGuid(); if (languages != null) { foreach (var item in languages) { affinityStatus.AffinityStatus_Name.AddEntry(item.CMN_LanguageID, STLD_AffinityStatus.affinityItems.First(t => t.Value == Parameter.AffinityStatus_RefID).Text); } } affinityStatus.Save(Connection, Transaction); } customer.CustomerAffinityStatus_RefID = Parameter.AffinityStatus_RefID; customer.Tenant_RefID = securityTicket.TenantID; customer.Save(Connection, Transaction); ORM_CMN_COM_CompanyInfo_Address compAddress; ORM_CMN_UniversalContactDetail address; var compAddressQuery = new ORM_CMN_COM_CompanyInfo_Address.Query(); compAddressQuery.Tenant_RefID = securityTicket.TenantID; compAddressQuery.CompanyInfo_RefID = practices.Ext_CompanyInfo_RefID; var compAddressRes = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, compAddressQuery); if (compAddressRes.Count > 0) { compAddress = compAddressRes.First(); var addressQuery = new ORM_CMN_UniversalContactDetail.Query(); addressQuery.CMN_UniversalContactDetailID = compAddress.Address_UCD_RefID; address = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, addressQuery).First(); } else { compAddress = new ORM_CMN_COM_CompanyInfo_Address(); compAddress.CMN_COM_CompanyInfo_AddressID = Guid.NewGuid(); compAddress.IsShipping = true; compAddress.CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; address = new ORM_CMN_UniversalContactDetail(); address.CMN_UniversalContactDetailID = Guid.NewGuid(); compAddress.Address_UCD_RefID = address.CMN_UniversalContactDetailID; } address.Town = Parameter.ShippingAddressCity; address.Street_Number = Parameter.ShippingAddressStreetNumber; address.Street_Name = Parameter.ShippingAddressStreetName; address.ZIP = Parameter.ShippingAddressZipCode; address.Region_Name = Parameter.ShippingAddressRegion; address.Tenant_RefID = securityTicket.TenantID; address.Save(Connection, Transaction); compAddress.Tenant_RefID = securityTicket.TenantID; compAddress.Save(Connection, Transaction); ORM_CMN_BPT_BusinessParticipant contactPBP; if (practices.ContactPerson_RefID != Guid.Empty) { var contactPBPQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); contactPBPQuery.CMN_BPT_BusinessParticipantID = practices.ContactPerson_RefID; contactPBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, contactPBPQuery).First(); } else { contactPBP = new ORM_CMN_BPT_BusinessParticipant(); contactPBP.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); contactPBP.IsCompany = true; practices.ContactPerson_RefID = contactPBP.CMN_BPT_BusinessParticipantID; } contactPBP.DisplayName = Parameter.ContactPerson_Name; contactPBP.Tenant_RefID = securityTicket.TenantID; contactPBP.Save(Connection, Transaction); companyInfo.Save(Connection, Transaction); practices.Save(Connection, Transaction); returnValue.Result = practices.HEC_MedicalPractiseID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_SMP__1122 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); if (Parameter.isDeleted == true) { P_L3MP_DPBID_1026 param = new P_L3MP_DPBID_1026(); param.HEC_MedicalPractiseID = Parameter.PracticeID; cls_Delete_Practice_By_ID.Invoke(Connection, Transaction, param, securityTicket); } else { #region Save if (Parameter.PracticeID == Guid.Empty) { /********************************* * Save ContactPerson ********************************/ //business Participants ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant(); Guid businessParticipantsID = Guid.NewGuid(); contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantsID; contactPerson.IsCompany = false; contactPerson.IsNaturalPerson = true; contactPerson.IsTenant = false; contactPerson.Creation_Timestamp = DateTime.Now; contactPerson.Tenant_RefID = securityTicket.TenantID; //person info ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); Guid personInfoID = Guid.NewGuid(); contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; contactPerson.Save(Connection, Transaction); personInfo.CMN_PER_PersonInfoID = personInfoID; personInfo.FirstName = Parameter.ContactPersonFirstName; personInfo.LastName = Parameter.ContactPersonLastName; personInfo.PrimaryEmail = Parameter.ContactPersonEmail; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.Save(Connection, Transaction); //Communication Contact ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfoID; communicationContacts.Contact_Type = Parameter.ContactTypePhone; communicationContacts.Content = Parameter.ContactPersonPhoneNumber; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); /********************************* * Save Practice ********************************/ P_L3MP_SPBI_1602 param = new P_L3MP_SPBI_1602(); param.Street_Number = Parameter.PracticeNumber; param.Street_Name = Parameter.PracticeStreet; param.Street_Name_Line2 = Parameter.PracticeStreet2; param.PracticeName = Parameter.PracticeName; param.isLucentis = true; param.ifLucentis_BSNR = Parameter.BSNR; param.PracticeEmail = Parameter.PracitceEmail; param.Town = Parameter.Town; param.ZIP = Parameter.ZIP; param.HEC_MedicalPractiseID = Parameter.PracticeID; Guid HEC_MedicalPractiseID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, param, securityTicket).Result; /********************************* * Save Cooperating Practices ********************************/ var queryMedicalPractice = new ORM_HEC_MedicalPractis.Query(); queryMedicalPractice.HEC_MedicalPractiseID = HEC_MedicalPractiseID; queryMedicalPractice.IsDeleted = false; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, queryMedicalPractice).FirstOrDefault(); if (medicalPractice != null) { medicalPractice.ContactPerson_RefID = businessParticipantsID; medicalPractice.Save(Connection, Transaction); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; queryCompanyInfo.IsDeleted = false; var CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).FirstOrDefault(); if (CompanyInfo != null) { var queryBussinessParticipients = new ORM_CMN_BPT_BusinessParticipant.Query(); queryBussinessParticipients.IfCompany_CMN_COM_CompanyInfo_RefID = CompanyInfo.CMN_COM_CompanyInfoID; queryBussinessParticipients.IsDeleted = false; var bussinessParticipants = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, queryBussinessParticipients).FirstOrDefault(); if (bussinessParticipants != null) { foreach (var cooperatingPractice in Parameter.CooperatingPractices) { ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBussinessParticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedBussinessParticipants.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); associatedBussinessParticipants.IsDeleted = cooperatingPractice.isDeleted; associatedBussinessParticipants.BusinessParticipant_RefID = bussinessParticipants.CMN_BPT_BusinessParticipantID; associatedBussinessParticipants.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID; associatedBussinessParticipants.Creation_Timestamp = DateTime.Now; associatedBussinessParticipants.Tenant_RefID = bussinessParticipants.Tenant_RefID; associatedBussinessParticipants.Save(Connection, Transaction); } } } returnValue.Result = medicalPractice.HEC_MedicalPractiseID; } } #endregion else { /********************************* * Edit Practice ********************************/ P_L3MP_SPBI_1602 param = new P_L3MP_SPBI_1602(); param.Street_Number = Parameter.PracticeNumber; param.Street_Name = Parameter.PracticeStreet; param.Street_Name_Line2 = Parameter.PracticeStreet2; param.PracticeName = Parameter.PracticeName; param.isLucentis = true; param.ifLucentis_BSNR = Parameter.BSNR; param.PracticeEmail = Parameter.PracitceEmail; param.Town = Parameter.Town; param.ZIP = Parameter.ZIP; param.HEC_MedicalPractiseID = Parameter.PracticeID; Guid HEC_MedicalPractiseID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, param, securityTicket).Result; var medicalPracticeQuery = new ORM_HEC_MedicalPractis.Query(); medicalPracticeQuery.IsDeleted = false; medicalPracticeQuery.HEC_MedicalPractiseID = HEC_MedicalPractiseID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medicalPracticeQuery).FirstOrDefault(); if (medicalPractice != null) { /********************************* * Edit Contact Person ********************************/ //contact person var contactPerson = new ORM_CMN_BPT_BusinessParticipant(); var contactPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); contactPersonQuery.IsDeleted = false; if (medicalPractice.ContactPerson_RefID != Guid.Empty) { contactPersonQuery.CMN_BPT_BusinessParticipantID = medicalPractice.ContactPerson_RefID; contactPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, contactPersonQuery).FirstOrDefault(); } else { contactPerson = null; } Guid personInfoID = Guid.NewGuid(); if (contactPerson == null) { contactPerson = new ORM_CMN_BPT_BusinessParticipant(); contactPerson.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); contactPerson.IsCompany = false; contactPerson.IsNaturalPerson = true; contactPerson.IsTenant = false; contactPerson.Creation_Timestamp = DateTime.Now; contactPerson.Tenant_RefID = securityTicket.TenantID; contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; contactPerson.Save(Connection, Transaction); medicalPractice.ContactPerson_RefID = contactPerson.CMN_BPT_BusinessParticipantID; medicalPractice.Save(Connection, Transaction); } var personInfo = new ORM_CMN_PER_PersonInfo(); //person info var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query(); personInfoQuery.IsDeleted = false; personInfoQuery.CMN_PER_PersonInfoID = contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID; personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).FirstOrDefault(); if (personInfo == null) { personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.CMN_PER_PersonInfoID = personInfoID; contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; contactPerson.Save(Connection, Transaction); } personInfo.FirstName = Parameter.ContactPersonFirstName; personInfo.LastName = Parameter.ContactPersonLastName; personInfo.PrimaryEmail = Parameter.ContactPersonEmail; personInfo.Save(Connection, Transaction); //Communication Contact var communicationContacts = new ORM_CMN_PER_CommunicationContact(); var communicationContactsQuery = new ORM_CMN_PER_CommunicationContact.Query(); communicationContactsQuery.IsDeleted = false; communicationContactsQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactsQuery).FirstOrDefault(); if (communicationContacts == null) { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; } communicationContacts.Contact_Type = Parameter.ContactTypePhone; communicationContacts.Content = Parameter.ContactPersonPhoneNumber; communicationContacts.Save(Connection, Transaction); /********************************* * Edit Cooperating Practices ********************************/ var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; queryCompanyInfo.IsDeleted = false; var CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).FirstOrDefault(); if (CompanyInfo != null) { var queryBussinessParticipients = new ORM_CMN_BPT_BusinessParticipant.Query(); queryBussinessParticipients.IfCompany_CMN_COM_CompanyInfo_RefID = CompanyInfo.CMN_COM_CompanyInfoID; queryBussinessParticipients.IsDeleted = false; var bussinessParticipants = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, queryBussinessParticipients).FirstOrDefault(); if (bussinessParticipants != null) { foreach (var cooperatingPractice in Parameter.CooperatingPractices) { var associatedBussinessParticipantsQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); associatedBussinessParticipantsQuery.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID; associatedBussinessParticipantsQuery.Tenant_RefID = bussinessParticipants.Tenant_RefID; associatedBussinessParticipantsQuery.BusinessParticipant_RefID = bussinessParticipants.CMN_BPT_BusinessParticipantID; var associtePractice = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBussinessParticipantsQuery).FirstOrDefault(); if (associtePractice != null) { associtePractice.IsDeleted = cooperatingPractice.isDeleted; associtePractice.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID; associtePractice.Save(Connection, Transaction); } else { ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBussinessParticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedBussinessParticipants.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); associatedBussinessParticipants.IsDeleted = cooperatingPractice.isDeleted; associatedBussinessParticipants.BusinessParticipant_RefID = bussinessParticipants.CMN_BPT_BusinessParticipantID; associatedBussinessParticipants.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID; associatedBussinessParticipants.Creation_Timestamp = DateTime.Now; associatedBussinessParticipants.Tenant_RefID = bussinessParticipants.Tenant_RefID; associatedBussinessParticipants.Save(Connection, Transaction); } } } } returnValue.Result = medicalPractice.HEC_MedicalPractiseID; } } } return(returnValue); #endregion UserCode }
protected static FR_L5MD_GDwPfID_1414 Execute(DbConnection Connection, DbTransaction Transaction, P_L5MD_GDwPfID_1414 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5MD_GDwPfID_1414(); P_L3MD_GDBIfID_1150 biParam = new P_L3MD_GDBIfID_1150(); biParam.DoctorID = Parameter.DoctorID; var baseInfo = cls_Get_Doctor_BaseInfo_byID.Invoke(Connection, Transaction, biParam, securityTicket).Result; returnValue.Result = new L5MD_GDwPfID_1414(); returnValue.Result.BaseInfo = baseInfo; P_L3DAC_RACDbBPID_1056 aiParam = new P_L3DAC_RACDbBPID_1056(); aiParam.BPrticipantID = baseInfo.Doctor_CMN_BPT_BusinessParticipantID; var accInfo = cls_Retrive_Account_Code_Details_byBParticipantID.Invoke(Connection, Transaction, aiParam, securityTicket).Result; if (accInfo != null) { var AccountInfo = new L5MD_GDwPfID_1414_AccountInfo(); AccountInfo.AccountCode_ValidFrom = accInfo.AccountCode_ValidFrom; AccountInfo.AccountCode_Value = accInfo.AccountCode_Value; AccountInfo.USR_AccountID = baseInfo.Account_RefID; AccountInfo.USR_Device_AccountCodeID = accInfo.USR_Device_AccountCodeID; returnValue.Result.AccountInfo = AccountInfo; } var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.Ext_BusinessParticipant_RefID = baseInfo.Doctor_CMN_BPT_BusinessParticipantID; customerQuery.IsDeleted = false; var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery); if (customerRes.Count > 0) { var ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query(); ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery.Customer_RefID = customerRes.First().CMN_BPT_CTM_CustomerID; ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery.IsDeleted = false; var ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative1 = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery).First(); returnValue.Result.SalesRepresentative = new L5MD_GDwPfID_1414_SalesRepresentative(); returnValue.Result.SalesRepresentative.SalesRepresentative_RefID = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative1.SalesRepresentative_RefID; } var assocBPQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); assocBPQuery.BusinessParticipant_RefID = baseInfo.Doctor_CMN_BPT_BusinessParticipantID; assocBPQuery.IsDeleted = false; var assocBPQs = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, assocBPQuery).ToArray(); if (assocBPQs.Length > 0) { assocBPQs = assocBPQs.OrderBy(a => a.Creation_Timestamp).ToArray(); var assocBPQ = assocBPQs.First(); var practiceBPQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceBPQuery.CMN_BPT_BusinessParticipantID = assocBPQ.AssociatedBusinessParticipant_RefID; var practiceBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceBPQuery).First(); var companInfoQuery = new ORM_CMN_COM_CompanyInfo.Query(); companInfoQuery.CMN_COM_CompanyInfoID = practiceBP.IfCompany_CMN_COM_CompanyInfo_RefID; var companInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companInfoQuery).First(); var practiceQuery = new ORM_HEC_MedicalPractis.Query(); practiceQuery.Ext_CompanyInfo_RefID = companInfo.CMN_COM_CompanyInfoID; var prac = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practiceQuery).First(); P_L3MP_GPfID_1222 pbiParam = new P_L3MP_GPfID_1222(); pbiParam.HEC_MedicalPractiseID = prac.HEC_MedicalPractiseID; var practiceBasInfo = cls_Get_Practice_For_ID.Invoke(Connection, Transaction, pbiParam, securityTicket).Result; if (practiceBasInfo != null) { L5MD_GDwPfID_1414_Practice practice = new L5MD_GDwPfID_1414_Practice(); practice.AssociatedParticipant_FunctionName = assocBPQ.AssociatedParticipant_FunctionName; practice.CMN_BPT_BusinessParticipantID = practiceBasInfo.BaseInfo.CMN_BPT_BusinessParticipantID; if (practiceBasInfo.OtherOphthal_PracticeData != null) { practice.HealthAssociation_Name = practiceBasInfo.OtherOphthal_PracticeData.HealthAssociation_Name; } practice.PracticeID = practiceBasInfo.BaseInfo.HEC_MedicalPractiseID; practice.PracticeName = practiceBasInfo.BaseInfo.PracticeName; practice.Region_Name = practiceBasInfo.BaseInfo.Region_Name; practice.Street_Name = practiceBasInfo.BaseInfo.Street_Name; practice.Street_Number = practiceBasInfo.BaseInfo.Street_Number; practice.Town = practiceBasInfo.BaseInfo.Town; practice.ZIP = practiceBasInfo.BaseInfo.ZIP; returnValue.Result.Practice = practice; } } return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MP_SPBI_1602 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); ORM_HEC_MedicalPractis practices; if (Parameter.HEC_MedicalPractiseID != Guid.Empty) { var practicesQuery = new ORM_HEC_MedicalPractis.Query(); practicesQuery.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID; practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First(); } else { practices = new ORM_HEC_MedicalPractis(); practices.HEC_MedicalPractiseID = Guid.NewGuid(); } practices.Tenant_RefID = securityTicket.TenantID; if (Parameter.isLucentis == false) { practices.Contact_EmergencyPhoneNumber = Parameter.Contact_EmergencyPhoneNumber; } ORM_CMN_COM_CompanyInfo companyInfo; if (practices.Ext_CompanyInfo_RefID != Guid.Empty) { var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query(); companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID; companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First(); } else { companyInfo = new ORM_CMN_COM_CompanyInfo(); companyInfo.CMN_COM_CompanyInfoID = Guid.NewGuid(); practices.Ext_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; } companyInfo.Tenant_RefID = securityTicket.TenantID; if (Parameter.isLucentis) { companyInfo.CompanyInfo_EstablishmentNumber = Parameter.ifLucentis_BSNR; } ORM_CMN_BPT_BusinessParticipant bParticipant; var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var bpRes = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery); if (bpRes.Count == 0) { bParticipant = new ORM_CMN_BPT_BusinessParticipant(); bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bParticipant.IsCompany = true; bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; } else { bParticipant = bpRes.First(); } bParticipant.DisplayName = Parameter.PracticeName; bParticipant.Tenant_RefID = securityTicket.TenantID; ORM_CMN_UniversalContactDetail contactDetails; if (companyInfo.Contact_UCD_RefID != Guid.Empty) { var ucdQuery = new ORM_CMN_UniversalContactDetail.Query(); ucdQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID; contactDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, ucdQuery).First(); } else { contactDetails = new ORM_CMN_UniversalContactDetail(); contactDetails.CMN_UniversalContactDetailID = Guid.NewGuid(); companyInfo.Contact_UCD_RefID = contactDetails.CMN_UniversalContactDetailID; contactDetails.IsCompany = true; } contactDetails.Tenant_RefID = securityTicket.TenantID; if (Parameter.isLucentis == false) { contactDetails.Contact_Website_URL = Parameter.Contact_Website_URL; } contactDetails.Contact_Email = Parameter.PracticeEmail; contactDetails.Town = Parameter.Town; contactDetails.Street_Number = Parameter.Street_Number; contactDetails.Street_Name = Parameter.Street_Name; contactDetails.ZIP = Parameter.ZIP; if (Parameter.isLucentis == false) { contactDetails.Region_Name = Parameter.Region_Name; } if (Parameter.isLucentis) { contactDetails.Street_Name_Line2 = Parameter.Street_Name_Line2; } companyInfo.Save(Connection, Transaction); bParticipant.Save(Connection, Transaction); contactDetails.Save(Connection, Transaction); practices.Save(Connection, Transaction); returnValue.Result = practices.HEC_MedicalPractiseID; return(returnValue); #endregion UserCode }