protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2CN_SCCfPI_1409 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var item = new ORM_CMN_PER_CommunicationContact();

            if (Parameter.CMN_PER_CommunicationContactID != Guid.Empty)
            {
                item.Load(Connection, Transaction, Parameter.CMN_PER_CommunicationContactID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_PER_CommunicationContactID));
            }

            if (Parameter.CMN_PER_CommunicationContactID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;
            }

            //GetComunication ContatctTypeID or create it if not exist
            var comunicationContactTypes = cls_Get_AllComunicationContactTypes.Invoke(Connection, Transaction, securityTicket).Result;

            var comunicationContactTypeID = DMComunactionContactTypes.Get_CommunactionContactType_for_GlobalPropertyMatchingID(Connection, Transaction, Parameter.ContactType, securityTicket);

            item.PersonInfo_RefID = Parameter.PersonInfo_RefID;
            item.Contact_Type     = comunicationContactTypeID;
            item.Content          = Parameter.ContactValue;

            return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_PER_CommunicationContactID));

            #endregion UserCode
        }
예제 #2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_SSU_1847 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var userAccount = new ORM_USR_Account();
            var result      = userAccount.Load(Connection, Transaction, Parameter.USR_AccountID);

            if (result.Status == FR_Status.Success)
            {
                //Get business participant via userAccount
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, userAccount.BusinessParticipant_RefID);

                //Load person
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                //Load communication contacts for person
                P_L2CN_GCCfPI_1222 contactsParam = new P_L2CN_GCCfPI_1222();
                contactsParam.PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                var contactsForPersonInfo = cls_Get_ComunicationContacts_for_PersonInfoID.Invoke(Connection, Transaction, contactsParam, securityTicket).Result.ToList();

                if (!Parameter.IsInitialSave)
                {
                    if (Parameter.IsDeleted)
                    {
                        #region Delete

                        var queryApplicationSubscription = new ORM_CMN_Account_ApplicationSubscription.Query();
                        queryApplicationSubscription.Application_RefID = Parameter.ApplicationID;
                        queryApplicationSubscription.Account_RefID     = userAccount.USR_AccountID;
                        queryApplicationSubscription.Tenant_RefID      = securityTicket.TenantID;

                        var foundApplicationSubscription = ORM_CMN_Account_ApplicationSubscription.Query.SoftDelete(Connection, Transaction, queryApplicationSubscription);

                        return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

                        #endregion
                    }

                    #region Edit


                    personInfo.FirstName = Parameter.FirstName_ContactPerson;
                    personInfo.LastName  = Parameter.LastName_ContactPerson;
                    personInfo.Save(Connection, Transaction);

                    var employeeTemp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                    {
                        BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();

                    if (employeeTemp == null)
                    {
                        var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                        newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                        newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                        newEmployee.StandardFunction          = "APOAdminEmployee";
                        newEmployee.Tenant_RefID = securityTicket.TenantID;
                        newEmployee.Save(Connection, Transaction);
                    }


                    var address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    address.Street_Name     = Parameter.Street_Name;
                    address.Street_Number   = Parameter.Street_Number;
                    address.City_Name       = Parameter.Town;
                    address.City_PostalCode = Parameter.ZIP;
                    address.Save(Connection, Transaction);


                    try
                    {
                        //telephone
                        var telephone = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Phone))
                                        .First().Contacts;

                        if (telephone.Count() == 1)
                        {
                            var contactID = telephone[0].CMN_PER_CommunicationContactID;

                            var contactTelephone = new ORM_CMN_PER_CommunicationContact();
                            contactTelephone.Load(Connection, Transaction, contactID);
                            contactTelephone.Content = Parameter.Contact_Telephone;
                            contactTelephone.Save(Connection, Transaction);
                        }
                    }
                    catch
                    {
                        //Log this
                    }

                    #region CommentedUsefull-PreviousWayOfContactEmailHandling

                    //try
                    //{
                    //    //email
                    //    var email = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Email))
                    //        .First().Contacts;

                    //    if (email.Count() == 1)
                    //    {
                    //        var contactID = email[0].CMN_PER_CommunicationContactID;

                    //        var contactEmail = new ORM_CMN_PER_CommunicationContact();
                    //        contactEmail.Load(Connection, Transaction, contactID);
                    //        contactEmail.Content = Parameter.Contact_Email;
                    //        contactEmail.Save(Connection, Transaction);
                    //    }

                    //}
                    //catch
                    //{

                    //    //Log this
                    //}

                    #endregion

                    #endregion
                }

                #region SaveGroup

                var userAccountToGroup = ORM_USR_Account_2_Group.Query.Search(Connection, Transaction, new ORM_USR_Account_2_Group.Query()
                {
                    USR_Account_RefID = userAccount.USR_AccountID,
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false
                }).SingleOrDefault();


                if (userAccountToGroup == null)
                {
                    var newGroup = new ORM_USR_Account_2_Group();
                    newGroup.AssignmentID       = Guid.NewGuid();
                    newGroup.USR_Account_RefID  = userAccount.USR_AccountID;
                    newGroup.USR_Group_RefID    = Parameter.USR_GroupID;
                    newGroup.Creation_Timestamp = DateTime.Now;
                    newGroup.Tenant_RefID       = securityTicket.TenantID;
                    newGroup.Save(Connection, Transaction);
                }
                else
                {
                    userAccountToGroup.USR_Group_RefID = Parameter.USR_GroupID;
                    userAccountToGroup.Save(Connection, Transaction);
                }

                #endregion

                #region SaveEmployee

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (employee == null)
                {
                    var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                    newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                    newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    newEmployee.StandardFunction          = "APOAdminEmployee";
                    newEmployee.Tenant_RefID = securityTicket.TenantID;
                    newEmployee.Save(Connection, Transaction);
                }

                #endregion

                #region CreateOrUpdateContactEmail

                var emailTypeProperty     = EnumUtils.GetEnumDescription(EComunactionContactType.Email);
                var contactEmailTypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                contactEmailTypeQuery.Type         = emailTypeProperty;
                contactEmailTypeQuery.Tenant_RefID = securityTicket.TenantID;
                var contactEmailType = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, contactEmailTypeQuery).FirstOrDefault();

                //Search for default contact email and create it if don't exist

                var defaultContactEmailQuery = new ORM_CMN_PER_CommunicationContact.Query();
                defaultContactEmailQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                defaultContactEmailQuery.Contact_Type     = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                defaultContactEmailQuery.Tenant_RefID     = securityTicket.TenantID;
                var defaultContactEmail = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, defaultContactEmailQuery).FirstOrDefault();

                if (defaultContactEmail == null)
                {
                    defaultContactEmail = new ORM_CMN_PER_CommunicationContact();
                    defaultContactEmail.PersonInfo_RefID        = personInfo.CMN_PER_PersonInfoID;
                    defaultContactEmail.Contact_Type            = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                    defaultContactEmail.IsDefaultForContactType = true;
                    defaultContactEmail.Tenant_RefID            = securityTicket.TenantID;
                }

                defaultContactEmail.Content = Parameter.Contact_Email;
                defaultContactEmail.IsDefaultForContactType = true;
                defaultContactEmail.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                FR_Guid error = new FR_Guid();
                error.ErrorMessage = "No Such ID.";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

            #endregion UserCode
        }
예제 #3
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_MD_SAU_1236 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
            IAccountServiceProvider accountService;
            var _providerFactory = ProviderFactory.Instance;
            accountService = _providerFactory.CreateAccountServiceProvider();

            var accId = Guid.NewGuid();
            if (Parameter.UserID == Guid.Empty)
            {
                if (!String.IsNullOrEmpty(Parameter.LoginEmail))
                {
                    string[] stringUser  = Parameter.LoginEmail.Split('@');
                    string   usernameStr = stringUser[0];

                    Person UserAccount = new Person();
                    UserAccount.FirstName = Parameter.FirstName;
                    UserAccount.LastName  = Parameter.LastName;
                    UserAccount.Title     = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title;
                    Account account = new Account();
                    account.Person       = UserAccount;
                    account.ID           = accId;
                    account.TenantID     = securityTicket.TenantID;
                    account.Email        = Parameter.LoginEmail;
                    account.PasswordHash = Parameter.inPassword;
                    account.Username     = usernameStr;
                    account.AccountType  = EAccountType.Standard;
                    account.Verified     = true;
                    accountService.CreateAccount(account, securityTicket.SessionTicket);
                    accountService.VerifyAccount(account.ID);

                    try
                    {
                        string emailTo  = Parameter.LoginEmail;
                        string appName  = WebConfigurationManager.AppSettings["mmAppUrl"];
                        var    prefix   = HttpContext.Current.Request.Url.AbsoluteUri.Contains("https") ? "https://" : "http://";
                        var    imageUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("api")) + "Content/images/logo.png";

                        var     email_template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/NewUserTemplate.html"));
                        var     subjectsJson   = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailSubjects.json"));
                        dynamic subjects       = Newtonsoft.Json.JsonConvert.DeserializeObject(subjectsJson);
                        var     subjectMail    = subjects["NewUserSubject"].ToString();

                        email_template = EmailTemplater.SetTemplateData(email_template, new
                        {
                            first_name = Parameter.FirstName,
                            salutation = Parameter.Salutation,
                            last_name  = Parameter.LastName,
                            title      = Parameter.Title,
                            password   = Parameter.inPasswordMail,
                            mm_app_url = prefix + HttpContext.Current.Request.Url.Authority + "/" + appName,
                            medios_connect_logo_url = imageUrl
                        }, "{{", "}}");

                        //string mailFrom = cls_Get_Company_Settings.Invoke(Connection, Transaction, securityTicket).Result.Email;
                        string mailFrom = WebConfigurationManager.AppSettings["mailFrom"];
                        EmailNotificationSenderUtil.SendEmail(mailFrom, emailTo, subjectMail, email_template);
                    }
                    catch (Exception ex)
                    {
                        LogUtils.Logger.LogDocAppInfo(new LogUtils.LogEntry(System.Reflection.MethodInfo.GetCurrentMethod(), ex, null, "Add new user: Email sending failed."), "EmailExceptions");
                    }
                    var userAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        IsDeleted     = false,
                        Tenant_RefID  = securityTicket.TenantID,
                        USR_AccountID = accId
                    }).Single();


                    var businesParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = userAccountInfo.BusinessParticipant_RefID
                    }).SingleOrDefault();
                    if (businesParticipant != null)
                    {
                        businesParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastName;
                        businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                        businesParticipant.IsNaturalPerson        = true;
                        businesParticipant.Modification_Timestamp = DateTime.Now;
                        businesParticipant.Save(Connection, Transaction);

                        var companyInfoUser = new ORM_CMN_PER_PersonInfo();
                        companyInfoUser.IsDeleted            = false;
                        companyInfoUser.Tenant_RefID         = securityTicket.TenantID;
                        companyInfoUser.CMN_PER_PersonInfoID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        companyInfoUser.FirstName            = Parameter.FirstName;
                        companyInfoUser.LastName             = Parameter.LastName;
                        companyInfoUser.Salutation_General   = Parameter.Salutation;
                        companyInfoUser.Title = Parameter.Title;
                        companyInfoUser.Save(Connection, Transaction);

                        var communicationContact = new ORM_CMN_PER_CommunicationContact();
                        communicationContact.IsDeleted              = false;
                        communicationContact.Contact_Type           = Guid.NewGuid();
                        communicationContact.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        communicationContact.Content = Parameter.Email;
                        communicationContact.Save(Connection, Transaction);

                        var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType.IsDeleted    = false;
                        communicationContactType.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType.CMN_PER_CommunicationContact_TypeID = communicationContact.Contact_Type;
                        communicationContactType.Type = "Email";
                        communicationContactType.Save(Connection, Transaction);

                        var communicationContactPhone = new ORM_CMN_PER_CommunicationContact();
                        communicationContactPhone.IsDeleted              = false;
                        communicationContactPhone.Contact_Type           = Guid.NewGuid();
                        communicationContactPhone.Tenant_RefID           = securityTicket.TenantID;
                        communicationContactPhone.Modification_Timestamp = DateTime.Now;
                        communicationContactPhone.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                        communicationContactPhone.Content = Parameter.Phone;
                        communicationContactPhone.Save(Connection, Transaction);

                        var communicationContactTypePhone = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactTypePhone.IsDeleted    = false;
                        communicationContactTypePhone.Tenant_RefID = securityTicket.TenantID;
                        communicationContactTypePhone.CMN_PER_CommunicationContact_TypeID = communicationContactPhone.Contact_Type;
                        communicationContactTypePhone.Type = "Phone";
                        communicationContactTypePhone.Save(Connection, Transaction);

                        var accountAppSettings = new ORM_USR_Account_ApplicationSetting();
                        accountAppSettings.IsDeleted          = false;
                        accountAppSettings.Account_RefID      = accId;
                        accountAppSettings.Creation_Timestamp = DateTime.Now;
                        accountAppSettings.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettings.ItemValue          = Parameter.ReceiveNotification.ToString();
                        accountAppSettings.ApplicationSetting_Definition_RefID = Guid.NewGuid();
                        accountAppSettings.Save(Connection, Transaction);

                        var accountAppSettingsDefinitions = new ORM_USR_Account_ApplicationSetting_Definition();
                        accountAppSettingsDefinitions.IsDeleted          = false;
                        accountAppSettingsDefinitions.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettingsDefinitions.Creation_Timestamp = DateTime.Now;
                        accountAppSettingsDefinitions.USR_Account_ApplicationSetting_DefinitionID = accountAppSettings.ApplicationSetting_Definition_RefID;
                        accountAppSettingsDefinitions.ItemKey = "ReceiveNotification";
                        accountAppSettingsDefinitions.Save(Connection, Transaction);
                    }
                }
            }
            else
            { //Edit existing user
                accId = Parameter.UserID;
                var userAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                {
                    IsDeleted     = false,
                    Tenant_RefID  = securityTicket.TenantID,
                    USR_AccountID = Parameter.UserID
                }).Single();

                var businesParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_BPT_BusinessParticipantID = userAccountInfo.BusinessParticipant_RefID
                }).SingleOrDefault();
                if (businesParticipant != null)
                {
                    businesParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastName;
                    businesParticipant.Modification_Timestamp = DateTime.Now;
                    businesParticipant.Save(Connection, Transaction);

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query()
                    {
                        IsDeleted            = false,
                        Tenant_RefID         = securityTicket.TenantID,
                        CMN_PER_PersonInfoID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID
                    }).SingleOrDefault();
                    if (personInfo != null)
                    {
                        personInfo.FirstName          = Parameter.FirstName;
                        personInfo.LastName           = Parameter.LastName;
                        personInfo.Salutation_General = Parameter.Salutation;
                        personInfo.Title = Parameter.Title;
                        personInfo.Save(Connection, Transaction);


                        var phone = cls_Get_Communication_Contact_Info_for_User_Person_Info.Invoke(Connection, Transaction, new P_MD_GCCIFUPID_1716()
                        {
                            CommunicationType = "Phone", PersonRefID = personInfo.CMN_PER_PersonInfoID
                        }, securityTicket).Result;
                        if (phone != null)
                        {
                            var communicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, new ORM_CMN_PER_CommunicationContact.Query()
                            {
                                IsDeleted        = false,
                                Tenant_RefID     = securityTicket.TenantID,
                                PersonInfo_RefID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                                CMN_PER_CommunicationContactID = phone.CMN_PER_CommunicationContactID
                            }).SingleOrDefault();
                            communicationContact.Content = Parameter.Phone;
                            communicationContact.Save(Connection, Transaction);
                        }
                        else
                        {
                            var communicationContactPhone = new ORM_CMN_PER_CommunicationContact();
                            communicationContactPhone.IsDeleted              = false;
                            communicationContactPhone.Contact_Type           = Guid.NewGuid();
                            communicationContactPhone.Tenant_RefID           = securityTicket.TenantID;
                            communicationContactPhone.Modification_Timestamp = DateTime.Now;
                            communicationContactPhone.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                            communicationContactPhone.Content = Parameter.Phone;
                            communicationContactPhone.Save(Connection, Transaction);

                            var communicationContactTypePhone = new ORM_CMN_PER_CommunicationContact_Type();
                            communicationContactTypePhone.IsDeleted    = false;
                            communicationContactTypePhone.Tenant_RefID = securityTicket.TenantID;
                            communicationContactTypePhone.CMN_PER_CommunicationContact_TypeID = communicationContactPhone.Contact_Type;
                            communicationContactTypePhone.Type = "Phone";
                            communicationContactTypePhone.Save(Connection, Transaction);
                        }


                        var email = cls_Get_Communication_Contact_Info_for_User_Person_Info.Invoke(Connection, Transaction, new P_MD_GCCIFUPID_1716()
                        {
                            CommunicationType = "Email", PersonRefID = personInfo.CMN_PER_PersonInfoID
                        }, securityTicket).Result;
                        if (email != null)
                        {
                            var communicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, new ORM_CMN_PER_CommunicationContact.Query()
                            {
                                IsDeleted        = false,
                                Tenant_RefID     = securityTicket.TenantID,
                                PersonInfo_RefID = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                                CMN_PER_CommunicationContactID = email.CMN_PER_CommunicationContactID
                            }).SingleOrDefault();
                            communicationContact.Content = Parameter.Email;
                            communicationContact.Save(Connection, Transaction);
                        }
                        else
                        {
                            var communicationContactPhone = new ORM_CMN_PER_CommunicationContact();
                            communicationContactPhone.IsDeleted              = false;
                            communicationContactPhone.Contact_Type           = Guid.NewGuid();
                            communicationContactPhone.Tenant_RefID           = securityTicket.TenantID;
                            communicationContactPhone.Modification_Timestamp = DateTime.Now;
                            communicationContactPhone.PersonInfo_RefID       = businesParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                            communicationContactPhone.Content = Parameter.Email;
                            communicationContactPhone.Save(Connection, Transaction);

                            var communicationContactTypePhone = new ORM_CMN_PER_CommunicationContact_Type();
                            communicationContactTypePhone.IsDeleted    = false;
                            communicationContactTypePhone.Tenant_RefID = securityTicket.TenantID;
                            communicationContactTypePhone.CMN_PER_CommunicationContact_TypeID = communicationContactPhone.Contact_Type;
                            communicationContactTypePhone.Type = "Email";
                            communicationContactTypePhone.Save(Connection, Transaction);
                        }
                    }

                    var appSettings = ORM_USR_Account_ApplicationSetting.Query.Search(Connection, Transaction, new ORM_USR_Account_ApplicationSetting.Query()
                    {
                        IsDeleted     = false,
                        Tenant_RefID  = securityTicket.TenantID,
                        Account_RefID = accId
                    }).SingleOrDefault();

                    if (appSettings == null)
                    {
                        var accountAppSettings = new ORM_USR_Account_ApplicationSetting();
                        accountAppSettings.IsDeleted          = false;
                        accountAppSettings.Account_RefID      = accId;
                        accountAppSettings.Creation_Timestamp = DateTime.Now;
                        accountAppSettings.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettings.ItemValue          = Parameter.ReceiveNotification.ToString();
                        accountAppSettings.ApplicationSetting_Definition_RefID = Guid.NewGuid();
                        accountAppSettings.Save(Connection, Transaction);

                        var accountAppSettingsDefinitions = new ORM_USR_Account_ApplicationSetting_Definition();
                        accountAppSettingsDefinitions.IsDeleted          = false;
                        accountAppSettingsDefinitions.Tenant_RefID       = securityTicket.TenantID;
                        accountAppSettingsDefinitions.Creation_Timestamp = DateTime.Now;
                        accountAppSettingsDefinitions.USR_Account_ApplicationSetting_DefinitionID = accountAppSettings.ApplicationSetting_Definition_RefID;
                        accountAppSettingsDefinitions.ItemKey = "ReceiveNotification";
                        accountAppSettingsDefinitions.Save(Connection, Transaction);
                    }
                    else
                    {
                        appSettings.ItemValue = Parameter.ReceiveNotification.ToString();
                        appSettings.Save(Connection, Transaction);
                    }

                    var accountStatus = accountService.GetAccountStatusHistory(securityTicket.TenantID, Parameter.UserID).OrderBy(sth => sth.CreationTimestamp).Reverse().FirstOrDefault();
                    if (Parameter.isDeactivated == true)
                    {
                        if (accountStatus.Status != EAccountStatus.BANNED)
                        {
                            accountService.BanAccount(Parameter.UserID, "Konto wurde vom Administrator deaktiviert");
                        }
                    }
                    else
                    {
                        if (accountStatus.Status == EAccountStatus.BANNED)
                        {
                            accountService.UnbanAccount(Parameter.UserID);
                        }
                    }
                }
            }
            P_MD_SPtMU_1433 PSaveUserPermisions = new P_MD_SPtMU_1433();
            PSaveUserPermisions.AccountID = accId;
            PSaveUserPermisions.Role      = Parameter.isAdmin ? Properties.Settings.Default.MasterAccountMMApp : Properties.Settings.Default.RegularAccountMMApp;
            PSaveUserPermisions.GroupName = Properties.Settings.Default.MMAppGroup;
            cls_Save_Permisions_to_User.Invoke(Connection, Transaction, PSaveUserPermisions, securityTicket);
            return(returnValue);

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

            var doctor = new ORM_HEC_Doctor();

            if (Parameter.DoctorID != Guid.Empty)
            {
                var result = doctor.Load(Connection, Transaction, Parameter.DoctorID);
                if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                #region Edit

                bool bopAccIsChenged = (doctor.Account_RefID == Parameter.Account_RefID) ? false : true;

                doctor.Account_RefID = Parameter.Account_RefID;
                if (Parameter.isLucentisSave)
                {
                    doctor.DoctorIDNumber = Parameter.ifLucentis_LANR;
                }
                doctor.Save(Connection, Transaction);

                //bussinessParticipant
                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID;

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

                if (!bopAccIsChenged)
                {
                    //personInfo
                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    if (Parameter.isOphthalSave)
                    {
                        personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General;
                        personInfo.Salutation_Letter  = Parameter.ifOphthal_Salutation_Letter;
                    }
                    if (Parameter.isLucentisSave)
                    {
                        personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail;
                    }
                    personInfo.Save(Connection, Transaction);

                    var query4 = new ORM_CMN_PER_CommunicationContact.Query();
                    query4.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList();

                    if (Parameter.Contacts != null)
                    {
                        foreach (var parContact in Parameter.Contacts)
                        {
                            ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID);
                            if (communicationContacts != null)
                            {
                                communicationContacts.Tenant_RefID = securityTicket.TenantID;
                                communicationContacts.Content      = parContact.Content;
                                communicationContacts.Save(Connection, Transaction);
                            }
                            else
                            {
                                communicationContacts = new ORM_CMN_PER_CommunicationContact();
                                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                                communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                                communicationContacts.Contact_Type       = parContact.CMN_PER_CommunicationContact_TypeID;
                                communicationContacts.Content            = parContact.Content;
                                communicationContacts.Creation_Timestamp = DateTime.Now;
                                communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                                communicationContacts.Save(Connection, Transaction);
                            }
                        }
                    }
                }
                else
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    account2personInfoQuery.IsDeleted         = false;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First();

                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    personInfo.Save(Connection, Transaction);

                    var query4 = new ORM_CMN_PER_CommunicationContact.Query();
                    query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList();

                    if (communicationContactsList != null)
                    {
                        foreach (var c in communicationContactsList)
                        {
                            c.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                            c.Save(Connection, Transaction);
                        }
                    }

                    if (Parameter.Contacts != null)
                    {
                        foreach (var parContact in Parameter.Contacts)
                        {
                            ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID);
                            if (communicationContacts != null)
                            {
                                communicationContacts.Tenant_RefID = securityTicket.TenantID;
                                communicationContacts.Content      = parContact.Content;
                                communicationContacts.Save(Connection, Transaction);
                            }
                            else
                            {
                                communicationContacts = new ORM_CMN_PER_CommunicationContact();
                                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                                communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                                communicationContacts.Contact_Type       = parContact.CMN_PER_CommunicationContact_TypeID;
                                communicationContacts.Content            = parContact.Content;
                                communicationContacts.Creation_Timestamp = DateTime.Now;
                                communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                                communicationContacts.Save(Connection, Transaction);
                            }
                        }
                    }

                    bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    bussinessParticipant.Save(Connection, Transaction);
                }
                if (Parameter.isLucentisSave)
                {
                    foreach (var practice in Parameter.Practices)
                    {
                        //if (practice.PracticeID != Guid.Empty) {

                        var medPract = new ORM_HEC_MedicalPractis.Query();
                        medPract.HEC_MedicalPractiseID = practice.PracticeID;

                        var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();

                        var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                        queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;

                        var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();

                        var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                        practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                        var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                        var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                        query3.BusinessParticipant_RefID           = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                        query3.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                        query3.IsDeleted = false;

                        var associatedbusinessparticipantsOriginal = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3).FirstOrDefault();
                        if (associatedbusinessparticipantsOriginal != null)
                        {
                            associatedbusinessparticipantsOriginal.IsDeleted = practice.isDeleted;
                            associatedbusinessparticipantsOriginal.Save(Connection, Transaction);
                        }
                        else
                        {
                            var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                            associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                            associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                            associatedbusinessparticipants.AssociatedParticipant_FunctionName  = practice.AssociatedParticipant_FunctionName;
                            associatedbusinessparticipants.Creation_Timestamp = DateTime.Now;
                            associatedbusinessparticipants.Tenant_RefID       = securityTicket.TenantID;
                            associatedbusinessparticipants.Save(Connection, Transaction);


                            // }
                        }
                    }
                }
                if (Parameter.isOphthalSave && Parameter.Practices.Length == 1)
                {
                    var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                    query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    query3.IsDeleted = false;
                    var associatedbusinessparticipantsRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3);
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant firstPractice;

                    var medPract = new ORM_HEC_MedicalPractis.Query();
                    medPract.HEC_MedicalPractiseID = Parameter.Practices[0].PracticeID;
                    var medicalPractice  = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();
                    var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                    queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                    var companyInfo   = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();
                    var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                    var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                    if (associatedbusinessparticipantsRes.Count > 0)
                    {
                        associatedbusinessparticipantsRes = associatedbusinessparticipantsRes.OrderBy(a => a.Creation_Timestamp).ToList();
                        firstPractice = associatedbusinessparticipantsRes.First();
                        foreach (var item in associatedbusinessparticipantsRes)
                        {
                            if (item != firstPractice && item.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == practiceBPT.CMN_BPT_BusinessParticipantID)
                            {
                                item.IsDeleted = true;
                                item.Save(Connection, Transaction);
                            }
                        }
                    }
                    else
                    {
                        firstPractice = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                        firstPractice.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                        firstPractice.Tenant_RefID = securityTicket.TenantID;
                        firstPractice.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    }
                    firstPractice.AssociatedParticipant_FunctionName  = Parameter.Practices[0].AssociatedParticipant_FunctionName;
                    firstPractice.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                    firstPractice.Save(Connection, Transaction);
                }
                #endregion
            }
            else
            {
                #region Save

                //personInfo
                Guid personInfoID;
                if (Parameter.Account_RefID == Guid.Empty)
                {
                    var personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.FirstName            = Parameter.FirstName;
                    personInfo.LastName             = Parameter.LastName;
                    if (Parameter.isLucentisSave)
                    {
                        personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail;
                    }
                    personInfo.Title = Parameter.Title;
                    personInfo.Creation_Timestamp = DateTime.Now;
                    personInfo.Tenant_RefID       = securityTicket.TenantID;
                    if (Parameter.isOphthalSave)
                    {
                        personInfo.Salutation_Letter  = Parameter.ifOphthal_Salutation_Letter;
                        personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General;
                    }
                    personInfo.Save(Connection, Transaction);
                    personInfoID = personInfo.CMN_PER_PersonInfoID;
                }
                else
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    account2personInfoQuery.IsDeleted         = false;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First();

                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    personInfo.Save(Connection, Transaction);

                    personInfoID = personInfo.CMN_PER_PersonInfoID;
                }
                //bussinessParticipants
                var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant();
                bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bussinessParticipantTable.IsNaturalPerson    = true;
                bussinessParticipantTable.IsTenant           = false;
                bussinessParticipantTable.IsCompany          = false;
                bussinessParticipantTable.IsDeleted          = false;
                bussinessParticipantTable.Creation_Timestamp = DateTime.Now;
                bussinessParticipantTable.Tenant_RefID       = securityTicket.TenantID;
                bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                bussinessParticipantTable.Save(Connection, Transaction);

                doctor.HEC_DoctorID = Guid.NewGuid();
                if (Parameter.isLucentisSave)
                {
                    doctor.DoctorIDNumber = Parameter.ifLucentis_LANR;
                }
                doctor.Creation_Timestamp        = DateTime.Now;
                doctor.Tenant_RefID              = securityTicket.TenantID;
                doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                doctor.Account_RefID             = Parameter.Account_RefID;
                doctor.Save(Connection, Transaction);

                if (Parameter.Contacts != null)
                {
                    foreach (var contact in Parameter.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();
                        communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                        communicationContacts.PersonInfo_RefID   = personInfoID;
                        communicationContacts.Contact_Type       = contact.CMN_PER_CommunicationContact_TypeID;
                        communicationContacts.Content            = contact.Content;
                        communicationContacts.Creation_Timestamp = DateTime.Now;
                        communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                        communicationContacts.Save(Connection, Transaction);
                    }
                }

                foreach (var practice in Parameter.Practices)
                {
                    if (practice.isDeleted == true)
                    {
                        continue;
                    }

                    var medPract = new ORM_HEC_MedicalPractis.Query();
                    medPract.HEC_MedicalPractiseID = practice.PracticeID;
                    var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();

                    var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                    queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                    var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();

                    var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                    var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                    //associatedbusinessparticipants
                    var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                    associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                    associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                    associatedbusinessparticipants.AssociatedParticipant_FunctionName  = practice.AssociatedParticipant_FunctionName;
                    associatedbusinessparticipants.Creation_Timestamp = DateTime.Now;
                    associatedbusinessparticipants.Tenant_RefID       = securityTicket.TenantID;
                    associatedbusinessparticipants.Save(Connection, Transaction);
                }
                #endregion
            }

            returnValue.Result = doctor.HEC_DoctorID;
            return(returnValue);

            #endregion UserCode
        }
예제 #5
0
        public static void Save_Doctors_to_DB(Doctor_model_from_xlsx Parameter, string connectionString, SessionSecurityTicket securityTicket)
        {
            DbConnection  Connection         = null;
            DbTransaction Transaction        = null;
            bool          cleanupConnection  = Connection == null;
            bool          cleanupTransaction = Transaction == null;

            if (cleanupConnection == true)
            {
                Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString);
                Connection.Open();
            }
            if (cleanupTransaction == true)
            {
                Transaction = Connection.BeginTransaction();
            }
            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
                Guid   BusinessParticipantID         = Guid.NewGuid();
                Guid   personInfoID                  = Guid.NewGuid();
                Guid   PracticeCustomerID            = Guid.NewGuid();
                Guid   PracticeBusinessParticipantID = Guid.NewGuid();
                Guid   PracticeCompanyInfoID         = Guid.NewGuid();
                String PracticeName                  = "";
                Guid   BankAccountID                 = Guid.Empty;
                Guid   doctor_id    = Parameter.DoctorID;
                var    isOpPractice = false;

                if (!String.IsNullOrEmpty(Parameter.LoginEmail))
                //uncomment this if you've created account
                //  if (false)
                {
                    string[] stringUser  = Parameter.LoginEmail.Split('@');
                    string   usernameStr = stringUser[0];

                    try
                    {
                        var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            AccountSignInEmailAddress = Parameter.LoginEmail,
                        }).Single();

                        var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query();
                        accountGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                        accountGroupQuery.IsDeleted                = false;
                        accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";

                        var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault();

                        if (accountGroup == null)
                        {
                            accountGroup = new ORM_USR_Account_FunctionLevelRights_Group();
                            accountGroup.Tenant_RefID             = securityTicket.TenantID;
                            accountGroup.Label                    = "mm.docconect.doc.app.group";
                            accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";
                            accountGroup.Creation_Timestamp       = DateTime.Now;
                            accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid();
                            accountGroup.Save(Connection, Transaction);
                        }

                        var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            HEC_MedicalPractice_RefID = Parameter.PracticeID
                        }).ToList();

                        List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>();
                        foreach (var item in PracticeAccount2UniversalProperty)
                        {
                            var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query()
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID
                            }).Single();
                            PracticeUniversalPropertyList.Add(PracticeUniversalProperty);
                        }
                        ;

                        P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522();
                        practiceAccountIDParameter.PracticeID = Parameter.PracticeID;

                        var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query();
                        practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID;
                        practiceAccountToFunctionLevelRightQ.Tenant_RefID  = securityTicket.TenantID;
                        practiceAccountToFunctionLevelRightQ.IsDeleted     = false;

                        var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault();

                        if (practiceAccountToFunctionLevelRight != null)
                        {
                            var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                            practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID;
                            practiceAccountFunctionLevelRightQ.IsDeleted    = false;
                            practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID;

                            var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault();

                            if (practiceAccountFunctionLevelRight != null)
                            {
                                isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice");
                            }
                        }

                        var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                        functionLevelRightQ.IsDeleted                = false;
                        functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

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

                        var tempFunctionLevelRightID = Guid.Empty;

                        if (existingFunctionLevelRight == null)
                        {
                            ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight();
                            functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid();
                            functionLevelRight.FunctionLevelRights_Group_RefID  = accountGroup.USR_Account_FunctionLevelRights_GroupID;
                            functionLevelRight.Tenant_RefID       = securityTicket.TenantID;
                            functionLevelRight.Creation_Timestamp = DateTime.Now;

                            functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";
                            functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                            functionLevelRight.Save(Connection, Transaction);

                            tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                        }
                        else
                        {
                            tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID;
                        }

                        var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight();
                        accountToFunctionLevelRight.Tenant_RefID             = securityTicket.TenantID;
                        accountToFunctionLevelRight.Creation_Timestamp       = DateTime.Now;
                        accountToFunctionLevelRight.AssignmentID             = Guid.NewGuid();
                        accountToFunctionLevelRight.Account_RefID            = doctorAccountInfo.USR_AccountID;
                        accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID;

                        accountToFunctionLevelRight.Save(Connection, Transaction);

                        var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

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

                        var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();
                        DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                        DoctorBusinessParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastNAme;
                        DoctorBusinessParticipant.IsNaturalPerson        = true;
                        DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                        DoctorBusinessParticipant.Save(Connection, Transaction);
                        personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;


                        var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                        companyInfoPractice.IsDeleted            = false;
                        companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                        companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                        companyInfoPractice.FirstName            = Parameter.FirstName;
                        companyInfoPractice.LastName             = Parameter.LastNAme;
                        companyInfoPractice.Salutation_General   = Parameter.Salutation;
                        companyInfoPractice.Title = Parameter.Title;
                        companyInfoPractice.Save(Connection, Transaction);

                        var communicationContact = new ORM_CMN_PER_CommunicationContact();
                        communicationContact.IsDeleted              = false;
                        communicationContact.Contact_Type           = Guid.NewGuid();
                        communicationContact.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.PersonInfo_RefID       = personInfoID;
                        communicationContact.Content = Parameter.Email;
                        communicationContact.Save(Connection, Transaction);
                        Guid CommunicationContactTypeID = communicationContact.Contact_Type;


                        var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType.IsDeleted    = false;
                        communicationContactType.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                        communicationContactType.Type = "Email";
                        communicationContactType.Save(Connection, Transaction);

                        var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                        communicationContact2.IsDeleted              = false;
                        communicationContact2.Contact_Type           = Guid.NewGuid();
                        communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact2.Modification_Timestamp = DateTime.Now;
                        communicationContact2.PersonInfo_RefID       = personInfoID;
                        communicationContact2.Content = Parameter.Phone;
                        communicationContact2.Save(Connection, Transaction);
                        Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                        var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType2.IsDeleted    = false;
                        communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                        communicationContactType2.Type = "Phone";
                        communicationContactType2.Save(Connection, Transaction);

                        var doctor = new ORM_HEC_Doctor();
                        doctor.HEC_DoctorID = Guid.NewGuid();
                        doctor.IsDeleted    = false;
                        doctor.Tenant_RefID = securityTicket.TenantID;
                        doctor.BusinessParticipant_RefID = BusinessParticipantID;
                        doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                        doctor.Account_RefID             = Parameter.account_id;

                        doctor.Save(Connection, Transaction);

                        doctor_id = doctor.HEC_DoctorID;

                        var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                        }).Single();


                        var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                        organizationalunit_Staff.IsDeleted    = false;
                        organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                        organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                        organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                        organizationalunit_Staff.Save(Connection, Transaction);

                        var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                        {
                            IsDeleted              = false,
                            Tenant_RefID           = securityTicket.TenantID,
                            CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                        }).Single();
                        var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                        }).Single();

                        PracticeName = PracticeBusinessParticipant.DisplayName;
                        PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                        PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                        if (Parameter.IsUsePracticeBank)
                        {
                            var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                            }).Single();


                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                            //end of save bank data if inherited from practice
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                                business2bankAccount.IsDeleted    = false;
                                business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                                business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                                business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                                business2bankAccount.Creation_Timestamp = DateTime.Now;
                                business2bankAccount.Save(Connection, Transaction);

                                var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                                bankAccountDoctor.IsDeleted             = false;
                                bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                                bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                                bankAccountDoctor.OwnerText             = Parameter.AccountHolder;
                                bankAccountDoctor.IBAN               = Parameter.IBAN;
                                bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                                bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                                bankAccountDoctor.Save(Connection, Transaction);

                                if (!String.IsNullOrEmpty(Parameter.Bank))
                                {
                                    var bank = new ORM_ACC_BNK_Bank();
                                    bank.IsDeleted          = false;
                                    bank.Tenant_RefID       = securityTicket.TenantID;
                                    bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                    bank.BICCode            = Parameter.Bic;
                                    bank.BankName           = Parameter.Bank;
                                    bank.Creation_Timestamp = DateTime.Now;
                                    bank.Save(Connection, Transaction);
                                }

                                BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                                // end save bank data
                            }
                        }
                    }
                    catch
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();

                    DoctorBusinessParticipant.IsDeleted    = false;
                    DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                    DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                    DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                    DoctorBusinessParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastNAme;
                    DoctorBusinessParticipant.IsNaturalPerson        = true;
                    DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                    DoctorBusinessParticipant.Save(Connection, Transaction);
                    personInfoID          = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID;

                    var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                    companyInfoPractice.IsDeleted            = false;
                    companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                    companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                    companyInfoPractice.FirstName            = Parameter.FirstName;
                    companyInfoPractice.LastName             = Parameter.LastNAme;
                    companyInfoPractice.Salutation_General   = Parameter.Salutation;
                    companyInfoPractice.Title = Parameter.Title;
                    companyInfoPractice.Save(Connection, Transaction);

                    var communicationContact = new ORM_CMN_PER_CommunicationContact();
                    communicationContact.IsDeleted              = false;
                    communicationContact.Contact_Type           = Guid.NewGuid();
                    communicationContact.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact.Modification_Timestamp = DateTime.Now;
                    communicationContact.PersonInfo_RefID       = personInfoID;
                    communicationContact.Content = Parameter.Email;
                    communicationContact.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID = communicationContact.Contact_Type;

                    var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType.IsDeleted    = false;
                    communicationContactType.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                    communicationContactType.Type = "Email";
                    communicationContactType.Save(Connection, Transaction);

                    var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                    communicationContact2.IsDeleted              = false;
                    communicationContact2.Contact_Type           = Guid.NewGuid();
                    communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact2.Modification_Timestamp = DateTime.Now;
                    communicationContact2.PersonInfo_RefID       = personInfoID;
                    communicationContact2.Content = Parameter.Phone;
                    communicationContact2.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                    var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType2.IsDeleted    = false;
                    communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                    communicationContactType2.Type = "Phone";
                    communicationContactType2.Save(Connection, Transaction);

                    var doctor = new ORM_HEC_Doctor();
                    doctor.HEC_DoctorID = Guid.NewGuid();
                    doctor.IsDeleted    = false;
                    doctor.Tenant_RefID = securityTicket.TenantID;
                    doctor.BusinessParticipant_RefID = BusinessParticipantID;
                    doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                    doctor.Account_RefID             = Parameter.account_id;

                    doctor.Save(Connection, Transaction);

                    doctor_id = doctor.HEC_DoctorID;

                    var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).Single();


                    var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                    organizationalunit_Staff.IsDeleted    = false;
                    organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                    organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                    organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                    organizationalunit_Staff.Save(Connection, Transaction);


                    var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                    {
                        IsDeleted              = false,
                        Tenant_RefID           = securityTicket.TenantID,
                        CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                    }).Single();
                    var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                    }).Single();
                    PracticeName = PracticeBusinessParticipant.DisplayName;
                    PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                    PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    if (Parameter.IsUsePracticeBank == true)
                    {
                        var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                        }).Single();


                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        //end of save bank data if inherited from practice
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                            bankAccountDoctor.IsDeleted             = false;
                            bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                            bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            bankAccountDoctor.OwnerText             = Parameter.AccountHolder;
                            bankAccountDoctor.IBAN               = Parameter.IBAN;
                            bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                            bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                            bankAccountDoctor.Save(Connection, Transaction);

                            if (!String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var bank = new ORM_ACC_BNK_Bank();
                                bank.IsDeleted          = false;
                                bank.Tenant_RefID       = securityTicket.TenantID;
                                bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                bank.BICCode            = Parameter.Bic;
                                bank.BankName           = Parameter.Bank;
                                bank.Creation_Timestamp = DateTime.Now;
                                bank.Save(Connection, Transaction);
                            }

                            BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            // end save bank data
                        }
                    }
                }
                var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query()
                {
                    IsDeleted           = false,
                    Tenant_RefID        = securityTicket.TenantID,
                    CompanyInfo_RefID   = PracticeCompanyInfoID,
                    Address_Description = "Standard address for billing, shipping",
                }).SingleOrDefault();



                Practice_Doctors_Model DPModel = new Practice_Doctors_Model();

                if (PracticeCompanyInfoAddress != null)
                {
                    var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID,
                    }).SingleOrDefault();
                    DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number;
                    DPModel.zip     = PracticeUCD.ZIP;
                    DPModel.city    = PracticeUCD.Town;
                }

                DPModel.account_status = "aktiv";
                DPModel.id             = doctor_id.ToString();

                var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim();

                DPModel.name              = title + " " + Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.name_untouched    = Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.bsnr_lanr         = Parameter.LANR.ToString();
                DPModel.autocomplete_name = title + " " + Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.salutation        = title;

                DPModel.type = "Doctor";

                DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;

                DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;


                DPModel.phone = Parameter.Phone;

                DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email;

                DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN;

                DPModel.bic = string.IsNullOrEmpty(Parameter.Bic) ? "" : Parameter.Bic;

                DPModel.bank_id             = BankAccountID.ToString();
                DPModel.bank_info_inherited = Parameter.IsUsePracticeBank;
                DPModel.aditional_info      = "";
                DPModel.contract            = 0;


                DPModel.tenantid = securityTicket.TenantID.ToString();
                DPModel.practice_name_for_doctor = PracticeName;
                DPModel.practice_for_doctor_id   = Parameter.PracticeID.ToString();

                DPModel.role = isOpPractice ? "op" : "ac";

                List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>();
                DPModelL.Add(DPModel);

                Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString());

                #region Assignment to Contract

                var contractIvi = ORM_CMN_CTR_Contract.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    ContractName = "IVI-Vertrag"
                }).SingleOrDefault();
                if (contractIvi != null)
                {
                    Guid AssignmentID = Guid.NewGuid();
                    var  insuranceTobrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract.Query()
                    {
                        Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false,
                    }).SingleOrDefault();
                    if (insuranceTobrokerContract != null)
                    {
                        AssignmentID = insuranceTobrokerContract.HEC_CRT_InsuranceToBrokerContractID;
                    }
                    else
                    {
                        var insuranceTobrokerContractNew = new ORM_HEC_CRT_InsuranceToBrokerContract();
                        insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID = Guid.NewGuid();
                        insuranceTobrokerContractNew.Creation_Timestamp         = DateTime.Now;
                        insuranceTobrokerContractNew.IsDeleted                  = false;
                        insuranceTobrokerContractNew.Tenant_RefID               = securityTicket.TenantID;
                        insuranceTobrokerContractNew.Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID;
                        insuranceTobrokerContractNew.Save(Connection, Transaction);
                        AssignmentID = insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID;
                    }
                    var insuranceTobrokerContract2doctor = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctor();
                    insuranceTobrokerContract2doctor.Creation_Timestamp = DateTime.Now;
                    insuranceTobrokerContract2doctor.HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctorID = Guid.NewGuid();
                    insuranceTobrokerContract2doctor.InsuranceToBrokerContract_RefID = AssignmentID;
                    insuranceTobrokerContract2doctor.Tenant_RefID = securityTicket.TenantID;
                    insuranceTobrokerContract2doctor.IsDeleted    = false;
                    insuranceTobrokerContract2doctor.Doctor_RefID = doctor_id;
                    insuranceTobrokerContract2doctor.ValidFrom    = new DateTime(2013, 6, 15);
                    insuranceTobrokerContract2doctor.ValidThrough = DateTime.MinValue;
                    insuranceTobrokerContract2doctor.Save(Connection, Transaction);

                    P_DO_CDCD_1505 ParameterDoctorID = new P_DO_CDCD_1505();
                    ParameterDoctorID.DoctorID = doctor_id;
                    var data = cls_Get_Doctor_Contract_Numbers.Invoke(Connection, Transaction, ParameterDoctorID, securityTicket).Result;

                    int DoctorContracts = data.Count();
                    Doctor_Contracts ParameterDoctor = new Doctor_Contracts();
                    ParameterDoctor.DocID = doctor_id;

                    Practice_Doctors_Model DoctorFound = Get_Doctors_for_PracticeID.Set_Contract_Number_for_DoctorID(ParameterDoctor, securityTicket);

                    if (DoctorFound != null)
                    {
                        List <Practice_Doctors_Model> DoctorFoundL = new List <Practice_Doctors_Model>();
                        DoctorFound.contract = DoctorContracts;
                        DoctorFoundL.Add(DoctorFound);
                        Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DoctorFoundL, securityTicket.TenantID.ToString());
                    }


                    P_DO_GPIDfDID_1353 ParametarDocID = new P_DO_GPIDfDID_1353();
                    ParametarDocID.DoctorID = doctor_id;
                    DO_GPIDfDID_1353[] data2 = cls_Get_PracticeID_for_DoctorID.Invoke(Connection, Transaction, ParametarDocID, securityTicket).Result;

                    P_DO_GCfPID_1507 ParametarPractice = new P_DO_GCfPID_1507();

                    ParametarPractice.PracticeID = data2.First().HEC_MedicalPractiseID;
                    DO_GCfPID_1507[] Contracts       = cls_Get_all_Doctors_Contract_Assignment_for_PracticeID.Invoke(Connection, Transaction, ParametarPractice, securityTicket).Result;
                    int NumberOfContractsForPractice = Contracts.Count();
                    Practice_Doctors_Model practice  = new Practice_Doctors_Model();
                    practice.id = ParametarPractice.PracticeID.ToString();

                    Practice_Doctors_Model        PracticeFound = Get_Doctors_for_PracticeID.Get_Practice_for_PracticeID(practice, securityTicket);
                    List <Practice_Doctors_Model> practiceL     = new List <Practice_Doctors_Model>();
                    PracticeFound.contract = NumberOfContractsForPractice;
                    practiceL.Add(PracticeFound);
                    Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(practiceL, securityTicket.TenantID.ToString());
                }
                #endregion



                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
            }



            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw ex;
            }
        }
예제 #6
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_DDBID_1653 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here


            P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653();
            param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID;

            var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result;

            var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID);

            if (driver != null)
            {
                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                if (driver.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    var result = person.Load(Connection, Transaction, driver.CMN_PER_PersonInfoID);
                    if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    person.IsDeleted = true;
                    person.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, driver.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);
                }

                if (driver.Contacts != null)
                {
                    foreach (var parContact in driver.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                        if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty)
                        {
                            var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID);
                            if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                            {
                                var error = new FR_Guid();
                                error.ErrorMessage = "No Such ID";
                                error.Status       = FR_Status.Error_Internal;
                                return(error);
                            }
                            contact.IsDeleted = true;
                            contact.Save(Connection, Transaction);
                        }
                    }
                }

                ORM_CMN_Address adress = new ORM_CMN_Address();
                if (driver.CMN_AddressID != Guid.Empty)
                {
                    var result = adress.Load(Connection, Transaction, driver.CMN_AddressID);
                    if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    adress.IsDeleted = true;
                    adress.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();
                if (driver.CMN_BPT_SupplierID != Guid.Empty)
                {
                    var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID);
                    if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    supplier.IsDeleted = true;
                    supplier.Save(Connection, Transaction);
                }

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


                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID);
                    if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true;
                    BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction);
                }

                ORM_USR_Account account = new ORM_USR_Account();
                if (driver.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, driver.USR_AccountID);
                    if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty)
                {
                    var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID);
                    if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    Device_AccountCode_StatusHistory.IsDeleted = true;
                    Device_AccountCode_StatusHistory.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                if (driver.USR_Device_AccountCodeID != Guid.Empty)
                {
                    var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID);
                    if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    accountCode.IsDeleted = true;
                    accountCode.Save(Connection, Transaction);
                }

                var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query();
                Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_UsageHistoryQuery.IsDeleted    = false;
                Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID;

                var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery);
                if (historyArray != null && historyArray.Count > 0)
                {
                    foreach (var historyItem in historyArray)
                    {
                        historyItem.IsDeleted = true;
                        historyItem.Save(Connection, Transaction);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
예제 #7
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_SD_1537 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            if (Parameter.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                #region Create Mode

                #region BusinessParticipant


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

                #endregion

                #region Account

                ORM_USR_Account account = new ORM_USR_Account();

                account.Username    = Parameter.FirstName + "_" + Parameter.LastName;
                account.AccountType = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID       = securityTicket.TenantID;
                account.Creation_Timestamp = DateTime.Now;
                account.Save(Connection, Transaction);

                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                accountCode.Account_RefID                   = account.USR_AccountID;
                accountCode.AccountCode_Value               = checkCodeValue.CodeValue;
                accountCode.AccountCode_ValidFrom           = DateTime.Now;
                accountCode.AccountCode_CurrentStatus_RefID = Guid.NewGuid();
                accountCode.IsAccountCode_Expirable         = false;
                accountCode.Tenant_RefID       = securityTicket.TenantID;
                accountCode.Creation_Timestamp = DateTime.Now;
                accountCode.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID = accountCode.AccountCode_CurrentStatus_RefID;
                Device_AccountCode_StatusHistory.IsAccountCode_Active     = true;
                Device_AccountCode_StatusHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_StatusHistory.Tenant_RefID             = securityTicket.TenantID;
                Device_AccountCode_StatusHistory.Creation_Timestamp       = DateTime.Now;
                Device_AccountCode_StatusHistory.Save(Connection, Transaction);


                ORM_USR_Device_AccountCode_UsageHistory USR_Device_AccountCode_UsageHistory = new ORM_USR_Device_AccountCode_UsageHistory();
                USR_Device_AccountCode_UsageHistory.USR_Device_AccountCode_UsageHistoryID = Guid.NewGuid();
                USR_Device_AccountCode_UsageHistory.Tenant_RefID             = securityTicket.TenantID;
                USR_Device_AccountCode_UsageHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                USR_Device_AccountCode_UsageHistory.Creation_Timestamp       = DateTime.Now;
                USR_Device_AccountCode_UsageHistory.Save(Connection, Transaction);


                #endregion

                #region PersonInfo and Adresses

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Salutation_General   = Parameter.Salutation_General;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryMail;
                personInfo.Address_RefID        = Guid.NewGuid();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_PER_PersonInfo_2_Address personAdress = new ORM_CMN_PER_PersonInfo_2_Address();
                personAdress.AssignmentID             = Guid.NewGuid();
                personAdress.CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                personAdress.CMN_Address_RefID        = personInfo.Address_RefID;
                personAdress.IsPrimary    = true;
                personAdress.Tenant_RefID = securityTicket.TenantID;
                personAdress.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.CMN_AddressID   = personInfo.Address_RefID;
                adress.City_Name       = Parameter.City_Name;
                adress.Province_Name   = Parameter.Province_Name;
                adress.Street_Name     = Parameter.Street_Name;
                adress.Street_Number   = Parameter.Street_Number;
                adress.City_PostalCode = Parameter.City_PostalCode;
                adress.Tenant_RefID    = securityTicket.TenantID;
                adress.Save(Connection, Transaction);

                #endregion

                #region Contacts

                foreach (var parContact in Parameter.Contacts)
                {
                    ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                    contact.Content          = parContact.Content;
                    contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Tenant_RefID     = securityTicket.TenantID;
                    contact.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    contact.Save(Connection, Transaction);
                }

                #endregion

                #region Driver To Employer

                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant bpt_asBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                bpt_asBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                bpt_asBP.BusinessParticipant_RefID          = bParticipant.CMN_BPT_BusinessParticipantID;
                bpt_asBP.AssociatedParticipant_FunctionName = "Driver";
                bpt_asBP.Tenant_RefID = securityTicket.TenantID;
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);

                #endregion

                #endregion
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                personInfo.Salutation_General = Parameter.Salutation_General;
                personInfo.FirstName          = Parameter.FirstName;
                personInfo.LastName           = Parameter.LastName;
                personInfo.PrimaryEmail       = Parameter.PrimaryMail;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.Load(Connection, Transaction, personInfo.Address_RefID);
                adress.City_Name     = Parameter.City_Name;
                adress.Province_Name = Parameter.Province_Name;
                adress.Street_Name   = Parameter.Street_Name;
                adress.Street_Number = Parameter.Street_Number;
                adress.Save(Connection, Transaction);

                foreach (var parContact in Parameter.Contacts)
                {
                    var query = new ORM_CMN_PER_CommunicationContact.Query();
                    query.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    query.IsDeleted        = false;
                    query.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var contact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query).First();
                    contact.Content      = parContact.Content;
                    contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Save(Connection, Transaction);
                }

                var associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.BusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;

                var bpt_asBP = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery).First();
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);
            }
            return(returnValue);

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

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name       = Parameter.City_Name;
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.Country_Name    = Parameter.Country_Name;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success address");
            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = securityTicket.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.ProfileImage_Document_RefID = Parameter.ImageID;
            person.BirthDate        = Parameter.BirthDate;
            person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0;
            person.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success persopm");

            var contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            contactQuery.IsDeleted        = false;
            var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery);
            foreach (var parContact in Parameter.Contacts)
            {
                ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                if (parContact.CMN_PER_CommunicationContactID != Guid.Empty)
                {
                    var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID);
                    if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
                contact.Content          = parContact.Content;
                contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                contact.Tenant_RefID     = securityTicket.TenantID;
                contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contact.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success contact");
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.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.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            CSV2Core.DlTrace.Trace("success bpart");


            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = securityTicket.TenantID;
            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employee");


            ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID != Guid.Empty)
            {
                var result = employmentRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID);
                if (result.Status != FR_Status.Success || employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employmentRelationship.Work_StartDate = Parameter.Work_StartDate;

            bool resignationDateChanged = false;
            if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate)
            {
                resignationDateChanged = true;
            }

            employmentRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employmentRelationship.Tenant_RefID   = securityTicket.TenantID;
            employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employmentRelationship.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employmentRelationship");

            if (Parameter.Work_EndDate.Ticks != 0)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID;
                empRelationShipToWorkingContractQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery);
                foreach (var workingContractAssignment in workingContractAssignments)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    if (workingContractAssignment.WorkingContract_RefID != Guid.Empty)
                    {
                        var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID);
                        if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks)
                    {
                        workingContract.Contract_EndDate         = Parameter.Work_EndDate;
                        workingContract.IsContractEndDateDefined = true;
                        workingContract.Save(Connection, Transaction);
                    }
                }
            }

            var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result;

            var timeframes   = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList();
            if (resultFrames.Count == 0)
            {
                var newFrame    = new ORM_CMN_CAL_CalculationTimeframe();
                int currentYear = Parameter.Work_StartDate.Year;
                while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year)
                {
                    if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear))
                    {
                        newFrame.CalculationTimeframe_StartDate        = new DateTime(currentYear, 1, 1);
                        newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31);
                        newFrame.Tenant_RefID = securityTicket.TenantID;
                        newFrame.Save(Connection, Transaction);
                        newFrame = new ORM_CMN_CAL_CalculationTimeframe();
                    }
                    currentYear++;

                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    relationshipFrame.CalculationTimeframe_RefID   = newFrame.CMN_CAL_CalculationTimeframeID;
                    relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                    relationshipFrame.Save(Connection, Transaction);
                }
            }
            else
            {
                timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList();
                foreach (var timeframe in timeframes)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query();
                    relationshipFrameQuery.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                    relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID;
                    List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery);
                    if (oldContractFrames.Count == 0)
                    {
                        ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                        relationshipFrame.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                        relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                        relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                        relationshipFrame.Save(Connection, Transaction);
                    }
                }
            }



            P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405();
            timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result;
            if (employeeTimeFrame == null)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                timeFrame.CalculationTimeframe_RefID   = activeTimeFrame.CMN_CAL_CalculationTimeframeID;
                timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                timeFrame.Tenant_RefID = securityTicket.TenantID;
                timeFrame.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success timeFrame");
            }

            //save employee professions
            P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447();
            saveProfessionsPar.Employee_RefID    = employee.CMN_BPT_EMP_EmployeeID;
            saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories;
            cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success employee function history");

            //save workplace histories
            P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625();
            saveWorkplaceHistoryPar.Employee_RefID     = employee.CMN_BPT_EMP_EmployeeID;
            saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories;
            cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket);
            CSV2Core.DlTrace.Trace("success workplaceHistories");

            P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648();
            saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveDocuments.Documents      = Parameter.Documents;
            cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket);
            CSV2Core.DlTrace.Trace("success documents");

            P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959();
            saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveSkillsPar.Skills         = Parameter.Skills;
            cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success skills");

            CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID);

            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                CSV2Core.DlTrace.Trace("success param");

                ORM_USR_Account account = new ORM_USR_Account();
                if (Parameter.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, Parameter.USR_AccountID);
                    if (account.USR_AccountID == Guid.Empty)
                    {
                        account.USR_AccountID = Guid.NewGuid();
                        account.AccountType   = 2;
                    }
                    account.Username = Parameter.username;
                    account.DefaultLanguage_RefID     = Parameter.LanguageID;
                    account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                    account.Tenant_RefID = securityTicket.TenantID;
                    account.Save(Connection, Transaction);


                    var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                    personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                    personToAccountQuery.IsDeleted         = false;
                    var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                    if (personToAccounts.Count != 0)
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                }



                if (Parameter.Rights != null)
                {
                    foreach (var rightsParam in Parameter.Rights)
                    {
                        if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            right2account.Account_RefID            = Parameter.USR_AccountID;
                            right2account.FunctionLevelRight_RefID = rightsParam.RightID;
                            right2account.Tenant_RefID             = securityTicket.TenantID;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID);
                        }

                        if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            if (rightsParam.RightAssinmentID != Guid.Empty)
                            {
                                var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID);
                                if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty)
                                {
                                    var error = new FR_Guid();
                                    error.ErrorMessage = "No Such ID";
                                    error.Status       = FR_Status.Error_Internal;
                                    return(error);
                                }
                            }
                            right2account.IsDeleted = true;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID);
                        }
                    }
                }
            }

            CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID);

            if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged)
            {
                var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
                KeyPerformanceIndicator action = new KeyPerformanceIndicator();
                action.PerformedByAccountID     = securityTicket.AccountID;
                action.PerformedByApplicationID = Parameter.ApplicationID;
                action.PerformedOn               = DateTime.Now;
                action.PerformedByTenantID       = securityTicket.TenantID;
                action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
                action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length;

                var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);
                // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed"));
                CSV2Core.DlTrace.Trace("success send kpi");
            }

            Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket);
            cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket);
            Parameter.SocialSecurity.CMN_PER_PersonInfoID          = person.CMN_PER_PersonInfoID;
            Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID        = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket);

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

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

            ORM_HEC_MedicalPractis item = new ORM_HEC_MedicalPractis();

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

                #region Delete

                if (Parameter.isDeleted == true)
                {
                    var query_BP_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BP_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_RefID;
                    query_BP_ContactPerson_del.Tenant_RefID = securityTicket.TenantID;

                    var found_BP_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BP_ContactPerson_del).First();
                    found_BP_ContactPerson_del.IsDeleted = true;

                    var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo_del.CMN_PER_PersonInfoID = found_BP_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    var found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First();
                    found_PersonInfo_del.IsDeleted = true;
                    found_PersonInfo_del.Save(Connection, Transaction);


                    var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID;


                    var found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First();
                    found_CommunicationContact_del.IsDeleted = true;

                    found_CommunicationContact_del.Save(Connection, Transaction);


                    var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query();
                    query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                    var found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First();
                    found_CompanyInfo_del.IsDeleted = true;

                    found_CompanyInfo_del.Save(Connection, Transaction);

                    var query_BP_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BP_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID;

                    var found_BP_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BP_Company_del).First();
                    found_BP_Company_del.IsDeleted = true;
                    found_BP_Company_del.Save(Connection, Transaction);

                    var query_UniversalContactDetails_del = new ORM_CMN_UniversalContactDetail.Query();
                    query_UniversalContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID;

                    var found_UniversalCompanyDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_UniversalContactDetails_del).First();

                    found_UniversalCompanyDetails_del.IsDeleted = true;
                    found_UniversalCompanyDetails_del.Save(Connection, Transaction);

                    item.IsDeleted = true;
                    return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_MedicalPractiseID));
                }

                #endregion
                #region Edit

                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = item.ContactPerson_RefID;
                query1.Tenant_RefID    = securityTicket.TenantID;
                query1.IsCompany       = false;
                query1.IsNaturalPerson = true;
                query1.IsTenant        = false;

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


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

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

                personInfo.FirstName    = Parameter.ContactPersonFirstName;
                personInfo.LastName     = Parameter.ContactPersonLastName;
                personInfo.PrimaryEmail = Parameter.ContactPersonEmail;
                personInfo.Save(Connection, Transaction);


                var query3 = new ORM_CMN_PER_CommunicationContact.Query();
                query3.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;


                var communicationContacts = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query3).First();
                communicationContacts.Contact_Type = Parameter.ContactTypePhone;
                communicationContacts.Content      = Parameter.ContactPersonPhoneNumber;

                communicationContacts.Save(Connection, Transaction);


                var query4 = new ORM_CMN_COM_CompanyInfo.Query();
                query4.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query4).First();
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.BSNR;

                companyInfo.Save(Connection, Transaction);

                var query5 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query5.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                var extCompany = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query5).First();
                extCompany.DisplayName = Parameter.PracticeName;
                extCompany.Save(Connection, Transaction);

                var query6 = new ORM_CMN_UniversalContactDetail.Query();
                query6.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;

                var companyDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query6).First();

                companyDetails.ZIP               = Parameter.ZIP;
                companyDetails.Town              = Parameter.Town;
                companyDetails.Street_Name       = Parameter.PracticeStreet;
                companyDetails.Street_Number     = Parameter.PracticeNumber;
                companyDetails.Contact_Email     = Parameter.PracitceEmail;
                companyDetails.Street_Name_Line2 = Parameter.PracticeStreet2;

                companyDetails.Save(Connection, Transaction);
                #endregion
            }
            else
            {
                #region Save

                item.HEC_MedicalPractiseID = Guid.NewGuid();

                item.Creation_Timestamp = DateTime.Now;
                item.Tenant_RefID       = securityTicket.TenantID;


                //business Participants
                ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                Guid businessParticipantsID = Guid.NewGuid();

                contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantsID;
                contactPerson.IsCompany          = false;
                contactPerson.IsNaturalPerson    = true;
                contactPerson.IsTenant           = false;
                contactPerson.Creation_Timestamp = DateTime.Now;
                contactPerson.Tenant_RefID       = securityTicket.TenantID;

                item.ContactPerson_RefID = businessParticipantsID;

                //person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                Guid personInfoID = Guid.NewGuid();

                contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                contactPerson.Save(Connection, Transaction);

                personInfo.CMN_PER_PersonInfoID = personInfoID;
                personInfo.FirstName            = Parameter.ContactPersonFirstName;
                personInfo.LastName             = Parameter.ContactPersonLastName;
                personInfo.PrimaryEmail         = Parameter.ContactPersonEmail;
                personInfo.Creation_Timestamp   = DateTime.Now;
                personInfo.Tenant_RefID         = securityTicket.TenantID;

                personInfo.Save(Connection, Transaction);

                //Communication Contact
                ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContacts.PersonInfo_RefID   = personInfoID;
                communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                communicationContacts.Content            = Parameter.ContactPersonPhoneNumber;
                communicationContacts.Creation_Timestamp = DateTime.Now;
                communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                communicationContacts.Save(Connection, Transaction);


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                Guid companyInfoID = Guid.NewGuid();
                companyInfo.CMN_COM_CompanyInfoID           = companyInfoID;
                companyInfo.Creation_Timestamp              = DateTime.Now;
                companyInfo.Tenant_RefID                    = securityTicket.TenantID;
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.BSNR;

                item.Ext_CompanyInfo_RefID = companyInfoID;


                ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant();
                extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                extCompany.Creation_Timestamp            = DateTime.Now;
                extCompany.Tenant_RefID    = securityTicket.TenantID;
                extCompany.DisplayName     = Parameter.PracticeName;
                extCompany.IsCompany       = true;
                extCompany.IsNaturalPerson = false;
                extCompany.IsTenant        = false;
                extCompany.IsDeleted       = false;
                extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfoID;

                extCompany.Save(Connection, Transaction);

                ORM_CMN_UniversalContactDetail companyDetails = new ORM_CMN_UniversalContactDetail();
                Guid companyDetailsID = Guid.NewGuid();

                companyInfo.Contact_UCD_RefID = companyDetailsID;
                companyInfo.Save(Connection, Transaction);

                companyDetails.CMN_UniversalContactDetailID = companyDetailsID;
                companyDetails.Tenant_RefID       = securityTicket.TenantID;
                companyDetails.Creation_Timestamp = DateTime.Now;
                companyDetails.IsCompany          = true;
                companyDetails.ZIP               = Parameter.ZIP;
                companyDetails.Town              = Parameter.Town;
                companyDetails.Street_Name       = Parameter.PracticeStreet;
                companyDetails.Street_Number     = Parameter.PracticeNumber;
                companyDetails.Contact_Email     = Parameter.PracitceEmail;
                companyDetails.Street_Name_Line2 = Parameter.PracticeStreet2;
                companyDetails.IsDeleted         = false;
                companyDetails.Save(Connection, Transaction);

                item.Save(Connection, Transaction);


                #endregion
            }

            returnValue.Result = item.HEC_MedicalPractiseID;

            return(returnValue);

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

            #region EMAIL
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");

            string        urlMM        = System.Configuration.ConfigurationManager.AppSettings["mmdocconnect.dashboard.url"];
            List <String> mailToL      = new List <String>();
            var           accountMails = cls_Get_All_Account_LoginEmails_Who_Receive_Notifications.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            foreach (var mail in accountMails)
            {
                mailToL.Add(mail.LoginEmail);
            }

            string appName  = WebConfigurationManager.AppSettings["mmAppUrl"];
            var    prefix   = HttpContext.Current.Request.Url.AbsoluteUri.Contains("https") ? "https://" : "http://";
            var    imageUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("api")) + "Content/images/logo.png";

            var     email_template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/NewTemporaryDoctorEmailTemplate.html"));
            var     subjectsJson   = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailSubjects.json"));
            dynamic subjects       = Newtonsoft.Json.JsonConvert.DeserializeObject(subjectsJson);
            var     subjectMail    = subjects["NewTemporaryDoctorSubject"].ToString();

            email_template = EmailTemplater.SetTemplateData(email_template, new
            {
                name                    = Parameter.name,
                street                  = String.IsNullOrEmpty(Parameter.street) ? "-" : Parameter.street,
                house_number            = String.IsNullOrEmpty(Parameter.house_number) ? "-" : Parameter.house_number,
                zip                     = String.IsNullOrEmpty(Parameter.zip) ? "-" : Parameter.zip,
                city                    = String.IsNullOrEmpty(Parameter.city) ? "-" : Parameter.city,
                phone                   = String.IsNullOrEmpty(Parameter.phone) ? "-" : Parameter.phone,
                fax                     = String.IsNullOrEmpty(Parameter.fax) ? "-" : Parameter.fax,
                email                   = String.IsNullOrEmpty(Parameter.email) ? "-" : Parameter.email,
                comment                 = String.IsNullOrEmpty(Parameter.comment) ? "-" : Parameter.comment,
                doc_app_url             = prefix + HttpContext.Current.Request.Url.Authority + "/" + appName,
                medios_connect_logo_url = imageUrl
            }, "{{", "}}");

            try
            {
                // string mailFrom = cls_Get_Company_Settings.Invoke(Connection, Transaction, securityTicket).Result.Email;
                string mailFrom      = WebConfigurationManager.AppSettings["mailFrom"];
                var    mailsDistinct = mailToL.Distinct().ToList();
                foreach (var mailTo in mailsDistinct)
                {
                    EmailNotificationSenderUtil.SendEmail(mailFrom, mailTo, subjectMail, email_template);
                }
            }
            catch (Exception ex)
            {
                LogUtils.Logger.LogDocAppInfo(new LogUtils.LogEntry(System.Reflection.MethodInfo.GetCurrentMethod(), ex, null, "Temporary doctor creation: Email sending failed."), "EmailExceptions");
            }
            #endregion

            #region PERSON INFO
            ORM_CMN_PER_PersonInfo temporary_doctor_person_info = new ORM_CMN_PER_PersonInfo();
            temporary_doctor_person_info.LastName = Parameter.name;
            temporary_doctor_person_info.Modification_Timestamp = DateTime.Now;
            temporary_doctor_person_info.Tenant_RefID           = securityTicket.TenantID;

            temporary_doctor_person_info.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact_Type temporary_doctor_communication_contact_type_email = new ORM_CMN_PER_CommunicationContact_Type();
            temporary_doctor_communication_contact_type_email.Tenant_RefID = securityTicket.TenantID;
            temporary_doctor_communication_contact_type_email.Type         = "Email";

            temporary_doctor_communication_contact_type_email.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact temporary_doctor_communication_contact_email = new ORM_CMN_PER_CommunicationContact();
            temporary_doctor_communication_contact_email.Tenant_RefID           = securityTicket.TenantID;
            temporary_doctor_communication_contact_email.Modification_Timestamp = DateTime.Now;
            temporary_doctor_communication_contact_email.PersonInfo_RefID       = temporary_doctor_person_info.CMN_PER_PersonInfoID;
            temporary_doctor_communication_contact_email.Content      = Parameter.email;
            temporary_doctor_communication_contact_email.Contact_Type = temporary_doctor_communication_contact_type_email.CMN_PER_CommunicationContact_TypeID;

            temporary_doctor_communication_contact_email.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact_Type temporary_doctor_communication_contact_type_phone = new ORM_CMN_PER_CommunicationContact_Type();
            temporary_doctor_communication_contact_type_phone.Tenant_RefID = securityTicket.TenantID;
            temporary_doctor_communication_contact_type_phone.Type         = "Phone";

            temporary_doctor_communication_contact_type_phone.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact temporary_doctor_communication_contact_phone = new ORM_CMN_PER_CommunicationContact();
            temporary_doctor_communication_contact_phone.Tenant_RefID           = securityTicket.TenantID;
            temporary_doctor_communication_contact_phone.Modification_Timestamp = DateTime.Now;
            temporary_doctor_communication_contact_phone.PersonInfo_RefID       = temporary_doctor_person_info.CMN_PER_PersonInfoID;
            temporary_doctor_communication_contact_phone.Content      = Parameter.phone;
            temporary_doctor_communication_contact_phone.Contact_Type = temporary_doctor_communication_contact_type_phone.CMN_PER_CommunicationContact_TypeID;

            temporary_doctor_communication_contact_phone.Save(Connection, Transaction);
            #endregion

            #region BPT
            ORM_CMN_BPT_BusinessParticipant temporary_doctor_bpt = new ORM_CMN_BPT_BusinessParticipant();
            temporary_doctor_bpt.IfNaturalPerson_CMN_PER_PersonInfo_RefID = temporary_doctor_person_info.CMN_PER_PersonInfoID;
            temporary_doctor_bpt.IsNaturalPerson        = true;
            temporary_doctor_bpt.Modification_Timestamp = DateTime.Now;
            temporary_doctor_bpt.Tenant_RefID           = securityTicket.TenantID;

            temporary_doctor_bpt.Save(Connection, Transaction);
            #endregion

            #region DOCTOR
            ORM_HEC_Doctor temporary_doctor = new ORM_HEC_Doctor();
            // account ref. id = guid empty means that this is a temporary doctor with no account
            temporary_doctor.Account_RefID                     = Guid.Empty;
            temporary_doctor.BusinessParticipant_RefID         = temporary_doctor_bpt.CMN_BPT_BusinessParticipantID;
            temporary_doctor.DoctorIDNumber                    = "";
            temporary_doctor.IsDoctorForFollowupTreatmentsOnly = true;
            temporary_doctor.Tenant_RefID = securityTicket.TenantID;

            temporary_doctor.Save(Connection, Transaction);

            ORM_HEC_Doctor_UniversalProperty temporary_doctor_universal_property = new ORM_HEC_Doctor_UniversalProperty();
            temporary_doctor_universal_property.GlobalPropertyMatchingID = "mm.docconnect.temporary.aftercare.doctor.comment";
            temporary_doctor_universal_property.IsValue_String           = true;
            temporary_doctor_universal_property.Modification_Timestamp   = DateTime.Now;
            temporary_doctor_universal_property.PropertyName             = "Comment";
            temporary_doctor_universal_property.Tenant_RefID             = securityTicket.TenantID;

            temporary_doctor_universal_property.Save(Connection, Transaction);

            ORM_HEC_Doctor_UniversalPropertyValue temporary_doctor_universal_property_value = new ORM_HEC_Doctor_UniversalPropertyValue();
            temporary_doctor_universal_property_value.HEC_Doctor_RefID        = temporary_doctor.HEC_DoctorID;
            temporary_doctor_universal_property_value.Modification_Timestamp  = DateTime.Now;
            temporary_doctor_universal_property_value.Value_String            = Parameter.comment;
            temporary_doctor_universal_property_value.UniversalProperty_RefID = temporary_doctor_universal_property.HEC_Doctor_UniversalPropertyID;
            temporary_doctor_universal_property_value.Tenant_RefID            = securityTicket.TenantID;

            temporary_doctor_universal_property_value.Save(Connection, Transaction);
            #endregion

            #region IMPORT TO ELASTIC

            Practice_Doctors_Model temporary_doctor_elastic_model = new Practice_Doctors_Model();
            temporary_doctor_elastic_model.autocomplete_name = Parameter.name;
            temporary_doctor_elastic_model.name                   = Parameter.name;
            temporary_doctor_elastic_model.name_untouched         = Parameter.name;
            temporary_doctor_elastic_model.address                = Parameter.street + " " + Parameter.house_number;
            temporary_doctor_elastic_model.zip                    = Parameter.zip;
            temporary_doctor_elastic_model.city                   = Parameter.city;
            temporary_doctor_elastic_model.email                  = Parameter.email;
            temporary_doctor_elastic_model.phone                  = Parameter.phone;
            temporary_doctor_elastic_model.account_status         = "temp";
            temporary_doctor_elastic_model.id                     = temporary_doctor.HEC_DoctorID.ToString();
            temporary_doctor_elastic_model.practice_for_doctor_id = Parameter.practice_id.ToString();
            temporary_doctor_elastic_model.tenantid               = securityTicket.TenantID.ToString();
            temporary_doctor_elastic_model.type                   = "Doctor";

            Add_New_Practice.Import_Practice_Data_to_ElasticDB(new List <Practice_Doctors_Model>()
            {
                temporary_doctor_elastic_model
            }, securityTicket.TenantID.ToString());
            #endregion

            returnValue.Result = temporary_doctor.HEC_DoctorID;
            return(returnValue);

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

            ORM_HEC_Pharmacy item = new ORM_HEC_Pharmacy();


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

                #region Delete

                if (Parameter.IsDeleted)
                {
                    //Contact person data finding and deleting
                    var query_BusinessParticipant_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BusinessParticipant_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID;
                    query_BusinessParticipant_ContactPerson_del.Tenant_RefID = item.Tenant_RefID;

                    ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson_del).First();
                    found_BusinessParticipant_ContactPerson_del.IsDeleted = true;

                    var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo_del.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    ORM_CMN_PER_PersonInfo found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First();
                    found_PersonInfo_del.IsDeleted = true;

                    var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID;

                    ORM_CMN_PER_CommunicationContact found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First();
                    found_CommunicationContact_del.IsDeleted = true;

                    found_BusinessParticipant_ContactPerson_del.Save(Connection, Transaction);
                    found_CommunicationContact_del.Save(Connection, Transaction);
                    found_PersonInfo_del.Save(Connection, Transaction);


                    //Company (pharmacy) finding and deleting

                    var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query();
                    query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                    ORM_CMN_COM_CompanyInfo found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First();
                    found_CompanyInfo_del.IsDeleted = true;

                    var query_CompanyContactDetails_del = new ORM_CMN_UniversalContactDetail.Query();
                    query_CompanyContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID;

                    ORM_CMN_UniversalContactDetail found_CompanyContactDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails_del).First();
                    found_CompanyContactDetails_del.IsDeleted = true;

                    var query_BusinessParticipant_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BusinessParticipant_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID;

                    ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company_del).First();
                    found_BusinessParticipant_Company_del.IsDeleted = true;

                    found_CompanyInfo_del.Save(Connection, Transaction);
                    found_CompanyContactDetails_del.Save(Connection, Transaction);
                    found_BusinessParticipant_Company_del.Save(Connection, Transaction);

                    item.IsDeleted = true;
                    return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_PharmacyID));
                }

                #endregion

                #region Edit

                //Contact person data finding and edit

                var query_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant.Query();
                query_BusinessParticipant_ContactPerson.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID;
                query_BusinessParticipant_ContactPerson.Tenant_RefID = item.Tenant_RefID;

                ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant();
                if (item.ContactPerson_BusinessParticipant_RefID != null && item.ContactPerson_BusinessParticipant_RefID != Guid.Empty)
                {
                    found_BusinessParticipant_ContactPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson).First();
                }
                else
                {
                    found_BusinessParticipant_ContactPerson = null;
                }
                if (found_BusinessParticipant_ContactPerson != null)
                {
                    var query_PersonInfo = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    ORM_CMN_PER_PersonInfo found_PersonInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo).First();
                    found_PersonInfo.FirstName    = Parameter.ContactFirstName;
                    found_PersonInfo.LastName     = Parameter.ContactLastName;
                    found_PersonInfo.PrimaryEmail = Parameter.ContactEmail;

                    var query_CommunicationContact = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact.PersonInfo_RefID = found_PersonInfo.CMN_PER_PersonInfoID;

                    ORM_CMN_PER_CommunicationContact found_CommunicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact).First();
                    found_CommunicationContact.Content = Parameter.ContactPhoneNumber;

                    found_CommunicationContact.Save(Connection, Transaction);
                    found_PersonInfo.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                    Guid businessParticipantID = Guid.NewGuid();

                    contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID;
                    contactPerson.IsCompany          = false;
                    contactPerson.IsNaturalPerson    = true;
                    contactPerson.IsTenant           = false;
                    contactPerson.Creation_Timestamp = DateTime.Now;
                    contactPerson.Tenant_RefID       = securityTicket.TenantID;

                    item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;

                    //person info
                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                    Guid personInfoID = Guid.NewGuid();

                    contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                    contactPerson.Save(Connection, Transaction);

                    personInfo.CMN_PER_PersonInfoID = personInfoID;
                    personInfo.FirstName            = Parameter.ContactFirstName;
                    personInfo.LastName             = Parameter.ContactLastName;
                    personInfo.PrimaryEmail         = Parameter.ContactEmail;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Tenant_RefID         = securityTicket.TenantID;

                    personInfo.Save(Connection, Transaction);

                    //Communication Contact
                    ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                    communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                    communicationContacts.PersonInfo_RefID   = personInfoID;
                    communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                    communicationContacts.Content            = Parameter.ContactPhoneNumber;
                    communicationContacts.Creation_Timestamp = DateTime.Now;
                    communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                    communicationContacts.Save(Connection, Transaction);


                    item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;
                    item.Save(Connection, Transaction);
                }

                //Company (pharmacy) finding and edit

                var query_CompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                query_CompanyInfo.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                ORM_CMN_COM_CompanyInfo found_CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo).First();

                var query_CompanyContactDetails = new ORM_CMN_UniversalContactDetail.Query();
                query_CompanyContactDetails.CMN_UniversalContactDetailID = found_CompanyInfo.Contact_UCD_RefID;

                ORM_CMN_UniversalContactDetail found_CompanyContactDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails).FirstOrDefault();
                if (found_CompanyContactDetails != null)
                {
                    found_CompanyContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                    found_CompanyContactDetails.Contact_Email     = Parameter.MainEmail;
                    found_CompanyContactDetails.Street_Name       = Parameter.Street;
                    found_CompanyContactDetails.Street_Number     = Parameter.Number;
                    found_CompanyContactDetails.Street_Name_Line2 = Parameter.Street2;
                    found_CompanyContactDetails.Town = Parameter.Town;
                    found_CompanyContactDetails.ZIP  = Parameter.ZIP;
                    found_CompanyContactDetails.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
                    universalContactDetails.CMN_UniversalContactDetailID = Guid.NewGuid();
                    universalContactDetails.IsCompany         = true;
                    universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                    universalContactDetails.Street_Name       = Parameter.Street;
                    universalContactDetails.Street_Name_Line2 = Parameter.Street2;
                    universalContactDetails.Street_Number     = Parameter.Number;
                    universalContactDetails.Contact_Email     = Parameter.MainEmail;
                    universalContactDetails.ZIP          = Parameter.ZIP;
                    universalContactDetails.Town         = Parameter.Town;
                    universalContactDetails.Tenant_RefID = securityTicket.TenantID;


                    universalContactDetails.Save(Connection, Transaction);

                    found_CompanyInfo.Contact_UCD_RefID = universalContactDetails.CMN_UniversalContactDetailID;
                    found_CompanyInfo.Save(Connection, Transaction);
                }

                var query_BusinessParticipant_Company = new ORM_CMN_BPT_BusinessParticipant.Query();
                query_BusinessParticipant_Company.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo.CMN_COM_CompanyInfoID;

                ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company).First();
                found_BusinessParticipant_Company.DisplayName = Parameter.PharmacyName;


                found_BusinessParticipant_Company.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                #region Save

                item.HEC_PharmacyID = Guid.NewGuid();

                item.Creation_Timestamp = DateTime.Now;
                item.Tenant_RefID       = securityTicket.TenantID;

                //business Participants
                ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                Guid businessParticipantID = Guid.NewGuid();

                contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID;
                contactPerson.IsCompany          = false;
                contactPerson.IsNaturalPerson    = true;
                contactPerson.IsTenant           = false;
                contactPerson.Creation_Timestamp = DateTime.Now;
                contactPerson.Tenant_RefID       = securityTicket.TenantID;

                item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;

                //person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                Guid personInfoID = Guid.NewGuid();

                contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                contactPerson.Save(Connection, Transaction);

                personInfo.CMN_PER_PersonInfoID = personInfoID;
                personInfo.FirstName            = Parameter.ContactFirstName;
                personInfo.LastName             = Parameter.ContactLastName;
                personInfo.PrimaryEmail         = Parameter.ContactEmail;
                personInfo.Creation_Timestamp   = DateTime.Now;
                personInfo.Tenant_RefID         = securityTicket.TenantID;

                personInfo.Save(Connection, Transaction);

                //Communication Contact
                ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContacts.PersonInfo_RefID   = personInfoID;
                communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                communicationContacts.Content            = Parameter.ContactPhoneNumber;
                communicationContacts.Creation_Timestamp = DateTime.Now;
                communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                communicationContacts.Save(Connection, Transaction);

                //ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                //Guid companyInfoID = Guid.NewGuid();

                ORM_CMN_COM_CompanyInfo extCompanyInfo = new ORM_CMN_COM_CompanyInfo();
                Guid extCompanyInfoID = Guid.NewGuid();
                extCompanyInfo.CMN_COM_CompanyInfoID = extCompanyInfoID;
                Guid contactUCDID = Guid.NewGuid();
                extCompanyInfo.Contact_UCD_RefID  = contactUCDID;
                extCompanyInfo.Creation_Timestamp = DateTime.Now;
                extCompanyInfo.Tenant_RefID       = securityTicket.TenantID;

                item.Ext_CompanyInfo_RefID = extCompanyInfoID;

                ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
                universalContactDetails.CMN_UniversalContactDetailID = contactUCDID;
                universalContactDetails.IsCompany         = true;
                universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                universalContactDetails.Street_Name       = Parameter.Street;
                universalContactDetails.Street_Name_Line2 = Parameter.Street2;
                universalContactDetails.Street_Number     = Parameter.Number;
                universalContactDetails.Contact_Email     = Parameter.MainEmail;
                universalContactDetails.ZIP          = Parameter.ZIP;
                universalContactDetails.Town         = Parameter.Town;
                universalContactDetails.Tenant_RefID = securityTicket.TenantID;

                ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant();
                extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                extCompany.Creation_Timestamp            = DateTime.Now;
                extCompany.Tenant_RefID    = securityTicket.TenantID;
                extCompany.DisplayName     = Parameter.PharmacyName;
                extCompany.IsCompany       = true;
                extCompany.IsNaturalPerson = false;
                extCompany.IsTenant        = false;
                extCompany.IsDeleted       = false;
                extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = extCompanyInfoID;

                extCompany.Save(Connection, Transaction);
                extCompanyInfo.Save(Connection, Transaction);
                universalContactDetails.Save(Connection, Transaction);
                item.Save(Connection, Transaction);

                returnValue.Result = item.HEC_PharmacyID;
                #endregion
            }

            return(returnValue);

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

            ORM_HEC_Patient patient = new ORM_HEC_Patient();
            if (Parameter.HEC_PatientID != Guid.Empty)
            {
                var result = patient.Load(Connection, Transaction, Parameter.HEC_PatientID);
                if (result.Status != FR_Status.Success || patient.HEC_PatientID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            patient.IsPatientParticipationPolicyValidated = Parameter.HasFulfilledParticipationPolicyRequirements;
            patient.PatientComment = Parameter.Comment;
            patient.Tenant_RefID   = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (patient.CMN_BPT_BusinessParticipant_RefID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, patient.CMN_BPT_BusinessParticipant_RefID);
                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.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;


            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            person.FirstName          = Parameter.FirstName;
            person.LastName           = Parameter.LastName;
            person.PrimaryEmail       = Parameter.Mail;
            person.Tenant_RefID       = securityTicket.TenantID;
            person.Salutation_General = Parameter.Salutation;
            person.Save(Connection, Transaction);

            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.Save(Connection, Transaction);

            patient.CMN_BPT_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            patient.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact.Query contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.IsDeleted        = false;
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            var contactQueryRes = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, contactQuery);
            ORM_CMN_PER_CommunicationContact contactPhone = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Phone);
            ORM_CMN_PER_CommunicationContact contactFax   = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Fax);

            if (contactPhone == null)
            {
                contactPhone = new ORM_CMN_PER_CommunicationContact();
                contactPhone.Contact_Type     = STLD_ContactTypes.Phone;
                contactPhone.Tenant_RefID     = securityTicket.TenantID;
                contactPhone.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            }
            contactPhone.Content = Parameter.Phone;
            contactPhone.Save(Connection, Transaction);

            if (contactFax == null)
            {
                contactFax                  = new ORM_CMN_PER_CommunicationContact();
                contactFax.Content          = Parameter.Fax;
                contactFax.Contact_Type     = STLD_ContactTypes.Fax;
                contactFax.Tenant_RefID     = securityTicket.TenantID;
                contactFax.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contactFax.Save(Connection, Transaction);
            }
            contactFax.Content = Parameter.Fax;
            contactFax.Save(Connection, Transaction);

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

            ORM_HEC_Patient_HealthInsurance Patient_HealthInsurance;
            var Patient_HealthInsuranceQueryRes = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, Patient_HealthInsuranceQuery);
            if (Patient_HealthInsuranceQueryRes.Count == 1)
            {
                Patient_HealthInsurance = Patient_HealthInsuranceQueryRes[0];
            }
            else
            {
                Patient_HealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                Patient_HealthInsurance.Patient_RefID = patient.HEC_PatientID;
                Patient_HealthInsurance.Tenant_RefID  = securityTicket.TenantID;
                Patient_HealthInsurance.IsPrimary     = true;
            }
            Patient_HealthInsurance.HealthInsurance_Number = Parameter.HealthcareNumber;
            Patient_HealthInsurance.Save(Connection, Transaction);

            ORM_HEC_STU_Study_ParticipatingPatient.Query Study_ParticipatingPatientsQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query();
            Study_ParticipatingPatientsQuery.Tenant_RefID  = securityTicket.TenantID;
            Study_ParticipatingPatientsQuery.IsDeleted     = false;
            Study_ParticipatingPatientsQuery.Patient_RefID = patient.HEC_PatientID;

            ORM_HEC_STU_Study_ParticipatingPatient Study_ParticipatingPatients;

            var Study_ParticipatingPatientsQueryRes = ORM_HEC_STU_Study_ParticipatingPatient.Query.Search(Connection, Transaction, Study_ParticipatingPatientsQuery);
            if (Study_ParticipatingPatientsQueryRes.Count == 1)
            {
                Study_ParticipatingPatients = Study_ParticipatingPatientsQueryRes[0];
            }
            else
            {
                Study_ParticipatingPatients = new ORM_HEC_STU_Study_ParticipatingPatient();
                Study_ParticipatingPatients.Patient_RefID = patient.HEC_PatientID;
                Study_ParticipatingPatients.Tenant_RefID  = securityTicket.TenantID;
            }
            Study_ParticipatingPatients.HasFulfilledParticipationPolicyRequirements = Parameter.HasFulfilledParticipationPolicyRequirements;
            Study_ParticipatingPatients.Save(Connection, Transaction);

            returnValue.Result = patient.HEC_PatientID;
            return(returnValue);

            #endregion UserCode
        }
예제 #13
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SMSP_1548 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var             returnValue = new FR_Guid();
            ORM_HEC_Patient patient     = new ORM_HEC_Patient();
            if (Parameter.HEC_PatientID != Guid.Empty)
            {
                var result = patient.Load(Connection, Transaction, Parameter.HEC_PatientID);
                if (result.Status != FR_Status.Success || patient.HEC_PatientID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            patient.IsPatientParticipationPolicyValidated = Parameter.HasFulfilledParticipationPolicyRequirements;
            patient.PatientComment = Parameter.Comment;
            patient.Tenant_RefID   = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (patient.CMN_BPT_BusinessParticipant_RefID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, patient.CMN_BPT_BusinessParticipant_RefID);
                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.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;


            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            person.FirstName          = Parameter.FirstName;
            person.LastName           = Parameter.LastName;
            person.PrimaryEmail       = Parameter.Mail;
            person.Tenant_RefID       = securityTicket.TenantID;
            person.Salutation_General = Parameter.Salutation;
            person.Save(Connection, Transaction);

            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.Save(Connection, Transaction);

            patient.CMN_BPT_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            patient.Save(Connection, Transaction);

            ORM_CMN_PER_CommunicationContact.Query contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.IsDeleted        = false;
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            var contactQueryRes = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, contactQuery);
            ORM_CMN_PER_CommunicationContact contactPhone = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Phone);
            ORM_CMN_PER_CommunicationContact contactFax   = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Fax);

            if (contactPhone == null)
            {
                contactPhone = new ORM_CMN_PER_CommunicationContact();
                contactPhone.Contact_Type     = STLD_ContactTypes.Phone;
                contactPhone.Tenant_RefID     = securityTicket.TenantID;
                contactPhone.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            }
            contactPhone.Content = Parameter.Phone;
            contactPhone.Save(Connection, Transaction);

            if (contactFax == null)
            {
                contactFax                  = new ORM_CMN_PER_CommunicationContact();
                contactFax.Content          = Parameter.Fax;
                contactFax.Contact_Type     = STLD_ContactTypes.Fax;
                contactFax.Tenant_RefID     = securityTicket.TenantID;
                contactFax.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contactFax.Save(Connection, Transaction);
            }
            contactFax.Content = Parameter.Fax;
            contactFax.Save(Connection, Transaction);

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

            ORM_HEC_Patient_HealthInsurance Patient_HealthInsurance;
            var Patient_HealthInsuranceQueryRes = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, Patient_HealthInsuranceQuery);
            if (Patient_HealthInsuranceQueryRes.Count == 1)
            {
                Patient_HealthInsurance = Patient_HealthInsuranceQueryRes[0];
            }
            else
            {
                Patient_HealthInsurance = new ORM_HEC_Patient_HealthInsurance();
                Patient_HealthInsurance.Patient_RefID = patient.HEC_PatientID;
                Patient_HealthInsurance.Tenant_RefID  = securityTicket.TenantID;
                Patient_HealthInsurance.IsPrimary     = true;
            }
            Patient_HealthInsurance.HealthInsurance_Number = Parameter.HealthcareNumber;
            Patient_HealthInsurance.Save(Connection, Transaction);

            ORM_HEC_STU_Study_ParticipatingPatient.Query Study_ParticipatingPatientsQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query();
            Study_ParticipatingPatientsQuery.Tenant_RefID  = securityTicket.TenantID;
            Study_ParticipatingPatientsQuery.IsDeleted     = false;
            Study_ParticipatingPatientsQuery.Patient_RefID = patient.HEC_PatientID;

            ORM_HEC_STU_Study_ParticipatingPatient Study_ParticipatingPatients;

            var Study_ParticipatingPatientsQueryRes = ORM_HEC_STU_Study_ParticipatingPatient.Query.Search(Connection, Transaction, Study_ParticipatingPatientsQuery);
            if (Study_ParticipatingPatientsQueryRes.Count == 1)
            {
                Study_ParticipatingPatients = Study_ParticipatingPatientsQueryRes[0];
            }
            else
            {
                Study_ParticipatingPatients = new ORM_HEC_STU_Study_ParticipatingPatient();
                Study_ParticipatingPatients.Patient_RefID = patient.HEC_PatientID;
                Study_ParticipatingPatients.Tenant_RefID  = securityTicket.TenantID;
            }
            Study_ParticipatingPatients.HasFulfilledParticipationPolicyRequirements = Parameter.HasFulfilledParticipationPolicyRequirements;
            Study_ParticipatingPatients.Save(Connection, Transaction);


            ORM_USR_Account       account;
            ORM_USR_Account.Query ORM_USR_AccountQuery = new ORM_USR_Account.Query();
            ORM_USR_AccountQuery.IsDeleted    = false;
            ORM_USR_AccountQuery.Tenant_RefID = securityTicket.TenantID;
            ORM_USR_AccountQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            var accountRes = ORM_USR_Account.Query.Search(Connection, Transaction, ORM_USR_AccountQuery);
            if (accountRes.Count == 1)
            {
                account = accountRes[0];
            }
            else
            {
                account = new ORM_USR_Account();
                account.Tenant_RefID = securityTicket.TenantID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.AccountType = 3;
                account.Save(Connection, Transaction);
            }

            ORM_USR_Device_AccountCode.Query ORM_USR_Device_AccountCodeQuery = new ORM_USR_Device_AccountCode.Query();
            ORM_USR_Device_AccountCodeQuery.IsDeleted     = false;
            ORM_USR_Device_AccountCodeQuery.Tenant_RefID  = securityTicket.TenantID;
            ORM_USR_Device_AccountCodeQuery.Account_RefID = account.USR_AccountID;
            var accountCodeRes = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, ORM_USR_Device_AccountCodeQuery);
            if (accountCodeRes.Count == 0)
            {
                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode_StatusHistory AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                AccountCode_StatusHistory.Tenant_RefID         = securityTicket.TenantID;
                AccountCode_StatusHistory.IsAccountCode_Active = true;
                AccountCode_StatusHistory.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode devoceAccpimtCpde = new ORM_USR_Device_AccountCode();
                devoceAccpimtCpde.Account_RefID                   = account.USR_AccountID;
                devoceAccpimtCpde.Tenant_RefID                    = securityTicket.TenantID;
                devoceAccpimtCpde.AccountCode_Value               = checkCodeValue.CodeValue;
                devoceAccpimtCpde.IsAccountCode_Expirable         = false;
                devoceAccpimtCpde.AccountCode_CurrentStatus_RefID = AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID;
                devoceAccpimtCpde.Save(Connection, Transaction);

                AccountCode_StatusHistory.Device_AccountCode_RefID = devoceAccpimtCpde.USR_Device_AccountCodeID;
                AccountCode_StatusHistory.Save(Connection, Transaction);
            }

            returnValue.Result = patient.HEC_PatientID;
            return(returnValue);

            #endregion UserCode
        }
예제 #14
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_DO_SD_1517 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
            Guid   BusinessParticipantID         = Guid.NewGuid();
            Guid   personInfoID                  = Guid.NewGuid();
            Guid   PracticeCustomerID            = Guid.NewGuid();
            Guid   PracticeBusinessParticipantID = Guid.NewGuid();
            Guid   PracticeCompanyInfoID         = Guid.NewGuid();
            String PracticeName                  = "";
            Guid   BankAccountID                 = Guid.Empty;
            Guid   doctor_id    = Parameter.DoctorID;
            var    isOpPractice = false;

            //if (!String.IsNullOrEmpty(Parameter.Login_Email))
            //uncomment this if you've created account
            if (false)
            {
                string[] stringUser  = Parameter.Login_Email.Split('@');
                string   usernameStr = stringUser[0];

                try
                {
                    var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        AccountSignInEmailAddress = Parameter.Login_Email,
                    }).Single();

                    var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query();
                    accountGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                    accountGroupQuery.IsDeleted                = false;
                    accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";

                    var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault();

                    if (accountGroup == null)
                    {
                        accountGroup = new ORM_USR_Account_FunctionLevelRights_Group();
                        accountGroup.Tenant_RefID             = securityTicket.TenantID;
                        accountGroup.Label                    = "mm.docconect.doc.app.group";
                        accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";
                        accountGroup.Creation_Timestamp       = DateTime.Now;
                        accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid();
                        accountGroup.Save(Connection, Transaction);
                    }

                    var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).ToList();

                    List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>();
                    foreach (var item in PracticeAccount2UniversalProperty)
                    {
                        var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID
                        }).Single();
                        PracticeUniversalPropertyList.Add(PracticeUniversalProperty);
                    }
                    ;

                    P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522();
                    practiceAccountIDParameter.PracticeID = Parameter.PracticeID;

                    var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query();
                    practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID;
                    practiceAccountToFunctionLevelRightQ.Tenant_RefID  = securityTicket.TenantID;
                    practiceAccountToFunctionLevelRightQ.IsDeleted     = false;

                    var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault();

                    if (practiceAccountToFunctionLevelRight != null)
                    {
                        var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID;
                        practiceAccountFunctionLevelRightQ.IsDeleted    = false;
                        practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID;

                        var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault();

                        if (practiceAccountFunctionLevelRight != null)
                        {
                            isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice");
                        }
                    }

                    var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                    functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                    functionLevelRightQ.IsDeleted                = false;
                    functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

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

                    var tempFunctionLevelRightID = Guid.Empty;

                    if (existingFunctionLevelRight == null)
                    {
                        ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight();
                        functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid();
                        functionLevelRight.FunctionLevelRights_Group_RefID  = accountGroup.USR_Account_FunctionLevelRights_GroupID;
                        functionLevelRight.Tenant_RefID       = securityTicket.TenantID;
                        functionLevelRight.Creation_Timestamp = DateTime.Now;

                        functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";
                        functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                        functionLevelRight.Save(Connection, Transaction);

                        tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                    }
                    else
                    {
                        tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID;
                    }

                    var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight();
                    accountToFunctionLevelRight.Tenant_RefID             = securityTicket.TenantID;
                    accountToFunctionLevelRight.Creation_Timestamp       = DateTime.Now;
                    accountToFunctionLevelRight.AssignmentID             = Guid.NewGuid();
                    accountToFunctionLevelRight.Account_RefID            = doctorAccountInfo.USR_AccountID;
                    accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID;

                    accountToFunctionLevelRight.Save(Connection, Transaction);

                    var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

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

                    var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();
                    DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                    DoctorBusinessParticipant.DisplayName            = Parameter.First_Name + " " + Parameter.Last_Name;
                    DoctorBusinessParticipant.IsNaturalPerson        = true;
                    DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                    DoctorBusinessParticipant.Save(Connection, Transaction);
                    personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;


                    var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                    companyInfoPractice.IsDeleted            = false;
                    companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                    companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                    companyInfoPractice.FirstName            = Parameter.First_Name;
                    companyInfoPractice.LastName             = Parameter.Last_Name;
                    companyInfoPractice.Salutation_General   = Parameter.Salutation;
                    companyInfoPractice.Title = Parameter.Title;
                    companyInfoPractice.Save(Connection, Transaction);

                    var communicationContact = new ORM_CMN_PER_CommunicationContact();
                    communicationContact.IsDeleted              = false;
                    communicationContact.Contact_Type           = Guid.NewGuid();
                    communicationContact.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact.Modification_Timestamp = DateTime.Now;
                    communicationContact.PersonInfo_RefID       = personInfoID;
                    communicationContact.Content = Parameter.Email;
                    communicationContact.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID = communicationContact.Contact_Type;


                    var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType.IsDeleted    = false;
                    communicationContactType.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                    communicationContactType.Type = "Email";
                    communicationContactType.Save(Connection, Transaction);

                    var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                    communicationContact2.IsDeleted              = false;
                    communicationContact2.Contact_Type           = Guid.NewGuid();
                    communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact2.Modification_Timestamp = DateTime.Now;
                    communicationContact2.PersonInfo_RefID       = personInfoID;
                    communicationContact2.Content = Parameter.Phone;
                    communicationContact2.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                    var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType2.IsDeleted    = false;
                    communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                    communicationContactType2.Type = "Phone";
                    communicationContactType2.Save(Connection, Transaction);

                    var doctor = new ORM_HEC_Doctor();
                    doctor.HEC_DoctorID = Guid.NewGuid();
                    doctor.IsDeleted    = false;
                    doctor.Tenant_RefID = securityTicket.TenantID;
                    doctor.BusinessParticipant_RefID = BusinessParticipantID;
                    doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                    doctor.Save(Connection, Transaction);

                    doctor_id = doctor.HEC_DoctorID;

                    var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).Single();


                    var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                    organizationalunit_Staff.IsDeleted    = false;
                    organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                    organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                    organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                    organizationalunit_Staff.Save(Connection, Transaction);

                    var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                    {
                        IsDeleted              = false,
                        Tenant_RefID           = securityTicket.TenantID,
                        CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                    }).Single();
                    var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                    }).Single();

                    PracticeName = PracticeBusinessParticipant.DisplayName;
                    PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                    PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                    if (Parameter.From_Practice_Bank)
                    {
                        var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                        }).Single();


                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        //end of save bank data if inherited from practice
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                            bankAccountDoctor.IsDeleted             = false;
                            bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                            bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            bankAccountDoctor.OwnerText             = Parameter.Account_Holder;
                            bankAccountDoctor.IBAN               = Parameter.IBAN;
                            bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                            bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                            bankAccountDoctor.Save(Connection, Transaction);

                            if (!String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var bank = new ORM_ACC_BNK_Bank();
                                bank.IsDeleted          = false;
                                bank.Tenant_RefID       = securityTicket.TenantID;
                                bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                bank.BICCode            = Parameter.BIC;
                                bank.BankName           = Parameter.Bank;
                                bank.Creation_Timestamp = DateTime.Now;
                                bank.Save(Connection, Transaction);
                            }

                            BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            // end save bank data
                        }
                    }
                }
                catch
                {
                    throw new Exception();
                }
            }
            else
            {
                var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();

                DoctorBusinessParticipant.IsDeleted    = false;
                DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                DoctorBusinessParticipant.DisplayName            = Parameter.First_Name + " " + Parameter.Last_Name;
                DoctorBusinessParticipant.IsNaturalPerson        = true;
                DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                DoctorBusinessParticipant.Save(Connection, Transaction);
                personInfoID          = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID;

                var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                companyInfoPractice.IsDeleted            = false;
                companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                companyInfoPractice.FirstName            = Parameter.First_Name;
                companyInfoPractice.LastName             = Parameter.Last_Name;
                companyInfoPractice.Salutation_General   = Parameter.Salutation;
                companyInfoPractice.Title = Parameter.Title;
                companyInfoPractice.Save(Connection, Transaction);

                var communicationContact = new ORM_CMN_PER_CommunicationContact();
                communicationContact.IsDeleted              = false;
                communicationContact.Contact_Type           = Guid.NewGuid();
                communicationContact.Tenant_RefID           = securityTicket.TenantID;
                communicationContact.Modification_Timestamp = DateTime.Now;
                communicationContact.PersonInfo_RefID       = personInfoID;
                communicationContact.Content = Parameter.Email;
                communicationContact.Save(Connection, Transaction);
                Guid CommunicationContactTypeID = communicationContact.Contact_Type;

                var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                communicationContactType.IsDeleted    = false;
                communicationContactType.Tenant_RefID = securityTicket.TenantID;
                communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                communicationContactType.Type = "Email";
                communicationContactType.Save(Connection, Transaction);

                var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                communicationContact2.IsDeleted              = false;
                communicationContact2.Contact_Type           = Guid.NewGuid();
                communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                communicationContact2.Modification_Timestamp = DateTime.Now;
                communicationContact2.PersonInfo_RefID       = personInfoID;
                communicationContact2.Content = Parameter.Phone;
                communicationContact2.Save(Connection, Transaction);
                Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                communicationContactType2.IsDeleted    = false;
                communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                communicationContactType2.Type = "Phone";
                communicationContactType2.Save(Connection, Transaction);

                var doctor = new ORM_HEC_Doctor();
                doctor.HEC_DoctorID = Guid.NewGuid();
                doctor.IsDeleted    = false;
                doctor.Tenant_RefID = securityTicket.TenantID;
                doctor.BusinessParticipant_RefID = BusinessParticipantID;
                doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                doctor.Save(Connection, Transaction);

                doctor_id = doctor.HEC_DoctorID;

                var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                }).Single();


                var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                organizationalunit_Staff.IsDeleted    = false;
                organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                organizationalunit_Staff.Save(Connection, Transaction);


                var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                {
                    IsDeleted              = false,
                    Tenant_RefID           = securityTicket.TenantID,
                    CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                }).Single();
                var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                }).Single();
                PracticeName = PracticeBusinessParticipant.DisplayName;
                PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                if (Parameter.From_Practice_Bank == true)
                {
                    var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                    }).Single();


                    var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                    business2bankAccount.IsDeleted    = false;
                    business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                    business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                    business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                    business2bankAccount.Creation_Timestamp = DateTime.Now;
                    business2bankAccount.Save(Connection, Transaction);

                    BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                    //end of save bank data if inherited from practice
                }
                else
                {
                    if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                    {
                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                        bankAccountDoctor.IsDeleted             = false;
                        bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                        bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                        bankAccountDoctor.OwnerText             = Parameter.Account_Holder;
                        bankAccountDoctor.IBAN               = Parameter.IBAN;
                        bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                        bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                        bankAccountDoctor.Save(Connection, Transaction);

                        if (!String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var bank = new ORM_ACC_BNK_Bank();
                            bank.IsDeleted          = false;
                            bank.Tenant_RefID       = securityTicket.TenantID;
                            bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                            bank.BICCode            = Parameter.BIC;
                            bank.BankName           = Parameter.Bank;
                            bank.Creation_Timestamp = DateTime.Now;
                            bank.Save(Connection, Transaction);
                        }

                        BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                        // end save bank data
                    }
                }
            }
            var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query()
            {
                IsDeleted           = false,
                Tenant_RefID        = securityTicket.TenantID,
                CompanyInfo_RefID   = PracticeCompanyInfoID,
                Address_Description = "Standard address for billing, shipping",
            }).SingleOrDefault();

            Practice_Doctors_Model DPModel = new Practice_Doctors_Model();

            if (PracticeCompanyInfoAddress != null)
            {
                var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID,
                }).SingleOrDefault();
                DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number;
                DPModel.zip     = PracticeUCD.ZIP;
                DPModel.city    = PracticeUCD.Town;
            }

            DPModel.account_status = "aktiv";
            DPModel.id             = doctor_id.ToString();

            var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim();

            DPModel.name           = title + " " + Parameter.Last_Name + " " + Parameter.First_Name;
            DPModel.name_untouched = Parameter.Last_Name + " " + Parameter.First_Name;
            DPModel.bsnr_lanr      = Parameter.LANR.ToString();

            DPModel.salutation = title;

            DPModel.type = "Doctor";

            DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;

            DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;


            DPModel.phone = Parameter.Phone;

            DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email;

            DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN;

            DPModel.bic = string.IsNullOrEmpty(Parameter.BIC) ? "" : Parameter.BIC;

            DPModel.bank_id             = BankAccountID.ToString();
            DPModel.bank_info_inherited = Parameter.From_Practice_Bank;
            DPModel.aditional_info      = "";
            DPModel.contract            = 0;


            DPModel.tenantid = securityTicket.TenantID.ToString();
            DPModel.practice_name_for_doctor = PracticeName;
            DPModel.practice_for_doctor_id   = Parameter.PracticeID.ToString();

            DPModel.role = isOpPractice ? "op" : "ac";

            List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>();
            DPModelL.Add(DPModel);

            Add_New_Practice.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString());
            return(returnValue);

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

            if (Parameter.isDeleted == true)
            {
                P_L3MP_DPBID_1026 param = new P_L3MP_DPBID_1026();
                param.HEC_MedicalPractiseID = Parameter.PracticeID;

                cls_Delete_Practice_By_ID.Invoke(Connection, Transaction, param, securityTicket);
            }
            else
            {
                #region Save

                if (Parameter.PracticeID == Guid.Empty)
                {
                    /*********************************
                     *  Save ContactPerson
                     ********************************/
                    //business Participants
                    ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                    Guid businessParticipantsID = Guid.NewGuid();

                    contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantsID;
                    contactPerson.IsCompany          = false;
                    contactPerson.IsNaturalPerson    = true;
                    contactPerson.IsTenant           = false;
                    contactPerson.Creation_Timestamp = DateTime.Now;
                    contactPerson.Tenant_RefID       = securityTicket.TenantID;

                    //person info
                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                    Guid personInfoID = Guid.NewGuid();

                    contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                    contactPerson.Save(Connection, Transaction);

                    personInfo.CMN_PER_PersonInfoID = personInfoID;
                    personInfo.FirstName            = Parameter.ContactPersonFirstName;
                    personInfo.LastName             = Parameter.ContactPersonLastName;
                    personInfo.PrimaryEmail         = Parameter.ContactPersonEmail;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Tenant_RefID         = securityTicket.TenantID;

                    personInfo.Save(Connection, Transaction);

                    //Communication Contact
                    ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                    communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                    communicationContacts.PersonInfo_RefID   = personInfoID;
                    communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                    communicationContacts.Content            = Parameter.ContactPersonPhoneNumber;
                    communicationContacts.Creation_Timestamp = DateTime.Now;
                    communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                    communicationContacts.Save(Connection, Transaction);

                    /*********************************
                     * Save Practice
                     ********************************/
                    P_L3MP_SPBI_1602 param = new P_L3MP_SPBI_1602();
                    param.Street_Number     = Parameter.PracticeNumber;
                    param.Street_Name       = Parameter.PracticeStreet;
                    param.Street_Name_Line2 = Parameter.PracticeStreet2;
                    param.PracticeName      = Parameter.PracticeName;
                    param.isLucentis        = true;
                    param.ifLucentis_BSNR   = Parameter.BSNR;
                    param.PracticeEmail     = Parameter.PracitceEmail;
                    param.Town = Parameter.Town;
                    param.ZIP  = Parameter.ZIP;
                    param.HEC_MedicalPractiseID = Parameter.PracticeID;

                    Guid HEC_MedicalPractiseID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, param, securityTicket).Result;


                    /*********************************
                     * Save Cooperating Practices
                     ********************************/
                    var queryMedicalPractice = new ORM_HEC_MedicalPractis.Query();
                    queryMedicalPractice.HEC_MedicalPractiseID = HEC_MedicalPractiseID;
                    queryMedicalPractice.IsDeleted             = false;

                    var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, queryMedicalPractice).FirstOrDefault();

                    if (medicalPractice != null)
                    {
                        medicalPractice.ContactPerson_RefID = businessParticipantsID;
                        medicalPractice.Save(Connection, Transaction);

                        var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                        queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                        queryCompanyInfo.IsDeleted             = false;

                        var CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).FirstOrDefault();

                        if (CompanyInfo != null)
                        {
                            var queryBussinessParticipients = new ORM_CMN_BPT_BusinessParticipant.Query();
                            queryBussinessParticipients.IfCompany_CMN_COM_CompanyInfo_RefID = CompanyInfo.CMN_COM_CompanyInfoID;
                            queryBussinessParticipients.IsDeleted = false;

                            var bussinessParticipants = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, queryBussinessParticipients).FirstOrDefault();


                            if (bussinessParticipants != null)
                            {
                                foreach (var cooperatingPractice in Parameter.CooperatingPractices)
                                {
                                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBussinessParticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();

                                    associatedBussinessParticipants.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                                    associatedBussinessParticipants.IsDeleted = cooperatingPractice.isDeleted;
                                    associatedBussinessParticipants.BusinessParticipant_RefID           = bussinessParticipants.CMN_BPT_BusinessParticipantID;
                                    associatedBussinessParticipants.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID;
                                    associatedBussinessParticipants.Creation_Timestamp = DateTime.Now;
                                    associatedBussinessParticipants.Tenant_RefID       = bussinessParticipants.Tenant_RefID;

                                    associatedBussinessParticipants.Save(Connection, Transaction);
                                }
                            }
                        }

                        returnValue.Result = medicalPractice.HEC_MedicalPractiseID;
                    }
                }
                #endregion
                else
                {
                    /*********************************
                     * Edit Practice
                     ********************************/
                    P_L3MP_SPBI_1602 param = new P_L3MP_SPBI_1602();
                    param.Street_Number     = Parameter.PracticeNumber;
                    param.Street_Name       = Parameter.PracticeStreet;
                    param.Street_Name_Line2 = Parameter.PracticeStreet2;
                    param.PracticeName      = Parameter.PracticeName;
                    param.isLucentis        = true;
                    param.ifLucentis_BSNR   = Parameter.BSNR;
                    param.PracticeEmail     = Parameter.PracitceEmail;
                    param.Town = Parameter.Town;
                    param.ZIP  = Parameter.ZIP;
                    param.HEC_MedicalPractiseID = Parameter.PracticeID;

                    Guid HEC_MedicalPractiseID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, param, securityTicket).Result;

                    var medicalPracticeQuery = new ORM_HEC_MedicalPractis.Query();
                    medicalPracticeQuery.IsDeleted             = false;
                    medicalPracticeQuery.HEC_MedicalPractiseID = HEC_MedicalPractiseID;

                    var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medicalPracticeQuery).FirstOrDefault();

                    if (medicalPractice != null)
                    {
                        /*********************************
                         *  Edit Contact Person
                         ********************************/

                        //contact person
                        var contactPerson = new ORM_CMN_BPT_BusinessParticipant();

                        var contactPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                        contactPersonQuery.IsDeleted = false;

                        if (medicalPractice.ContactPerson_RefID != Guid.Empty)
                        {
                            contactPersonQuery.CMN_BPT_BusinessParticipantID = medicalPractice.ContactPerson_RefID;
                            contactPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, contactPersonQuery).FirstOrDefault();
                        }
                        else
                        {
                            contactPerson = null;
                        }

                        Guid personInfoID = Guid.NewGuid();

                        if (contactPerson == null)
                        {
                            contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                            contactPerson.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                            contactPerson.IsCompany          = false;
                            contactPerson.IsNaturalPerson    = true;
                            contactPerson.IsTenant           = false;
                            contactPerson.Creation_Timestamp = DateTime.Now;
                            contactPerson.Tenant_RefID       = securityTicket.TenantID;

                            contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                            contactPerson.Save(Connection, Transaction);

                            medicalPractice.ContactPerson_RefID = contactPerson.CMN_BPT_BusinessParticipantID;
                            medicalPractice.Save(Connection, Transaction);
                        }

                        var personInfo = new ORM_CMN_PER_PersonInfo();

                        //person info
                        var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
                        personInfoQuery.IsDeleted            = false;
                        personInfoQuery.CMN_PER_PersonInfoID = contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

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

                        if (personInfo == null)
                        {
                            personInfo = new ORM_CMN_PER_PersonInfo();
                            personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                            personInfo.Creation_Timestamp   = DateTime.Now;
                            personInfo.Tenant_RefID         = securityTicket.TenantID;
                            personInfo.CMN_PER_PersonInfoID = personInfoID;

                            contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                            contactPerson.Save(Connection, Transaction);
                        }

                        personInfo.FirstName    = Parameter.ContactPersonFirstName;
                        personInfo.LastName     = Parameter.ContactPersonLastName;
                        personInfo.PrimaryEmail = Parameter.ContactPersonEmail;

                        personInfo.Save(Connection, Transaction);

                        //Communication Contact

                        var communicationContacts = new ORM_CMN_PER_CommunicationContact();

                        var communicationContactsQuery = new ORM_CMN_PER_CommunicationContact.Query();
                        communicationContactsQuery.IsDeleted        = false;
                        communicationContactsQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                        communicationContacts = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactsQuery).FirstOrDefault();

                        if (communicationContacts == null)
                        {
                            communicationContacts = new ORM_CMN_PER_CommunicationContact();
                            communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                            communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                            communicationContacts.Creation_Timestamp = DateTime.Now;
                            communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                        }
                        communicationContacts.Contact_Type = Parameter.ContactTypePhone;
                        communicationContacts.Content      = Parameter.ContactPersonPhoneNumber;

                        communicationContacts.Save(Connection, Transaction);


                        /*********************************
                         *  Edit Cooperating Practices
                         ********************************/

                        var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                        queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                        queryCompanyInfo.IsDeleted             = false;

                        var CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).FirstOrDefault();

                        if (CompanyInfo != null)
                        {
                            var queryBussinessParticipients = new ORM_CMN_BPT_BusinessParticipant.Query();
                            queryBussinessParticipients.IfCompany_CMN_COM_CompanyInfo_RefID = CompanyInfo.CMN_COM_CompanyInfoID;
                            queryBussinessParticipients.IsDeleted = false;

                            var bussinessParticipants = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, queryBussinessParticipients).FirstOrDefault();


                            if (bussinessParticipants != null)
                            {
                                foreach (var cooperatingPractice in Parameter.CooperatingPractices)
                                {
                                    var associatedBussinessParticipantsQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                                    associatedBussinessParticipantsQuery.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID;
                                    associatedBussinessParticipantsQuery.Tenant_RefID = bussinessParticipants.Tenant_RefID;
                                    associatedBussinessParticipantsQuery.BusinessParticipant_RefID = bussinessParticipants.CMN_BPT_BusinessParticipantID;

                                    var associtePractice = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBussinessParticipantsQuery).FirstOrDefault();

                                    if (associtePractice != null)
                                    {
                                        associtePractice.IsDeleted = cooperatingPractice.isDeleted;
                                        associtePractice.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID;
                                        associtePractice.Save(Connection, Transaction);
                                    }
                                    else
                                    {
                                        ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBussinessParticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();

                                        associatedBussinessParticipants.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                                        associatedBussinessParticipants.IsDeleted = cooperatingPractice.isDeleted;
                                        associatedBussinessParticipants.BusinessParticipant_RefID           = bussinessParticipants.CMN_BPT_BusinessParticipantID;
                                        associatedBussinessParticipants.AssociatedBusinessParticipant_RefID = cooperatingPractice.PracticeID;
                                        associatedBussinessParticipants.Creation_Timestamp = DateTime.Now;
                                        associatedBussinessParticipants.Tenant_RefID       = bussinessParticipants.Tenant_RefID;

                                        associatedBussinessParticipants.Save(Connection, Transaction);
                                    }
                                }
                            }
                        }

                        returnValue.Result = medicalPractice.HEC_MedicalPractiseID;
                    }
                }
            }

            return(returnValue);

            #endregion UserCode
        }
예제 #16
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_GPBD_1613 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            returnValue.Result = new Guid();
            var patient = new ORM_HEC_Patient();
            //var serializer = new JsonNetSerializer();
            //var connection = new ElasticConnection((String)HttpContext.GetGlobalResourceObject("Global", "ElasticConnection"), 9200);

            #region Save

            if (Parameter.ID == null || Parameter.ID == Guid.Empty)
            {
                //ORM_HEC_Patient
                patient.HEC_PatientID      = Guid.NewGuid();
                patient.Tenant_RefID       = securityTicket.TenantID;
                patient.Creation_Timestamp = DateTime.Now;
                patient.CMN_BPT_BusinessParticipant_RefID = Guid.NewGuid();
                patient.Save(Connection, Transaction);

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

                //ORM_CMN_PER_PersonInfo
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryEmail;
                personInfo.Title = Parameter.Title;
                personInfo.ProfileImage_Document_RefID = Parameter.ProfileImage_Document_RefID;
                personInfo.BirthDate                  = Parameter.BirthDate;
                personInfo.Gender                     = Int32.Parse(Parameter.Gender);
                personInfo.Salutation_General         = Parameter.AcademicTitle;
                personInfo.Address_RefID              = Guid.NewGuid();
                personInfo.Tenant_RefID               = securityTicket.TenantID;
                personInfo.Creation_Timestamp         = DateTime.Now;
                personInfo.Modification_Timestamp     = DateTime.Now;
                personInfo.AgeCalculation_YearOfBirth = DateTime.Now.Year - personInfo.BirthDate.Year;
                personInfo.Save(Connection, Transaction);

                //ORM_CMN_Address
                var address = new ORM_CMN_Address();
                address.CMN_AddressID      = personInfo.Address_RefID;
                address.Street_Name        = Parameter.Street_Name;
                address.Street_Number      = Parameter.Street_Number;
                address.City_Name          = Parameter.City_Name;
                address.City_PostalCode    = Parameter.City_PostalCode;
                address.Country_ISOCode    = Parameter.Country_ISOCode;
                address.Tenant_RefID       = securityTicket.TenantID;
                address.Creation_Timestamp = DateTime.Now;
                address.Save(Connection, Transaction);

                //ORM_CMN_PER_PersonInfo_SocialSecurityNumber
                var socialSecurityNumber = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber();
                socialSecurityNumber.CMN_PER_PersonInfo_SocialSecurityNumberID = Guid.NewGuid();
                socialSecurityNumber.PersonInfo_RefID     = personInfo.CMN_PER_PersonInfoID;
                socialSecurityNumber.SocialSecurityNumber = Parameter.SocialSecurityNumber;
                socialSecurityNumber.Tenant_RefID         = securityTicket.TenantID;
                socialSecurityNumber.Creation_Timestamp   = DateTime.Now;
                socialSecurityNumber.Save(Connection, Transaction);

                var TelephoneCompanyType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                                          new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                var MobileCompanyType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                                       new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();
                var EmailType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                               new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();
                //add into database
                //var UrlType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                //      new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                //      {
                //          Type = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.URL),
                //          Tenant_RefID = securityTicket.TenantID,
                //          IsDeleted = false
                //      }).Single();
                var FaxType = CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction,
                                                                                             new CL1_CMN_PER.ORM_CMN_PER_CommunicationContact_Type.Query()
                {
                    Type         = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Fax),
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();



                ORM_CMN_PER_CommunicationContact communicationContactsPhone = new ORM_CMN_PER_CommunicationContact();

                communicationContactsPhone.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContactsPhone.PersonInfo_RefID       = personInfo.CMN_PER_PersonInfoID;
                communicationContactsPhone.Contact_Type           = TelephoneCompanyType.CMN_PER_CommunicationContact_TypeID;
                communicationContactsPhone.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone)).Single().Content;
                communicationContactsPhone.Creation_Timestamp     = DateTime.Now;
                communicationContactsPhone.Modification_Timestamp = DateTime.Now;
                communicationContactsPhone.Tenant_RefID           = securityTicket.TenantID;
                communicationContactsPhone.Save(Connection, Transaction);

                ORM_CMN_PER_CommunicationContact communicationContactsMobile = new ORM_CMN_PER_CommunicationContact();

                communicationContactsMobile.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContactsMobile.PersonInfo_RefID       = personInfo.CMN_PER_PersonInfoID;
                communicationContactsMobile.Contact_Type           = MobileCompanyType.CMN_PER_CommunicationContact_TypeID;
                communicationContactsMobile.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile)).Single().Content;
                communicationContactsMobile.Creation_Timestamp     = DateTime.Now;
                communicationContactsMobile.Modification_Timestamp = DateTime.Now;
                communicationContactsMobile.Tenant_RefID           = securityTicket.TenantID;

                communicationContactsMobile.Save(Connection, Transaction);

                ORM_CMN_PER_CommunicationContact communicationContactsEmail = new ORM_CMN_PER_CommunicationContact();

                communicationContactsEmail.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContactsEmail.PersonInfo_RefID       = personInfo.CMN_PER_PersonInfoID;
                communicationContactsEmail.Contact_Type           = EmailType.CMN_PER_CommunicationContact_TypeID;
                communicationContactsEmail.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email)).Single().Content;
                communicationContactsEmail.Creation_Timestamp     = DateTime.Now;
                communicationContactsEmail.Modification_Timestamp = DateTime.Now;
                communicationContactsEmail.Tenant_RefID           = securityTicket.TenantID;

                communicationContactsEmail.Save(Connection, Transaction);

                //*******************Save languages to patient************************

                if (Parameter.Languages != null && Parameter.Languages.Count() != 0)
                {
                    foreach (var language in Parameter.Languages)
                    {
                        ORM_CMN_BPT_BusinessParticipant_SpokenLanguage bpLanguage = new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage();
                        bpLanguage.CMN_BPT_BusinessParticipant_RefID            = businessParticipant.CMN_BPT_BusinessParticipantID;
                        bpLanguage.CMN_BPT_BusinessParticipant_SpokenLanguageID = Guid.NewGuid();
                        bpLanguage.CMN_Language_RefID = language.CMN_Language_RefID;
                        bpLanguage.IsDeleted          = false;
                        bpLanguage.Tenant_RefID       = securityTicket.TenantID;
                        bpLanguage.Save(Connection, Transaction);
                    }
                }

                //#region Upload To Elastic

                //bool indexExists = true;
                //#region set Mapping
                //string jsonPatientMapping = new MapBuilder<Patient>()
                //             .RootObject("patient", ro => ro
                //             .Properties(pr => pr
                //                 .MultiField("name", mfp => mfp.Fields(f => f
                //                     .String("name", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                     )
                //                 )
                //                  .MultiField("last_name", mfp => mfp.Fields(f => f
                //                                     .String("last_name", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                                     )
                //                                  )
                //                    .MultiField("birthday", mfp => mfp.Fields(f => f
                //                                     .String("birthday", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                                     )
                //                                  )
                //                 .MultiField("age", mfp => mfp.Fields(f => f
                //                                     .String("age", sp => sp.IndexAnalyzer("autocomplete").SearchAnalyzer(DefaultAnalyzers.standard))
                //                                     .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive"))
                //                                     )
                //                                  )
                //                 )).BuildBeautified();
                //#endregion


                //try
                //{
                //    connection.Head(new IndexExistsCommand(securityTicket.TenantID.ToString()));
                //}
                //catch (OperationException ex)
                //{
                //    if (ex.HttpStatusCode == 404)
                //        indexExists = false;
                //}

                //if (!indexExists)
                //{

                //    #region set index settings
                //    string settings = new IndexSettingsBuilder()
                //                          .Analysis(anl => anl
                //                              .Filter(fil => fil
                //                                  .EdgeNGram("autocomplete_filter", gr => gr.MinGram(1).MaxGram(20)))
                //                              .Analyzer(a => a
                //                                  .Custom("caseinsensitive", custom => custom
                //                                      .Tokenizer(DefaultTokenizers.keyword)
                //                                      .Filter("lowercase")
                //                                  )
                //                                  .Custom("autocomplete", custom => custom
                //                                      .Tokenizer(DefaultTokenizers.standard)
                //                                      .Filter("lowercase", "autocomplete_filter")
                //                                  )
                //                              )
                //                          )
                //                          .BuildBeautified();
                //    #endregion
                //    connection.Put(securityTicket.TenantID.ToString(), settings);

                //}


                //#region check if type exists

                //bool typeExists = true;

                //try
                //{
                //    connection.Head(new IndexExistsCommand(securityTicket.TenantID.ToString() + "/patient"));
                //}
                //catch (OperationException ex)
                //{
                //    if (ex.HttpStatusCode == 404)
                //        typeExists = false;
                //}
                //#endregion


                //if (!typeExists)
                //    connection.Put(new PutMappingCommand(securityTicket.TenantID.ToString(), "patient"), jsonPatientMapping);

                //string bulkCommand = new BulkCommand(index: securityTicket.TenantID.ToString(), type: "patient").Refresh();

                //List<Patient> patientList = new List<Patient>();
                //Patient patient_elastic = new Patient();
                //patient_elastic.id = patient.HEC_PatientID.ToString();
                //patient_elastic.age = (DateTime.Today.Year - Parameter.BirthDate.Year).ToString();
                //patient_elastic.birthday = Parameter.BirthDate.ToShortDateString();
                //patient_elastic.last_name = Parameter.LastName;
                //patient_elastic.name = Parameter.FirstName;
                //patientList.Add(patient_elastic);

                //string bulkJson = new BulkBuilder(serializer)
                //    .BuildCollection(patientList, (builder, pro) => builder.Index(data: pro, id: pro.id)
                //    );
                //connection.Post(bulkCommand, bulkJson);

                //#endregion
            }
            #endregion
            else
            {
                #region Delete
                if (Parameter.isDeleted)
                {
                    var patientQuery = new ORM_HEC_Patient.Query();
                    patientQuery.HEC_PatientID = Parameter.ID;
                    patientQuery.IsDeleted     = false;
                    patientQuery.Tenant_RefID  = securityTicket.TenantID;

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

                    var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    businessParticipantQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID;
                    businessParticipantQuery.IsDeleted    = false;
                    businessParticipantQuery.Tenant_RefID = securityTicket.TenantID;

                    var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();
                    businessParticipant.IsDeleted = true;
                    businessParticipant.Save(Connection, Transaction);

                    var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
                    personInfoQuery.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    personInfoQuery.IsDeleted            = false;
                    personInfoQuery.Tenant_RefID         = securityTicket.TenantID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single();
                    personInfo.IsDeleted = true;
                    personInfo.Save(Connection, Transaction);

                    var addressQuery = new ORM_CMN_Address.Query();
                    addressQuery.CMN_AddressID = personInfo.Address_RefID;
                    addressQuery.IsDeleted     = false;
                    addressQuery.Tenant_RefID  = securityTicket.TenantID;

                    var address = ORM_CMN_Address.Query.Search(Connection, Transaction, addressQuery).Single();
                    address.IsDeleted = true;
                    address.Save(Connection, Transaction);

                    var socialSecurityNumberQuery = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query();
                    socialSecurityNumberQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    socialSecurityNumberQuery.IsDeleted        = false;
                    socialSecurityNumberQuery.Tenant_RefID     = securityTicket.TenantID;

                    var socialSecurityNumber = ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query.Search(Connection, Transaction, socialSecurityNumberQuery).Single();
                    socialSecurityNumber.IsDeleted = true;
                    socialSecurityNumber.Save(Connection, Transaction);

                    var communicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                    communicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    communicationContactQuery.IsDeleted        = false;
                    communicationContactQuery.Tenant_RefID     = securityTicket.TenantID;

                    var communicationContactList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactQuery).ToList();

                    ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.SoftDelete(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                        CMN_BPT_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                    });

                    //// delete on Elastic
                    //connection.Delete(securityTicket.TenantID.ToString() + "/patient/" + Parameter.ID.ToString());
                }
                #endregion
                #region Edit
                else
                {
                    var patientQuery = new ORM_HEC_Patient.Query();
                    patientQuery.HEC_PatientID = Parameter.ID;
                    patientQuery.IsDeleted     = false;
                    patientQuery.Tenant_RefID  = securityTicket.TenantID;

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

                    var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    businessParticipantQuery.CMN_BPT_BusinessParticipantID = patient.CMN_BPT_BusinessParticipant_RefID;
                    businessParticipantQuery.IsDeleted    = false;
                    businessParticipantQuery.Tenant_RefID = securityTicket.TenantID;

                    var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

                    var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
                    personInfoQuery.CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    personInfoQuery.IsDeleted            = false;
                    personInfoQuery.Tenant_RefID         = securityTicket.TenantID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single();
                    personInfo.FirstName    = Parameter.FirstName;
                    personInfo.LastName     = Parameter.LastName;
                    personInfo.PrimaryEmail = Parameter.PrimaryEmail;
                    personInfo.Title        = Parameter.Title;
                    personInfo.Gender       = Int32.Parse(Parameter.Gender);
                    personInfo.ProfileImage_Document_RefID = Parameter.ProfileImage_Document_RefID;
                    personInfo.BirthDate                  = Parameter.BirthDate;
                    personInfo.Salutation_General         = Parameter.AcademicTitle;
                    personInfo.Modification_Timestamp     = DateTime.Now;
                    personInfo.AgeCalculation_YearOfBirth = DateTime.Now.Year - personInfo.BirthDate.Year;
                    personInfo.Save(Connection, Transaction);

                    if (personInfo.Address_RefID != Guid.Empty)
                    {
                        var addressQuery = new ORM_CMN_Address.Query();
                        addressQuery.CMN_AddressID = personInfo.Address_RefID;
                        addressQuery.IsDeleted     = false;
                        addressQuery.Tenant_RefID  = securityTicket.TenantID;

                        var address = ORM_CMN_Address.Query.Search(Connection, Transaction, addressQuery).Single();
                        address.Street_Name     = Parameter.Street_Name;
                        address.Street_Number   = Parameter.Street_Number;
                        address.City_Name       = Parameter.City_Name;
                        address.City_PostalCode = Parameter.City_PostalCode;
                        address.Country_ISOCode = Parameter.Country_ISOCode;
                        address.Save(Connection, Transaction);
                    }
                    else
                    {
                        var address = new ORM_CMN_Address();
                        address.CMN_AddressID      = Guid.NewGuid();
                        address.Street_Name        = Parameter.Street_Name;
                        address.Street_Number      = Parameter.Street_Number;
                        address.City_Name          = Parameter.City_Name;
                        address.City_PostalCode    = Parameter.City_PostalCode;
                        address.Country_ISOCode    = Parameter.Country_ISOCode;
                        address.Tenant_RefID       = securityTicket.TenantID;
                        address.Creation_Timestamp = DateTime.Now;
                        address.Save(Connection, Transaction);


                        personInfo.Address_RefID = address.CMN_AddressID;
                        personInfo.Save(Connection, Transaction);
                    }


                    var socialSecurityNumberQuery = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query();
                    socialSecurityNumberQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    socialSecurityNumberQuery.IsDeleted        = false;
                    socialSecurityNumberQuery.Tenant_RefID     = securityTicket.TenantID;

                    var socialSecurityNumber = ORM_CMN_PER_PersonInfo_SocialSecurityNumber.Query.Search(Connection, Transaction, socialSecurityNumberQuery).SingleOrDefault();

                    if (socialSecurityNumber == null)
                    {
                        socialSecurityNumber = new ORM_CMN_PER_PersonInfo_SocialSecurityNumber();
                        socialSecurityNumber.CMN_PER_PersonInfo_SocialSecurityNumberID = Guid.NewGuid();
                        socialSecurityNumber.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                        socialSecurityNumber.Tenant_RefID     = securityTicket.TenantID;
                    }

                    socialSecurityNumber.SocialSecurityNumber = Parameter.SocialSecurityNumber;
                    socialSecurityNumber.Save(Connection, Transaction);

                    var communicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                    communicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    communicationContactQuery.IsDeleted        = false;
                    communicationContactQuery.Tenant_RefID     = securityTicket.TenantID;

                    var communicationContactList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, communicationContactQuery).ToList();

                    List <string> unusedTypes = new List <string>()
                    {
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.URL),
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Mobile),
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone),
                        DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Email)
                    };

                    foreach (var communicationContact in communicationContactList)
                    {
                        var communicationContact_TypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                        communicationContact_TypeQuery.CMN_PER_CommunicationContact_TypeID = communicationContact.Contact_Type;
                        communicationContact_TypeQuery.IsDeleted    = false;
                        communicationContact_TypeQuery.Tenant_RefID = securityTicket.TenantID;
                        var communicationContact_Type = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, communicationContact_TypeQuery).Single();

                        var newType = Parameter.ContactTypes.Where(i => i.Type == communicationContact_Type.Type).Single();
                        communicationContact.Content = newType.Content;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.Save(Connection, Transaction);

                        if (unusedTypes.Contains(communicationContact_Type.Type))
                        {
                            unusedTypes.Remove(communicationContact_Type.Type);
                        }
                    }

                    var contactTypes = cls_Get_AllComunicationContactTypes.Invoke(Connection, Transaction, securityTicket).Result.ToList();

                    foreach (var type in unusedTypes)
                    {
                        ORM_CMN_PER_CommunicationContact communicationContactsPhone = new ORM_CMN_PER_CommunicationContact();

                        communicationContactsPhone.CMN_PER_CommunicationContactID = Guid.NewGuid();
                        communicationContactsPhone.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                        P_L2CN_GCTIDfGPMID_1359 contantTypeParam = new P_L2CN_GCTIDfGPMID_1359();
                        contantTypeParam.Type = type;
                        var contantTypeID = cls_Get_ContantTypeID_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, contantTypeParam, securityTicket).Result.ContactTypeID;
                        communicationContactsPhone.Contact_Type           = contantTypeID;
                        communicationContactsPhone.Content                = Parameter.ContactTypes.Where(p => p.Type == DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(CL2_Contact.DomainManagement.EComunactionContactType.Phone)).Single().Content;
                        communicationContactsPhone.Creation_Timestamp     = DateTime.Now;
                        communicationContactsPhone.Modification_Timestamp = DateTime.Now;
                        communicationContactsPhone.Tenant_RefID           = securityTicket.TenantID;
                        communicationContactsPhone.Save(Connection, Transaction);
                    }

                    //connection.Delete(securityTicket.TenantID.ToString() + "/patient/" + Parameter.ID.ToString());
                    //string bulkCommand = new BulkCommand(index: securityTicket.TenantID.ToString(), type: "patient").Refresh();

                    //List<Patient> patientList = new List<Patient>();
                    //Patient patient_elastic = new Patient();
                    //patient_elastic.id = patient.HEC_PatientID.ToString();
                    //patient_elastic.age = (DateTime.Today.Year - Parameter.BirthDate.Year).ToString();
                    //patient_elastic.birthday = Parameter.BirthDate.ToShortDateString();
                    //patient_elastic.last_name = Parameter.LastName;
                    //patient_elastic.name = Parameter.FirstName;
                    //patientList.Add(patient_elastic);

                    //string bulkJson = new BulkBuilder(serializer)
                    //    .BuildCollection(patientList, (builder, pro) => builder.Index(data: pro, id: pro.id)
                    //    );
                    //connection.Post(bulkCommand, bulkJson);


                    #region languages

                    if (Parameter.Languages == null || Parameter.Languages.Count() == 0)
                    {
                        P_L5PA_GPBD_1613_Languages Languages = new P_L5PA_GPBD_1613_Languages();
                        Languages.CMN_Language_RefID = Guid.Empty;
                    }
                    else if (Parameter.Languages != null || Parameter.Languages.Count() != 0)
                    {
                        foreach (var language in Parameter.Languages)
                        {
                            var languageToPatient = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                                CMN_Language_RefID = language.CMN_Language_RefID, CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                            }).FirstOrDefault();
                            if (languageToPatient == null)
                            {
                                ORM_CMN_BPT_BusinessParticipant_SpokenLanguage bpLanguage = new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage();
                                bpLanguage.CMN_BPT_BusinessParticipant_RefID            = patient.CMN_BPT_BusinessParticipant_RefID;
                                bpLanguage.CMN_BPT_BusinessParticipant_SpokenLanguageID = Guid.NewGuid();
                                bpLanguage.CMN_Language_RefID = language.CMN_Language_RefID;
                                bpLanguage.IsDeleted          = false;
                                bpLanguage.Tenant_RefID       = securityTicket.TenantID;
                                bpLanguage.Save(Connection, Transaction);
                            }
                        }

                        // deleting languages to patient that were deleted during edit

                        List <ORM_CMN_BPT_BusinessParticipant_SpokenLanguage> languageToDoctorList = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                            CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                        });
                        foreach (var languageToDoctor in languageToDoctorList)
                        {
                            if (Parameter.Languages.FirstOrDefault(x => x.CMN_Language_RefID == languageToDoctor.CMN_Language_RefID) == null)
                            {
                                languageToDoctor.IsDeleted = true;
                                languageToDoctor.Save(Connection, Transaction);
                            }
                        }
                    }
                    else
                    {
                        List <ORM_CMN_BPT_BusinessParticipant_SpokenLanguage> languageToDoctorList = ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_SpokenLanguage.Query {
                            CMN_BPT_BusinessParticipant_RefID = patient.CMN_BPT_BusinessParticipant_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                        });
                        if (languageToDoctorList != null || languageToDoctorList.Count() != 0)
                        {
                            foreach (var language in languageToDoctorList)
                            {
                                language.IsDeleted = true;
                                language.Save(Connection, Transaction);
                            }
                        }
                    }

                    #endregion
                }
                #endregion
            }
            returnValue.Result = patient.HEC_PatientID;
            return(returnValue);

            #endregion UserCode
        }