Пример #1
0
        protected static FR_L3MD_GDwPfT_1404_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3MD_GDwPfT_1404_Array();

            var basicInfos = cls_Get_Doctor_BaseInfo_withPractice_forTenant.Invoke(Connection, Transaction, securityTicket).Result;
            var accs       = cls_Retrive_Account_Code_Details_forTenant.Invoke(Connection, Transaction, securityTicket).Result;

            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Tenant_RefID = securityTicket.TenantID;
            customerQuery.IsDeleted    = false;
            var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);

            var ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
            ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery.Tenant_RefID = securityTicket.TenantID;
            ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery.IsDeleted    = false;
            var cust2SalesRespRes = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, ORM_CMN_BPT_CTM_Customer_2_SalesRepresentativeQuery);

            List <L3MD_GDwPfT_1404> retVal = new List <L3MD_GDwPfT_1404>();
            foreach (var item in basicInfos)
            {
                var doc = new L3MD_GDwPfT_1404();
                doc.BaseInfo = item;

                if (item.Account_RefID != Guid.Empty)
                {
                    var accountInfo = accs.FirstOrDefault(a => a.BusinessParticipant_RefID == item.Doctor_CMN_BPT_BusinessParticipantID);
                    if (accountInfo != null)
                    {
                        doc.AccountInfo = new L3MD_GDwPfT_1404_AccountInfo();
                        doc.AccountInfo.AccountCode_ValidFrom    = accountInfo.AccountCode_ValidFrom;
                        doc.AccountInfo.AccountCode_Value        = accountInfo.AccountCode_Value;
                        doc.AccountInfo.USR_AccountID            = accountInfo.Account_RefID;
                        doc.AccountInfo.USR_Device_AccountCodeID = accountInfo.USR_Device_AccountCodeID;
                    }

                    var customer = customerRes.FirstOrDefault(c => c.Ext_BusinessParticipant_RefID == item.Doctor_CMN_BPT_BusinessParticipantID);
                    if (customer != null)
                    {
                        var c2SalesResp = cust2SalesRespRes.FirstOrDefault(sr => sr.Customer_RefID == customer.CMN_BPT_CTM_CustomerID);
                        if (c2SalesResp != null)
                        {
                            doc.SalesRepresentative = new L3MD_GDwPfT_1404_SalesRepresentative();
                            doc.SalesRepresentative.SalesRepresentative_RefID = c2SalesResp.SalesRepresentative_RefID;
                        }
                    }
                }

                retVal.Add(doc);
            }
            returnValue.Result = retVal.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Пример #2
0
        protected static FR_L5OD_GLDfT_1111_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5OD_GLDfT_1111_Array();

            var basicInfos = cls_Get_Doctor_BaseInfo_forTenant.Invoke(Connection, Transaction, securityTicket).Result;

            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Tenant_RefID = securityTicket.TenantID;
            var customers = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);

            var customer2SRQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
            customer2SRQuery.Tenant_RefID = securityTicket.TenantID;
            var customer2SRs = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, customer2SRQuery);

            List <L5OD_GLDfT_1111> retVal = new List <L5OD_GLDfT_1111>();
            foreach (var item in basicInfos)
            {
                var doc = new L5OD_GLDfT_1111();
                doc.BaseInfo     = item;
                doc.FirstName    = item.FirstName;
                doc.LastName     = item.LastName;
                doc.HEC_DoctorID = item.HEC_DoctorID;
                doc.Title        = item.Title;

                var customer = customers.FirstOrDefault(c => c.Ext_BusinessParticipant_RefID == item.Doctor_CMN_BPT_BusinessParticipantID);
                if (customer != null)
                {
                    var c2sr = customer2SRs.FirstOrDefault(c => c.Customer_RefID == customer.CMN_BPT_CTM_CustomerID);
                    if (c2sr != null)
                    {
                        doc.SalesRepresentative = new L5OD_GLDfT_1111_SalesRepresentative();
                        doc.SalesRepresentative.SalesRepresentative_RefID = c2sr.SalesRepresentative_RefID;
                    }
                }

                retVal.Add(doc);
            }
            returnValue.Result = retVal.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Пример #3
0
        protected static FR_L3MP_GPfT_1209_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3MP_GPfT_1209_Array();

            List <L3MP_GPfT_1209> res = new List <L3MP_GPfT_1209>();

            var baseInfos = cls_Get_Practice_BaseInfo_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            var contactsP = cls_Get_Practice_ContactPerson_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;

            var officeHoursQuery = new ORM_CMN_CAL_WeeklyOfficeHours_Template.Query();
            officeHoursQuery.IsDeleted    = false;
            officeHoursQuery.Tenant_RefID = securityTicket.TenantID;
            var officeHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery);

            var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query();
            companyTypeQuery.IsDeleted    = false;
            companyTypeQuery.Tenant_RefID = securityTicket.TenantID;
            var companyTypes = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery);

            var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query();
            pHealthcareQuery.Tenant_RefID = securityTicket.TenantID;
            var pHealthcares = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery);

            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Tenant_RefID = securityTicket.TenantID;
            var customers           = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);
            var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query();
            affinityStatusQuery.Tenant_RefID = securityTicket.TenantID;
            var affinityStatuses = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery);

            var compAddressQuery = new ORM_CMN_COM_CompanyInfo_Address.Query();
            compAddressQuery.Tenant_RefID = securityTicket.TenantID;
            compAddressQuery.IsShipping   = true;
            compAddressQuery.IsDeleted    = false;
            var compAddresses = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, compAddressQuery);
            var addressQuery  = new ORM_CMN_UniversalContactDetail.Query();
            addressQuery.Tenant_RefID = securityTicket.TenantID;
            addressQuery.IsDeleted    = false;
            var addresses = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, addressQuery);

            foreach (var bInfo in baseInfos)
            {
                L3MP_GPfT_1209 practice = new L3MP_GPfT_1209();
                practice.BaseInfo = bInfo;
                if (bInfo.ContactPerson_RefID != null)
                {
                    var contactPerson = contactsP.FirstOrDefault(c => c.CMN_BPT_BusinessParticipantID == bInfo.ContactPerson_RefID);
                    practice.ContactPerson = contactPerson;
                }

                if (bInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty && bInfo.WeeklySurgeryHours_Template_RefID != Guid.Empty)
                {
                    var oHours = officeHours.FirstOrDefault(o => o.CMN_CAL_WeeklyOfficeHours_TemplateID == bInfo.WeeklyOfficeHours_Template_RefID);
                    var cHours = officeHours.FirstOrDefault(o => o.CMN_CAL_WeeklyOfficeHours_TemplateID == bInfo.WeeklySurgeryHours_Template_RefID);
                    if (oHours != null && cHours != null)
                    {
                        practice.OfficeHours = new L3MP_GPfT_1209_OfficeHours();
                        practice.OfficeHours.ConsultingHours_FormattedOfficeHours = cHours.FormattedOfficeHours;
                        practice.OfficeHours.WorkingHours_FormattedOfficeHours    = oHours.FormattedOfficeHours;
                    }
                }
                if (bInfo.CompanyType_RefID != Guid.Empty)
                {
                    practice.OtherOphthal_PracticeData = new L3MP_GPfT_1209_OtherOphthal_PracticeData();
                    var company = companyTypes.FirstOrDefault(c => c.CMN_COM_CompanyInfo_TypeID == bInfo.CompanyType_RefID);
                    if (company != null)
                    {
                        practice.OtherOphthal_PracticeData.CompanyType_Name           = company.CompanyType_Name;
                        practice.OtherOphthal_PracticeData.CMN_COM_CompanyInfo_TypeID = company.CMN_COM_CompanyInfo_TypeID;
                    }

                    var pHealthcare = pHealthcares.FirstOrDefault(c => c.HEC_PublicHealthcare_PhysitianAssociationID == bInfo.AssociatedWith_PhysitianAssociation_RefID);
                    if (pHealthcare != null)
                    {
                        practice.OtherOphthal_PracticeData.HealthAssociation_Name = pHealthcare.HealthAssociation_Name;
                        practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID = pHealthcare.HEC_PublicHealthcare_PhysitianAssociationID;
                    }
                }

                var customer = customers.FirstOrDefault(c => c.Ext_BusinessParticipant_RefID == bInfo.CMN_BPT_BusinessParticipantID);
                if (customer != null)
                {
                    var affinityStatus = affinityStatuses.FirstOrDefault(a => a.CMN_BPT_CTM_AffinityStatusID == customer.CustomerAffinityStatus_RefID);
                    if (affinityStatus != null)
                    {
                        practice.OtherOphthal_PracticeData.CMN_BPT_CTM_AffinityStatusID = affinityStatus.CMN_BPT_CTM_AffinityStatusID;
                        practice.OtherOphthal_PracticeData.AffinityStatus_Name          = affinityStatus.AffinityStatus_Name;
                    }
                }

                var compAddress = compAddresses.FirstOrDefault(ca => ca.CompanyInfo_RefID == bInfo.CMN_COM_CompanyInfoID);
                if (compAddress != null)
                {
                    var address = addresses.FirstOrDefault(a => a.CMN_UniversalContactDetailID == compAddress.Address_UCD_RefID);
                    if (address != null)
                    {
                        practice.ShippingAddress = new L3MP_GPfT_1209_ShippingAddress();
                        practice.ShippingAddress.CMN_UniversalContactDetailID  = address.CMN_UniversalContactDetailID;
                        practice.ShippingAddress.CMN_COM_CompanyInfo_AddressID = compAddress.CMN_COM_CompanyInfo_AddressID;
                        practice.ShippingAddress.Region_Name   = address.Region_Name;
                        practice.ShippingAddress.Street_Name   = address.Street_Name;
                        practice.ShippingAddress.Street_Number = address.Street_Number;
                        practice.ShippingAddress.Town          = address.Town;
                        practice.ShippingAddress.ZIP           = address.ZIP;
                    }
                }

                res.Add(practice);
            }

            returnValue.Result = res.ToArray();

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_L5BD_SCDP_1347 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guids();
            //Put your code here

            var savedProcesses = new List <Guid>();

            foreach (var billHeaderID in Parameter.BIL_BillHeaderIDs.ToList())
            {
                #region Prerequisites

                var billHeader = new ORM_BIL_BillHeader();
                billHeader.Load(Connection, Transaction, billHeaderID);

                //assigned payments
                var assignedPaymentsQuery = new ORM_BIL_BillHeader_AssignedPayment.Query();
                assignedPaymentsQuery.BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID;
                assignedPaymentsQuery.Tenant_RefID         = securityTicket.TenantID;
                var foundAssignmentPayments = ORM_BIL_BillHeader_AssignedPayment.Query.Search(Connection, Transaction, assignedPaymentsQuery);

                //calculated sum of payments to the present day
                var paymentsSummForCurrentDate = foundAssignmentPayments.Where(fap => fap.Creation_Timestamp <= DateTime.Now).Sum(x => x.AssignedValue);

                //customer
                var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQuery.Tenant_RefID = securityTicket.TenantID;
                customerQuery.Ext_BusinessParticipant_RefID = billHeader.BillRecipient_BuisnessParticipant_RefID;
                var foundCustomer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).Single();

                //Model
                ORM_ACC_DUN_Dunning_Model.Query defaultDunningModelQuery = new ORM_ACC_DUN_Dunning_Model.Query();
                defaultDunningModelQuery.Tenant_RefID           = securityTicket.TenantID;
                defaultDunningModelQuery.IsDefaultCustomerModel = true;
                var foundDunningModel = ORM_ACC_DUN_Dunning_Model.Query.Search(Connection, Transaction, defaultDunningModelQuery).SingleOrDefault();

                //Assignment to levels
                var modelToLevelsAssignmentQuery = new ORM_ACC_DUN_DunningLevel_ModelAssignment.Query();
                modelToLevelsAssignmentQuery.Dunning_Model_RefID = foundDunningModel.ACC_DUN_Dunning_ModelID;
                modelToLevelsAssignmentQuery.Tenant_RefID        = securityTicket.TenantID;
                var foundModelToLevelsAssignments = ORM_ACC_DUN_DunningLevel_ModelAssignment.Query.Search(Connection, Transaction, modelToLevelsAssignmentQuery);

                var minimalLevelInSequence = foundModelToLevelsAssignments.OrderBy(la => la.OrderSequence).First();



                //Levels
                var dunningLevels = new ORM_ACC_DUN_Dunning_Level();
                //dunningLevels.Load(Connection, Transaction, foundModelToLevelsAssignment.Dunning_Level_RefID);

                #endregion

                //model to customer assignment
                var modelToCustomerAssignment = new ORM_ACC_DUN_Dunning_Model_2_Customer();
                modelToCustomerAssignment.Tenant_RefID = securityTicket.TenantID;
                modelToCustomerAssignment.ACC_DUN_DunningModel_RefID = foundDunningModel.ACC_DUN_Dunning_ModelID;
                modelToCustomerAssignment.CMN_BPT_CTM_Customer_RefID = foundCustomer.CMN_BPT_CTM_CustomerID;
                var savedModelToCustomerAssignmentID = new FR_Guid(modelToCustomerAssignment.Save(Connection, Transaction), modelToCustomerAssignment.AssignmentID);

                //dunning process
                P_L2BD_SADDP_1412 saveDunningProcessParameter = new P_L2BD_SADDP_1412();
                saveDunningProcessParameter.DunnedCustomer_RefID          = foundCustomer.CMN_BPT_CTM_CustomerID;
                saveDunningProcessParameter.DunningModel_RefID            = foundDunningModel.ACC_DUN_Dunning_ModelID;
                saveDunningProcessParameter.Current_DunningLevel_RefID    = minimalLevelInSequence.Dunning_Level_RefID;
                saveDunningProcessParameter.DunnedAmount_Total            = billHeader.TotalValue_BeforeTax - paymentsSummForCurrentDate;
                saveDunningProcessParameter.Currency_RefID                = billHeader.Currency_RefID;
                saveDunningProcessParameter.ReachesNextDunningLevelAtDate = DateTime.Now.AddDays(minimalLevelInSequence.WaitPeriodToNextDunningLevel_In_Days);

                var savedDunningProcessID = cls_Save_ACC_DUN_DunningProcess.Invoke(Connection, Transaction, saveDunningProcessParameter, securityTicket).Result;

                //dunning process member bills
                P_L2BD_SADDPMB_1359 saveMemberBillsParameter = new P_L2BD_SADDPMB_1359();
                saveMemberBillsParameter.BIL_BillHeader_RefID         = billHeaderID;
                saveMemberBillsParameter.ACC_DUN_DunningProcess_RefID = savedDunningProcessID;
                saveMemberBillsParameter.ApplicableProcessDunningFees = 0;
                saveMemberBillsParameter.CurrentUnpaidBillFraction    = 0;

                var savedMemberBillID = cls_Save_ACC_DUN_DunningProcess_MemberBill.Invoke(Connection, Transaction, saveMemberBillsParameter, securityTicket).Result;
                savedProcesses.Add(savedMemberBillID);

                //dunning process history
                var dunningProcessHistory = new ORM_ACC_DUN_DunningProcess_History();
                dunningProcessHistory.ACC_DUN_Dunning_Level_RefID  = minimalLevelInSequence.Dunning_Level_RefID;
                dunningProcessHistory.ACC_DUN_DunningProcess_RefID = savedDunningProcessID;
                dunningProcessHistory.Creation_Timestamp           = DateTime.Now;
                dunningProcessHistory.DunningProcessFee_IncludingThisDunningLevel = 0;
                dunningProcessHistory.IsCurrentStep = true;
                dunningProcessHistory.Tenant_RefID  = securityTicket.TenantID;

                var savedDunningProcessHistoryID = new FR_Guid(dunningProcessHistory.Save(Connection, Transaction), dunningProcessHistory.ACC_DUN_DunningProcess_HistoryID);
            }

            returnValue.Result = savedProcesses.ToArray();

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3ACAAD_GCAfT_1612_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L3ACAAD_GCAfCID_1612 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3ACAAD_GCAfT_1612_Array();
            //Put your code here
            if (Parameter.CustomerID == Guid.Empty)
            {
                return(returnValue);
            }

            ORM_CMN_BPT_CTM_Customer customer;
            var customerQ = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQ.Tenant_RefID           = securityTicket.TenantID;
            customerQ.IsDeleted              = false;
            customerQ.CMN_BPT_CTM_CustomerID = Parameter.CustomerID;
            customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).FirstOrDefault();
            if (customer == null)
            {
                return(returnValue);
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant;
            var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQ.Tenant_RefID = securityTicket.TenantID;
            bParticipantQ.IsDeleted    = false;
            bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
            bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).FirstOrDefault();
            if (bParticipant == null)
            {
                return(returnValue);
            }
            //L5ACAAD_GCAfT_1544
            var list = new List <L3ACAAD_GCAfT_1612>();

            if (bParticipant.IsCompany)
            {
                P_L3ACAAD_GCAfT_1607 param = new P_L3ACAAD_GCAfT_1607();
                param.CompanyInfoID = bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                var addresses = cls_Get_CompanyAddresses_for_CompanyInfoID.Invoke(Connection, Transaction, param, securityTicket).Result;
                if (addresses != null)
                {
                    foreach (var a in addresses)
                    {
                        L3ACAAD_GCAfT_1612 item = new L3ACAAD_GCAfT_1612();
                        item.AddressID             = a.CMN_UniversalContactDetailID;
                        item.Country_639_1_ISOCode = a.Country_639_1_ISOCode;
                        item.IsBilling             = a.IsBilling;
                        item.IsShipping            = a.IsShipping;
                        item.IsContact             = a.IsContact;
                        item.Street_Name           = a.Street_Name;
                        item.Street_Number         = a.Street_Number;
                        item.Town         = a.Town;
                        item.ZIP          = a.ZIP;
                        item.AssignmentID = Guid.Empty;
                        item.CMN_COM_CompanyInfo_AddressID = a.CMN_COM_CompanyInfo_AddressID;
                        item.Country_Name = a.Country_Name;
                        item.AddressName  = a.Address_Description;
                        item.IsDefault    = a.IsDefault;
                        item.IsCompany    = true;
                        list.Add(item);
                    }
                }
            }
            else
            {
                P_L3ACAAD_GPAfT_1608 param = new P_L3ACAAD_GPAfT_1608();
                param.PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                var addresses = cls_Get_PersonAddresses_for_PersonInfoID.Invoke(Connection, Transaction, param, securityTicket).Result;
                if (addresses != null)
                {
                    foreach (var a in addresses)
                    {
                        L3ACAAD_GCAfT_1612 item = new L3ACAAD_GCAfT_1612();
                        item.AddressID             = a.CMN_AddressID;
                        item.Country_639_1_ISOCode = a.Country_ISOCode;
                        item.IsBilling             = a.IsAddress_Billing;
                        item.IsShipping            = a.IsAddress_Shipping;
                        item.IsContact             = a.IsAddress_Contact;
                        item.Street_Name           = a.Street_Name;
                        item.Street_Number         = a.Street_Number;
                        item.Town         = a.City_Name;
                        item.ZIP          = a.City_PostalCode;
                        item.AssignmentID = a.AssignmentID;
                        item.CMN_COM_CompanyInfo_AddressID = Guid.Empty;
                        item.Country_Name = a.Country_Name;
                        item.AddressName  = a.AddressLabel;
                        item.IsDefault    = a.IsPrimary;
                        item.IsCompany    = false;
                        list.Add(item);
                    }
                }
            }

            returnValue.Result = list.ToArray();

            return(returnValue);



            return(returnValue);

            #endregion UserCode
        }
Пример #6
0
        protected static FR_L5OD_GDfT_1126_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5OD_GDfT_1126_Array();

            var basicInfos   = cls_Get_Doctor_BaseInfo_withPractice_forTenant.Invoke(Connection, Transaction, securityTicket).Result;
            var allPractices = cls_Get_Practice_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            var accs         = cls_Retrive_Account_Code_Details_forTenant.Invoke(Connection, Transaction, securityTicket).Result;

            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Tenant_RefID = securityTicket.TenantID;
            var customers = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);

            var customer2SRQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
            customer2SRQuery.Tenant_RefID = securityTicket.TenantID;
            var customer2SRs = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, customer2SRQuery);

            List <L5OD_GDfT_1126> retVal = new List <L5OD_GDfT_1126>();
            foreach (var item in basicInfos)
            {
                var doc = new L5OD_GDfT_1126();
                doc.BaseInfo     = item;
                doc.FirstName    = item.FirstName;
                doc.LastName     = item.LastName;
                doc.HEC_DoctorID = item.HEC_DoctorID;
                doc.Title        = item.Title;
                if (item.AllPractices != null)
                {
                    var practices       = item.AllPractices.OrderBy(p => p.Creation_Timestamp);
                    var doctorsPractice = practices.FirstOrDefault();
                    if (doctorsPractice != null)
                    {
                        var practicesForDoctor = allPractices.FirstOrDefault(p => p.BaseInfo.HEC_MedicalPractiseID == doctorsPractice.PracticeID);
                        if (practicesForDoctor != null)
                        {
                            L5OD_GDfT_1126_Practice practice = new L5OD_GDfT_1126_Practice();
                            practice.AssociatedParticipant_FunctionName = doctorsPractice.AssociatedParticipant_FunctionName;
                            practice.CMN_BPT_BusinessParticipantID      = doctorsPractice.CMN_BPT_BusinessParticipantID;
                            if (practicesForDoctor.OtherOphthal_PracticeData != null)
                            {
                                practice.HealthAssociation_Name = practicesForDoctor.OtherOphthal_PracticeData.HealthAssociation_Name;
                            }
                            practice.PracticeID    = practicesForDoctor.BaseInfo.HEC_MedicalPractiseID;
                            practice.PracticeName  = practicesForDoctor.BaseInfo.PracticeName;
                            practice.Region_Name   = practicesForDoctor.BaseInfo.Region_Name;
                            practice.Street_Name   = practicesForDoctor.BaseInfo.Street_Name;
                            practice.Street_Number = practicesForDoctor.BaseInfo.Street_Number;
                            practice.Town          = practicesForDoctor.BaseInfo.Town;
                            practice.ZIP           = practicesForDoctor.BaseInfo.ZIP;
                            doc.Practice           = practice;
                        }
                    }

                    var customer = customers.FirstOrDefault(c => c.Ext_BusinessParticipant_RefID == item.Doctor_CMN_BPT_BusinessParticipantID);
                    if (customer != null)
                    {
                        var c2sr = customer2SRs.FirstOrDefault(c => c.Customer_RefID == customer.CMN_BPT_CTM_CustomerID);
                        if (c2sr != null)
                        {
                            doc.SalesRepresentative = new L5OD_GDfT_1126_SalesRepresentative();
                            doc.SalesRepresentative.SalesRepresentative_RefID = c2sr.SalesRepresentative_RefID;
                        }
                    }

                    var accountInfo = accs.FirstOrDefault(a => a.BusinessParticipant_RefID == item.Doctor_CMN_BPT_BusinessParticipantID);
                    if (accountInfo != null)
                    {
                        doc.AccountInfo = new L5OD_GDfT_1126_AccountInfo();
                        doc.AccountInfo.AccountCode_Value = accountInfo.AccountCode_Value;
                    }
                }
                retVal.Add(doc);
            }
            returnValue.Result = retVal.ToArray();
            return(returnValue);

            #endregion UserCode
        }
Пример #7
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACACU_SCC_1051 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            if (Parameter.IsDelete && (Parameter.CMN_BPT_CTM_CustomerID == Guid.Empty))
            {
                return(returnValue);
            }

            ORM_CMN_BPT_CTM_Customer customer;
            if (Parameter.CMN_BPT_CTM_CustomerID != Guid.Empty)
            {
                var customerQ = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQ.Tenant_RefID           = securityTicket.TenantID;
                customerQ.IsDeleted              = false;
                customerQ.CMN_BPT_CTM_CustomerID = Parameter.CMN_BPT_CTM_CustomerID;
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).First();
                customer.InternalCustomerNumber = Parameter.Number;
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }
            else
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.Tenant_RefID           = securityTicket.TenantID;
                customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid();
                customer.InternalCustomerNumber = Parameter.Number;
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }

            ORM_CMN_BPT_CTM_AvailablePaymentType customer2PaymentType;

            var customer2PaymentTypeQ = new ORM_CMN_BPT_CTM_AvailablePaymentType.Query();
            customer2PaymentTypeQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentTypeQ.IsDeleted      = false;
            customer2PaymentTypeQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentType = ORM_CMN_BPT_CTM_AvailablePaymentType.Query.Search(Connection, Transaction, customer2PaymentTypeQ).FirstOrDefault();
            if (customer2PaymentType == null)
            {
                customer2PaymentType = new ORM_CMN_BPT_CTM_AvailablePaymentType();
                customer2PaymentType.ACC_PAY_Type_RefID = Guid.NewGuid();
                customer2PaymentType.Tenant_RefID       = securityTicket.TenantID;
                customer2PaymentType.Customer_RefID     = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentType.ACC_PAY_Type_RefID = Parameter.PaymentTypeID;
            customer2PaymentType.Save(Connection, Transaction);

            #region payment condition

            ORM_CMN_BPT_CTM_AvailablePaymentCondition customer2PaymentCondition;

            var customer2PaymentConditionQ = new ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query();
            customer2PaymentConditionQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentConditionQ.IsDeleted      = false;
            customer2PaymentConditionQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentCondition = ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query.Search(Connection, Transaction, customer2PaymentConditionQ).FirstOrDefault();
            if (customer2PaymentCondition == null)
            {
                customer2PaymentCondition = new ORM_CMN_BPT_CTM_AvailablePaymentCondition();
                customer2PaymentCondition.ACC_PAY_Condition_RefID = Guid.NewGuid();
                customer2PaymentCondition.Tenant_RefID            = securityTicket.TenantID;
                customer2PaymentCondition.Customer_RefID          = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentCondition.ACC_PAY_Condition_RefID = Parameter.PaymentConditionID;
            customer2PaymentCondition.Save(Connection, Transaction);

            #endregion

            ORM_CMN_BPT_BusinessParticipant bParticipant;
            if (customer.Ext_BusinessParticipant_RefID != Guid.Empty)
            {
                var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();
                bParticipantQ.Tenant_RefID = securityTicket.TenantID;
                bParticipantQ.IsDeleted    = false;
                bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
                bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).First();
            }
            else
            {
                bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Tenant_RefID = securityTicket.TenantID;
                bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bParticipant.IsCompany = true;
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }

            bParticipant.DisplayName = Parameter.FirmName;

            ORM_CMN_COM_CompanyInfo company;
            if (bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID != Guid.Empty)
            {
                var companyQ = new ORM_CMN_COM_CompanyInfo.Query();
                companyQ.Tenant_RefID          = securityTicket.TenantID;
                companyQ.IsDeleted             = false;
                companyQ.CMN_COM_CompanyInfoID = bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                company = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyQ).First();
            }
            else
            {
                company = new ORM_CMN_COM_CompanyInfo();
                company.Tenant_RefID          = securityTicket.TenantID;
                company.CMN_COM_CompanyInfoID = Guid.NewGuid();
                bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = company.CMN_COM_CompanyInfoID;
            }

            ORM_CMN_UniversalContactDetail ucd;
            if (company.Contact_UCD_RefID != Guid.Empty)
            {
                var ucdQ = new ORM_CMN_UniversalContactDetail.Query();
                ucdQ.Tenant_RefID = securityTicket.TenantID;
                ucdQ.IsDeleted    = false;
                ucdQ.CMN_UniversalContactDetailID = company.Contact_UCD_RefID;
                ucd = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, ucdQ).First();
            }
            else
            {
                ucd = new ORM_CMN_UniversalContactDetail();
                ucd.Tenant_RefID = securityTicket.TenantID;
                ucd.CMN_UniversalContactDetailID = Guid.NewGuid();
                ucd.IsCompany             = true;
                company.Contact_UCD_RefID = ucd.CMN_UniversalContactDetailID;
            }

            ucd.CompanyName_Line1  = Parameter.FirmName;
            ucd.CompanyName_Line2  = Parameter.Additional;
            ucd.IsDeleted          = Parameter.IsDelete;
            company.IsDeleted      = Parameter.IsDelete;
            bParticipant.IsDeleted = Parameter.IsDelete;
            customer.IsDeleted     = Parameter.IsDelete;

            ucd.Save(Connection, Transaction);
            company.Save(Connection, Transaction);
            bParticipant.Save(Connection, Transaction);
            customer.Save(Connection, Transaction);

            returnValue.Result = customer.CMN_BPT_CTM_CustomerID;

            return(returnValue);

            #endregion UserCode
        }
Пример #8
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_CL5CO_SC_1724 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            Guid personInfoID = Guid.Empty;

            ORM_CMN_BPT_CTM_Customer.Query customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.CMN_BPT_CTM_CustomerID = Parameter.CustomerID;
            customerQuery.IsDeleted = false;
            ORM_CMN_BPT_CTM_Customer customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).Single();

            ORM_CMN_BPT_BusinessParticipant.Query businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
            businessParticipantQuery.IsDeleted = false;
            ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

            if (businessParticipant.IsNaturalPerson)
            {
                personInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;
                List <ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant> associations = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery);

                foreach (var association in associations)
                {
                    ORM_CMN_BPT_BusinessParticipant.Query bpQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    bpQuery.CMN_BPT_BusinessParticipantID = association.BusinessParticipant_RefID;
                    bpQuery.IsDeleted       = false;
                    bpQuery.IsNaturalPerson = true;
                    ORM_CMN_BPT_BusinessParticipant bp = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bpQuery).First();
                    if (bp != null)
                    {
                        personInfoID = bp.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        break;
                    }
                }
            }

            if (personInfoID != Guid.Empty)
            {
                if (Parameter.Correspondences.Any(x => x.IsDefaultCorrespondence) && !Parameter.Correspondences.Any(x => x.IsDeleted))
                {
                    var findDefaultCorrespondenceQuery = ORM_CMN_PER_PersonInfo_Correspondence.Query.Search(Connection, Transaction,
                                                                                                            new ORM_CMN_PER_PersonInfo_Correspondence.Query
                    {
                        CMN_PER_PersonInfo_RefID = personInfoID,
                        IsDefaultCorrespondence  = true,
                        IsDeleted    = false,
                        Tenant_RefID = customer.Tenant_RefID
                    });

                    if (findDefaultCorrespondenceQuery != null && findDefaultCorrespondenceQuery.Any())
                    {
                        foreach (var item in findDefaultCorrespondenceQuery)
                        {
                            item.IsDefaultCorrespondence = false;
                            item.Save(Connection, Transaction);
                        }
                    }
                }

                foreach (var item in Parameter.Correspondences)
                {
                    ORM_CMN_PER_PersonInfo_Correspondence.Query correspondenceQuery = new ORM_CMN_PER_PersonInfo_Correspondence.Query();
                    correspondenceQuery.IsDeleted = false;
                    correspondenceQuery.CMN_PER_PersonInfo_CorrespondenceID = item.CorrespondenceID;
                    List <ORM_CMN_PER_PersonInfo_Correspondence> correspondences = ORM_CMN_PER_PersonInfo_Correspondence.Query.Search(Connection, Transaction, correspondenceQuery);

                    if (item.IsDeleted && correspondences.Count > 0)
                    {
                        correspondences.First().IsDeleted = true;
                        correspondences.First().Save(Connection, Transaction);
                    }
                    else if (!item.IsDeleted)
                    {
                        if (correspondences.Count > 0)
                        {
                            correspondences.First().CorrespondenceText = item.CorrespondenceText;

                            correspondences.First().IsDefaultCorrespondence  = item.IsDefaultCorrespondence;
                            correspondences.First().CorrespondenceType_RefID = item.CorrespondenceTypeRefId;

                            correspondences.First().Save(Connection, Transaction);

                            // save name in correspodencetype
                            //var correspodenceTypeQuery = ORM_CMN_PER_PersonInfo_CorrespondenceType.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_CorrespondenceType.Query{
                            //    CMN_PER_PersonInfo_CorrespondenceTypeID = correspondences.First().CorrespondenceType_RefID,
                            //    Tenant_RefID = customer.Tenant_RefID
                            //}).SingleOrDefault()

                            //if (correspodenceTypeQuery != null)
                            //{
                            //    correspodenceTypeQuery.DisplayName = item.CorrespondenceName;
                            //    correspodenceTypeQuery.Save(Connection, Transaction);
                            //}
                        }
                        else
                        {
                            ORM_CMN_PER_PersonInfo.Query personQuery = new ORM_CMN_PER_PersonInfo.Query();
                            personQuery.CMN_PER_PersonInfoID = personInfoID;
                            personQuery.IsDeleted            = false;
                            ORM_CMN_PER_PersonInfo person = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personQuery).First();

                            ORM_CMN_PER_PersonInfo_Correspondence newCorrespondance = new ORM_CMN_PER_PersonInfo_Correspondence();
                            newCorrespondance.CorrespondenceText       = item.CorrespondenceText;
                            newCorrespondance.IsDefaultCorrespondence  = item.IsDefaultCorrespondence;
                            newCorrespondance.CorrespondenceType_RefID = item.CorrespondenceTypeRefId;
                            newCorrespondance.IsDeleted          = false;
                            newCorrespondance.Creation_Timestamp = DateTime.Now;
                            newCorrespondance.CMN_PER_PersonInfo_CorrespondenceID = Guid.NewGuid();
                            newCorrespondance.CMN_PER_PersonInfo_RefID            = person.CMN_PER_PersonInfoID;
                            newCorrespondance.Tenant_RefID = customer.Tenant_RefID;
                            newCorrespondance.Save(Connection, Transaction);

                            //  We will need some of this code later
                            //var correspodenceTypeQuery = ORM_CMN_PER_PersonInfo_CorrespondenceType.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_CorrespondenceType.Query{
                            //    CMN_PER_PersonInfo_CorrespondenceTypeID = newCorrespondance.CorrespondenceType_RefID,
                            //    Tenant_RefID = customer.Tenant_RefID
                            //}).SingleOrDefault()

                            //if (correspodenceTypeQuery != null)
                            //{
                            //    correspodenceTypeQuery.DisplayName = item.CorrespondenceName;
                            //    correspodenceTypeQuery.Save(Connection,Transaction);
                            //}
                            //else
                            //{
                            //    ORM_CMN_PER_PersonInfo_CorrespondenceType newCorrespodenceType = new ORM_CMN_PER_PersonInfo_CorrespondenceType();
                            //    newCorrespodenceType.Tenant_RefID = customer.Tenant_RefID;
                            //    newCorrespodenceType.CMN_PER_PersonInfo_CorrespondenceTypeID = newCorrespondance.CorrespondenceType_RefID;
                            //    newCorrespodenceType.DisplayName = item.CorrespondenceName;
                            //}
                        }
                    }
                }
            }
            return(returnValue);

            #endregion UserCode
        }
Пример #9
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OD_SD_1130 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            Guid           accounrRefID = Guid.Empty;
            var            doctorQuery  = new ORM_HEC_Doctor.Query();
            ORM_HEC_Doctor doctor;
            if (Parameter.HEC_DoctorID != Guid.Empty)
            {
                doctorQuery.HEC_DoctorID = Parameter.HEC_DoctorID;
                doctor       = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First();
                accounrRefID = doctor.Account_RefID;
            }

            P_L3MD_SDBI_1349 sbdParam = new P_L3MD_SDBI_1349();
            sbdParam.DoctorID      = Parameter.HEC_DoctorID;
            sbdParam.Account_RefID = accounrRefID;
            sbdParam.FirstName     = Parameter.FirstName;
            sbdParam.LastName      = Parameter.LastName;
            sbdParam.isOphthalSave = true;
            sbdParam.ifOphthal_Salutation_General = Parameter.Salutation_General;
            sbdParam.ifOphthal_Salutation_Letter  = Parameter.Salutation_Letter;
            sbdParam.Title = Parameter.Title;

            List <P_L3MD_SDBI_1349_Contacts> contactsParams = new List <P_L3MD_SDBI_1349_Contacts>();
            if (Parameter.Contacts != null)
            {
                foreach (var item in Parameter.Contacts)
                {
                    var c = new P_L3MD_SDBI_1349_Contacts();
                    c.CMN_PER_CommunicationContact_TypeID = item.CMN_PER_CommunicationContact_TypeID;
                    c.Content = item.Content;
                    contactsParams.Add(c);
                }
            }
            sbdParam.Contacts = contactsParams.ToArray();

            List <P_L3MD_SDBI_1349_Practice> practicesParams = new List <P_L3MD_SDBI_1349_Practice>();
            if (Parameter.Practices != null)
            {
                foreach (var item in Parameter.Practices)
                {
                    var p = new P_L3MD_SDBI_1349_Practice();
                    p.PracticeID = item.PracticeID;
                    p.isDeleted  = item.isDeleted;
                    p.AssociatedParticipant_FunctionName = item.AssociatedParticipant_FunctionName;
                    practicesParams.Add(p);
                }
            }
            sbdParam.Practices = practicesParams.ToArray();

            var docID = cls_Save_Doctor_BaseInfo.Invoke(Connection, Transaction, sbdParam, securityTicket).Result;

            doctorQuery = new ORM_HEC_Doctor.Query();
            doctorQuery.HEC_DoctorID = docID;

            doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First();
            var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQuery.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID;
            var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).First();

            ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative;
            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).FirstOrDefault();
            if (customer == null)
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                customer.Tenant_RefID                  = securityTicket.TenantID;
                SalesRepresentative                    = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative();
                SalesRepresentative.AssignmentID       = Guid.NewGuid();
                SalesRepresentative.Customer_RefID     = customer.CMN_BPT_CTM_CustomerID;
                SalesRepresentative.Tenant_RefID       = securityTicket.TenantID;
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }
            else
            {
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First();
                var SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
                SalesRepresentativeQuery.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;
                SalesRepresentative = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, SalesRepresentativeQuery).First();
            }
            SalesRepresentative.SalesRepresentative_RefID = Parameter.CMN_BPT_SalesRepresentativeID;

            var sRepresentativeQuery = new ORM_CMN_BPT_SalesRepresentative.Query();
            sRepresentativeQuery.CMN_BPT_SalesRepresentativeID = Parameter.CMN_BPT_SalesRepresentativeID;
            sRepresentativeQuery.IsDeleted = false;
            var sRepresentative = ORM_CMN_BPT_SalesRepresentative.Query.Search(Connection, Transaction, sRepresentativeQuery).FirstOrDefault();
            if (sRepresentative == null)
            {
                sRepresentative = new ORM_CMN_BPT_SalesRepresentative();
                sRepresentative.CMN_BPT_SalesRepresentativeID = Parameter.CMN_BPT_SalesRepresentativeID;
                sRepresentative.Save(Connection, Transaction);
            }

            customer.Save(Connection, Transaction);
            SalesRepresentative.Save(Connection, Transaction);

            ORM_USR_Account            account;
            ORM_USR_Device_AccountCode code;
            ORM_USR_Device_AccountCode_StatusHistory codeStatus;
            var accountQuery = new ORM_USR_Account.Query();
            accountQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            accountQuery.AccountType = 3;
            var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery);
            if (accountQueryRes.Count == 0)
            {
                account = new ORM_USR_Account();
                account.USR_AccountID             = Guid.NewGuid();
                account.Tenant_RefID              = securityTicket.TenantID;
                account.AccountType               = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Save(Connection, Transaction);

                code = new ORM_USR_Device_AccountCode();
                code.Tenant_RefID             = securityTicket.TenantID;
                code.USR_Device_AccountCodeID = Guid.NewGuid();
                code.Account_RefID            = account.USR_AccountID;
                code.AccountCode_ValidFrom    = DateTime.Now;

                codeStatus = new ORM_USR_Device_AccountCode_StatusHistory();
                codeStatus.USR_Device_AccountCode_StatusHistoryID = Guid.NewGuid();
                codeStatus.Device_AccountCode_RefID = code.USR_Device_AccountCodeID;
                codeStatus.Tenant_RefID             = securityTicket.TenantID;
                codeStatus.IsAccountCode_Active     = true;
                codeStatus.Save(Connection, Transaction);

                code.AccountCode_CurrentStatus_RefID = codeStatus.USR_Device_AccountCode_StatusHistoryID;

                L3DAC_GDACFTCV_1616   checkCodeValue;
                P_L3DAC_GDACFTCV_1616 codeParam = new P_L3DAC_GDACFTCV_1616();
                string codeValue;
                do
                {
                    codeValue           = RandomString.Generate(8);
                    codeParam.CodeValue = codeValue;
                    checkCodeValue      = cls_GetDeviceAccountCodeForTenantAndCodeValue.Invoke(Connection, Transaction, codeParam, securityTicket).Result;
                } while (checkCodeValue != null);

                code.AccountCode_Value = codeValue;
                code.Save(Connection, Transaction);
            }

            returnValue.Result = docID;
            return(returnValue);

            #endregion UserCode
        }
Пример #10
0
        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
        }
Пример #11
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACACU_SPC_1047 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            if (Parameter.IsDelete && (Parameter.CMN_BPT_CTM_CustomerID == Guid.Empty))
            {
                return(returnValue);
            }

            ORM_CMN_BPT_CTM_Customer customer;
            if (Parameter.CMN_BPT_CTM_CustomerID != Guid.Empty)
            {
                var customerQ = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQ.Tenant_RefID           = securityTicket.TenantID;
                customerQ.IsDeleted              = false;
                customerQ.CMN_BPT_CTM_CustomerID = Parameter.CMN_BPT_CTM_CustomerID;
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).First();
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }
            else
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.Tenant_RefID           = securityTicket.TenantID;
                customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid();
                customer.InternalCustomerNumber = Parameter.Number;
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }

            ORM_CMN_BPT_CTM_AvailablePaymentType customer2PaymentType;

            var customer2PaymentTypeQ = new ORM_CMN_BPT_CTM_AvailablePaymentType.Query();
            customer2PaymentTypeQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentTypeQ.IsDeleted      = false;
            customer2PaymentTypeQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentType = ORM_CMN_BPT_CTM_AvailablePaymentType.Query.Search(Connection, Transaction, customer2PaymentTypeQ).FirstOrDefault();
            if (customer2PaymentType == null)
            {
                customer2PaymentType = new ORM_CMN_BPT_CTM_AvailablePaymentType();
                customer2PaymentType.ACC_PAY_Type_RefID = Guid.NewGuid();
                customer2PaymentType.Tenant_RefID       = securityTicket.TenantID;
                customer2PaymentType.Customer_RefID     = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentType.ACC_PAY_Type_RefID = Parameter.PaymentTypeID;
            customer2PaymentType.Save(Connection, Transaction);

            #region payment condition

            ORM_CMN_BPT_CTM_AvailablePaymentCondition customer2PaymentCondition;

            var customer2PaymentConditionQ = new ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query();
            customer2PaymentConditionQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentConditionQ.IsDeleted      = false;
            customer2PaymentConditionQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentCondition = ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query.Search(Connection, Transaction, customer2PaymentConditionQ).FirstOrDefault();
            if (customer2PaymentCondition == null)
            {
                customer2PaymentCondition = new ORM_CMN_BPT_CTM_AvailablePaymentCondition();
                customer2PaymentCondition.ACC_PAY_Condition_RefID = Guid.NewGuid();
                customer2PaymentCondition.Tenant_RefID            = securityTicket.TenantID;
                customer2PaymentCondition.Customer_RefID          = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentCondition.ACC_PAY_Condition_RefID = Parameter.PaymentConditionID;
            customer2PaymentCondition.Save(Connection, Transaction);

            #endregion

            ORM_CMN_BPT_BusinessParticipant bParticipant;
            if (customer.Ext_BusinessParticipant_RefID != Guid.Empty)
            {
                var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();
                bParticipantQ.Tenant_RefID = securityTicket.TenantID;
                bParticipantQ.IsDeleted    = false;
                bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
                bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).First();
            }
            else
            {
                bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Tenant_RefID = securityTicket.TenantID;
                bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bParticipant.IsNaturalPerson           = true;
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }

            bParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastName;

            ORM_CMN_PER_PersonInfo personInfo;
            if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty)
            {
                var personInfoQ = new ORM_CMN_PER_PersonInfo.Query();
                personInfoQ.Tenant_RefID         = securityTicket.TenantID;
                personInfoQ.IsDeleted            = false;
                personInfoQ.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQ).First();
            }
            else
            {
                personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
            }

            #region connection with legal guardian
            //checking is there allready legal guardian associated with this business participant

            ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query LGCheckQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
            LGCheckQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            LGCheckQuery.IsDeleted = false;

            Boolean oldLegalGuardianConnectionExist = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Exists(Connection, Transaction, LGCheckQuery);

            if (Parameter.IsRepresentedByLegalGuardian)
            {
                if (oldLegalGuardianConnectionExist)
                {
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant oldLegalGuardianConnection = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, LGCheckQuery).First();
                    ORM_CMN_BPT_BusinessParticipant.Query oldLegalGuardianQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    oldLegalGuardianQuery.CMN_BPT_BusinessParticipantID = oldLegalGuardianConnection.AssociatedBusinessParticipant_RefID;
                    oldLegalGuardianQuery.IsDeleted = false;

                    ORM_CMN_BPT_BusinessParticipant oldLegalGuardian = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, oldLegalGuardianQuery).First();
                    oldLegalGuardian.DisplayName = Parameter.LegalGuardianName;
                    oldLegalGuardian.Save(Connection, Transaction);
                }
                else
                {
                    // creating a new legal guardian
                    ORM_CMN_BPT_BusinessParticipant newLegalGuardian = new ORM_CMN_BPT_BusinessParticipant();
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant legalGuardianLink = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();

                    newLegalGuardian.DisplayName = Parameter.LegalGuardianName;
                    legalGuardianLink.AssociatedBusinessParticipant_RefID = newLegalGuardian.CMN_BPT_BusinessParticipantID;
                    legalGuardianLink.BusinessParticipant_RefID           = bParticipant.CMN_BPT_BusinessParticipantID;
                    newLegalGuardian.Save(Connection, Transaction);
                    legalGuardianLink.Save(Connection, Transaction);
                }
            }
            else
            {
                //delete old legal guardian if there is an old legal guardian
                if (oldLegalGuardianConnectionExist)
                {
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant oldLegalGuardianConnection = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, LGCheckQuery).First();
                    ORM_CMN_BPT_BusinessParticipant.Query oldLegalGuardianQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    oldLegalGuardianQuery.CMN_BPT_BusinessParticipantID = oldLegalGuardianConnection.AssociatedBusinessParticipant_RefID;
                    oldLegalGuardianQuery.IsDeleted = false;

                    //deleting old legal guardian from business participant table
                    if (ORM_CMN_BPT_BusinessParticipant.Query.Exists(Connection, Transaction, oldLegalGuardianQuery))
                    {
                        ORM_CMN_BPT_BusinessParticipant oldLegalGuardian = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, oldLegalGuardianQuery).First();
                        oldLegalGuardian.IsDeleted = true;
                        oldLegalGuardian.Save(Connection, Transaction);
                    }
                    // deleting connenction beetwen customer and legal guardian
                    oldLegalGuardianConnection.IsDeleted = true;
                    oldLegalGuardianConnection.Save(Connection, Transaction);
                }
            }

            #endregion

            personInfo.FirstName = Parameter.FirstName;
            personInfo.LastName  = Parameter.LastName;
            personInfo.BirthDate = Parameter.BirthDate;
            personInfo.IsRepresentedByLegalGuardian = Parameter.IsRepresentedByLegalGuardian;

            personInfo.IsDeleted   = Parameter.IsDelete;
            bParticipant.IsDeleted = Parameter.IsDelete;
            customer.IsDeleted     = Parameter.IsDelete;

            personInfo.Save(Connection, Transaction);
            bParticipant.Save(Connection, Transaction);
            customer.Save(Connection, Transaction);

            returnValue.Result = customer.CMN_BPT_CTM_CustomerID;

            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
        }
Пример #13
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_DDbID_1031 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #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);
                }
                doctor.IsDeleted = true;
                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();
                bussinessParticipant.IsDeleted = true;
                bussinessParticipant.Save(Connection, Transaction);

                if (doctor.Account_RefID != Guid.Empty)
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = doctor.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).FirstOrDefault();
                    if (account2personInfo != null)
                    {
                        account2personInfo.IsDeleted = true;
                        account2personInfo.Save(Connection, Transaction);

                        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.IsDeleted = true;
                        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();

                    foreach (var contact in communicationContactsList)
                    {
                        contact.IsDeleted = true;
                        contact.Save(Connection, Transaction);
                    }
                }

                var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                query3.IsDeleted = false;
                var abpRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3);
                foreach (ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant assigned in abpRes)
                {
                    assigned.IsDeleted = true;
                    assigned.Save(Connection, Transaction);
                }

                #endregion

                ORM_CMN_BPT_CTM_Customer customer;
                ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative;
                var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQuery.Ext_BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);
                if (customerRes.Count != 0)
                {
                    customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First();
                    var SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
                    SalesRepresentativeQuery.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;
                    SalesRepresentative = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, SalesRepresentativeQuery).First();

                    customer.IsDeleted = true;
                    customer.Save(Connection, Transaction);
                    SalesRepresentative.IsDeleted = true;
                    SalesRepresentative.Save(Connection, Transaction);
                }

                var accountQuery = new ORM_USR_Account.Query();
                accountQuery.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                accountQuery.AccountType = 3;
                var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery);
                if (accountQueryRes.Count != 0)
                {
                    var account = accountQueryRes.First();
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);

                    var codeQuery = new ORM_USR_Device_AccountCode.Query();
                    codeQuery.Account_RefID = account.USR_AccountID;
                    var code = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, codeQuery).First();
                    code.IsDeleted = true;
                    code.Save(Connection, Transaction);

                    var codeStatusQuery = new ORM_USR_Device_AccountCode_StatusHistory.Query();
                    codeStatusQuery.Device_AccountCode_RefID = code.USR_Device_AccountCodeID;
                    var codeStatus = ORM_USR_Device_AccountCode_StatusHistory.Query.Search(Connection, Transaction, codeStatusQuery).First();
                    codeStatus.IsDeleted = true;
                    codeStatus.Save(Connection, Transaction);
                }
            }

            returnValue.Result = doctor.HEC_DoctorID;
            return(returnValue);
        }
Пример #14
0
        protected static FR_L3MP_GPfID_1222 Execute(DbConnection Connection, DbTransaction Transaction, P_L3MP_GPfID_1222 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3MP_GPfID_1222();

            returnValue.Result = new L3MP_GPfID_1222();

            P_L3MP_GPBIfID_1131 paramBasicInfo = new P_L3MP_GPBIfID_1131();
            paramBasicInfo.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID;
            var baseInfo = cls_Get_Practice_BaseInfo_For_ID.Invoke(Connection, Transaction, paramBasicInfo, securityTicket).Result;
            if (baseInfo == null)
            {
                returnValue.Result = null;
                return(returnValue);
            }

            returnValue.Result.BaseInfo = baseInfo;

            P_L3MP_GPCPfPID_1155 paramCP = new P_L3MP_GPCPfPID_1155();
            paramCP.CMN_BPT_BusinessParticipantID = baseInfo.ContactPerson_RefID;
            var contactPerson = cls_Get_Practice_ContactPerson_For_PersonID.Invoke(Connection, Transaction, paramCP, securityTicket).Result;
            returnValue.Result.ContactPerson = contactPerson;

            if (baseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty && baseInfo.WeeklySurgeryHours_Template_RefID != Guid.Empty)
            {
                returnValue.Result.OfficeHours = new L3MP_GPfID_1222_OfficeHours();

                var officeHoursQuery = new ORM_CMN_CAL_WeeklyOfficeHours_Template.Query();
                officeHoursQuery.IsDeleted    = false;
                officeHoursQuery.Tenant_RefID = securityTicket.TenantID;
                officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = baseInfo.WeeklyOfficeHours_Template_RefID;
                var officeHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First();
                returnValue.Result.OfficeHours.WorkingHours_FormattedOfficeHours = officeHours.FormattedOfficeHours;
                officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID            = baseInfo.WeeklySurgeryHours_Template_RefID;
                var consultingHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First();
                returnValue.Result.OfficeHours.ConsultingHours_FormattedOfficeHours = consultingHours.FormattedOfficeHours;

                returnValue.Result.OtherOphthal_PracticeData = new L3MP_GPfID_1222_OtherOphthal_PracticeData();
                var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query();
                companyTypeQuery.IsDeleted = false;
                companyTypeQuery.CMN_COM_CompanyInfo_TypeID = baseInfo.CompanyType_RefID;
                var companyType = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery).First();
                returnValue.Result.OtherOphthal_PracticeData.CompanyType_Name           = companyType.CompanyType_Name;
                returnValue.Result.OtherOphthal_PracticeData.CMN_COM_CompanyInfo_TypeID = companyType.CMN_COM_CompanyInfo_TypeID;
                var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query();
                pHealthcareQuery.HEC_PublicHealthcare_PhysitianAssociationID = baseInfo.AssociatedWith_PhysitianAssociation_RefID;
                var pHealthcare = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery).First();
                returnValue.Result.OtherOphthal_PracticeData.HealthAssociation_Name = pHealthcare.HealthAssociation_Name;
                returnValue.Result.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID = baseInfo.AssociatedWith_PhysitianAssociation_RefID;
                var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQuery.Ext_BusinessParticipant_RefID = baseInfo.CMN_BPT_BusinessParticipantID;
                var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).FirstOrDefault();

                if (customer != null)
                {
                    var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query();
                    affinityStatusQuery.CMN_BPT_CTM_AffinityStatusID = customer.CustomerAffinityStatus_RefID;
                    var affinityStatus = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery).FirstOrDefault();

                    if (affinityStatus != null)
                    {
                        returnValue.Result.OtherOphthal_PracticeData.CMN_BPT_CTM_AffinityStatusID = affinityStatus.CMN_BPT_CTM_AffinityStatusID;
                        returnValue.Result.OtherOphthal_PracticeData.AffinityStatus_Name          = affinityStatus.AffinityStatus_Name;
                    }
                }
                returnValue.Result.ShippingAddress = new L3MP_GPfID_1222_ShippingAddress();
                var compAddressQuery = new ORM_CMN_COM_CompanyInfo_Address.Query();
                compAddressQuery.Tenant_RefID      = securityTicket.TenantID;
                compAddressQuery.CompanyInfo_RefID = baseInfo.CMN_COM_CompanyInfoID;
                compAddressQuery.IsShipping        = true;
                compAddressQuery.IsDeleted         = false;
                var compAddress  = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, compAddressQuery).First();
                var addressQuery = new ORM_CMN_UniversalContactDetail.Query();
                addressQuery.Tenant_RefID = securityTicket.TenantID;
                addressQuery.IsDeleted    = false;
                addressQuery.CMN_UniversalContactDetailID = compAddress.Address_UCD_RefID;
                var address = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, addressQuery).First();

                returnValue.Result.ShippingAddress.CMN_UniversalContactDetailID  = address.CMN_UniversalContactDetailID;
                returnValue.Result.ShippingAddress.CMN_COM_CompanyInfo_AddressID = compAddress.CMN_COM_CompanyInfo_AddressID;

                returnValue.Result.ShippingAddress.Region_Name   = address.Region_Name;
                returnValue.Result.ShippingAddress.Street_Name   = address.Street_Name;
                returnValue.Result.ShippingAddress.Street_Number = address.Street_Number;
                returnValue.Result.ShippingAddress.Town          = address.Town;
                returnValue.Result.ShippingAddress.ZIP           = address.ZIP;
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #15
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MP_DPBID_1026 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            P_L3MP_GPfID_1222 param = new P_L3MP_GPfID_1222();
            param.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID;
            var practice = cls_Get_Practice_For_ID.Invoke(Connection, Transaction, param, securityTicket).Result;
            if (practice != null)
            {
                ORM_CMN_UniversalContactDetail contactDetails = new ORM_CMN_UniversalContactDetail();
                if (practice.BaseInfo.CMN_UniversalContactDetailID != Guid.Empty)
                {
                    var result = contactDetails.Load(Connection, Transaction, practice.BaseInfo.CMN_UniversalContactDetailID);
                    if (result.Status != FR_Status.Success || contactDetails.CMN_UniversalContactDetailID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    contactDetails.IsDeleted = true;
                    contactDetails.Save(Connection, Transaction);
                }

                ORM_CMN_COM_CompanyInfo info = new ORM_CMN_COM_CompanyInfo();
                if (practice.BaseInfo.CMN_COM_CompanyInfoID != Guid.Empty)
                {
                    var result = info.Load(Connection, Transaction, practice.BaseInfo.CMN_COM_CompanyInfoID);
                    if (result.Status != FR_Status.Success || info.CMN_COM_CompanyInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    info.IsDeleted = true;
                    info.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (practice.BaseInfo.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, practice.BaseInfo.CMN_BPT_BusinessParticipantID);
                    if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    bParticipant.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }


                ORM_HEC_MedicalPractis practis = new ORM_HEC_MedicalPractis();
                if (practice.BaseInfo.HEC_MedicalPractiseID != Guid.Empty)
                {
                    var result = practis.Load(Connection, Transaction, practice.BaseInfo.HEC_MedicalPractiseID);
                    if (result.Status != FR_Status.Success || practis.HEC_MedicalPractiseID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    practis.IsDeleted = true;
                    practis.Save(Connection, Transaction);
                }

                if (practice.BaseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty)
                {
                    ORM_CMN_CAL_WeeklyOfficeHours_Template consultationHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template();
                    if (practice.BaseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty)
                    {
                        var result = consultationHours.Load(Connection, Transaction, practice.BaseInfo.WeeklyOfficeHours_Template_RefID);
                        if (result.Status != FR_Status.Success || consultationHours.CMN_CAL_WeeklyOfficeHours_TemplateID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                        consultationHours.IsDeleted = true;
                        consultationHours.Save(Connection, Transaction);
                    }
                }
                if (practice.BaseInfo.WeeklySurgeryHours_Template_RefID != Guid.Empty)
                {
                    ORM_CMN_CAL_WeeklyOfficeHours_Template consultationHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template();
                    if (practice.BaseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty)
                    {
                        var result = consultationHours.Load(Connection, Transaction, practice.BaseInfo.WeeklySurgeryHours_Template_RefID);
                        if (result.Status != FR_Status.Success || consultationHours.CMN_CAL_WeeklyOfficeHours_TemplateID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                        consultationHours.IsDeleted = true;
                        consultationHours.Save(Connection, Transaction);
                    }
                }

                if (practice.ShippingAddress != null)
                {
                    ORM_CMN_UniversalContactDetail shippingDetails = new ORM_CMN_UniversalContactDetail();
                    if (practice.ShippingAddress.CMN_UniversalContactDetailID != Guid.Empty)
                    {
                        var result = shippingDetails.Load(Connection, Transaction, practice.ShippingAddress.CMN_UniversalContactDetailID);
                        if (result.Status != FR_Status.Success || contactDetails.CMN_UniversalContactDetailID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }

                        shippingDetails.IsDeleted = true;
                        shippingDetails.Save(Connection, Transaction);
                    }

                    ORM_CMN_COM_CompanyInfo_Address shippingAddress = new ORM_CMN_COM_CompanyInfo_Address();
                    if (practice.ShippingAddress.CMN_COM_CompanyInfo_AddressID != Guid.Empty)
                    {
                        var result = shippingAddress.Load(Connection, Transaction, practice.ShippingAddress.CMN_COM_CompanyInfo_AddressID);
                        if (result.Status != FR_Status.Success || shippingAddress.CMN_COM_CompanyInfo_AddressID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                        shippingAddress.IsDeleted = true;
                        shippingAddress.Save(Connection, Transaction);
                    }
                }

                var associatedBussinessParticipantsQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associatedBussinessParticipantsQuery.AssociatedBusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                associatedBussinessParticipantsQuery.IsDeleted = false;
                var associatedBussinessParticipants = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBussinessParticipantsQuery);

                if (associatedBussinessParticipants.Count != 0)
                {
                    foreach (var assBussiness in associatedBussinessParticipants)
                    {
                        assBussiness.IsDeleted = true;
                        assBussiness.Save(Connection, Transaction);

                        //brisanje doktora ako je imao jednu praksu
                        //var d2pAssignmentQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                        //d2pAssignmentQuery.IsDeleted = false;
                        //d2pAssignmentQuery.BusinessParticipant_RefID = assBussiness.BusinessParticipant_RefID;
                        //var d2pAssignmentRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, d2pAssignmentQuery).ToArray();
                        //if (d2pAssignmentRes.Length == 0)
                        //{
                        //    var docQuery = new ORM_HEC_Doctor.Query();
                        //    docQuery.BusinessParticipant_RefID = assBussiness.BusinessParticipant_RefID;
                        //    var doctor =  ORM_HEC_Doctor.Query.Search(Connection, Transaction, docQuery).First();
                        //    P_L3MD_DDbID_1031 delDoc = new P_L3MD_DDbID_1031();
                        //    delDoc.DoctorID = doctor.HEC_DoctorID;
                        //    var delRes = cls_Delete_Doctor_byID.Invoke(Connection, Transaction, delDoc, securityTicket).Result;
                        //}
                    }
                }

                if (practice.OtherOphthal_PracticeData != null)
                {
                    ORM_HEC_PublicHealthcare_PhysitianAssociation association = new ORM_HEC_PublicHealthcare_PhysitianAssociation();
                    if (practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID != Guid.Empty)
                    {
                        var result = association.Load(Connection, Transaction, practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID);
                        if (result.Status != FR_Status.Success || association.HEC_PublicHealthcare_PhysitianAssociationID == Guid.Empty)
                        {
                            var item = STLD_MedicalAssociation.associationItems.FirstOrDefault(a => a.Value == practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID);
                            if (item != null)
                            {
                                association.IsDeleted = true;
                                association.HealthAssociation_Name = item.Text;
                                association.Save(Connection, Transaction);
                            }
                        }
                    }

                    var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
                    customerQuery.Ext_BusinessParticipant_RefID = practice.BaseInfo.CMN_BPT_BusinessParticipantID;
                    var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).FirstOrDefault();
                    if (customer != null)
                    {
                        customer.IsDeleted = true;
                        customer.Save(Connection, Transaction);
                    }

                    var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query();
                    companyTypeQuery.IsDeleted = false;
                    companyTypeQuery.CMN_COM_CompanyInfo_TypeID = practice.OtherOphthal_PracticeData.CMN_COM_CompanyInfo_TypeID;
                    var companyType      = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery).First();
                    var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query();
                    pHealthcareQuery.HEC_PublicHealthcare_PhysitianAssociationID = practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID;
                    var pHealthcare = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery).First();
                    pHealthcare.IsDeleted = true;
                    pHealthcare.Save(Connection, Transaction);

                    if (customer != null)
                    {
                        var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query();
                        affinityStatusQuery.CMN_BPT_CTM_AffinityStatusID = customer.CustomerAffinityStatus_RefID;
                        var affinityStatus = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery).First();
                        if (affinityStatus != null)
                        {
                            affinityStatus.IsDeleted = true;
                            affinityStatus.Save(Connection, Transaction);
                        }
                    }
                }
            }

            return(returnValue);

            #endregion UserCode
        }