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

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

                var ORM_CMN_BPT_Memo_AdditionalFieldQuery = new ORM_CMN_BPT_Memo_AdditionalField.Query();
                ORM_CMN_BPT_Memo_AdditionalFieldQuery.Memo_RefID   = Parameter.CMN_BPT_MemoID;
                ORM_CMN_BPT_Memo_AdditionalFieldQuery.Tenant_RefID = securityTicket.TenantID;
                ORM_CMN_BPT_Memo_AdditionalFieldQuery.IsDeleted    = false;

                var additianFileds = ORM_CMN_BPT_Memo_AdditionalField.Query.SoftDelete(Connection, Transaction, ORM_CMN_BPT_Memo_AdditionalFieldQuery);

                var ORM_DOC_Structure_Header_Query = new ORM_DOC_Structure_Header.Query();
                ORM_DOC_Structure_Header_Query.IsDeleted              = false;
                ORM_DOC_Structure_Header_Query.Tenant_RefID           = securityTicket.TenantID;
                ORM_DOC_Structure_Header_Query.DOC_Structure_HeaderID = memo.DocumentStructureHeader_RefID;
                ORM_DOC_Structure_Header.Query.SoftDelete(Connection, Transaction, ORM_DOC_Structure_Header_Query);

                var ORM_DOC_Structure_Query = new ORM_DOC_Structure.Query();
                ORM_DOC_Structure_Query.IsDeleted              = false;
                ORM_DOC_Structure_Query.Tenant_RefID           = securityTicket.TenantID;
                ORM_DOC_Structure_Query.Structure_Header_RefID = memo.DocumentStructureHeader_RefID;
                ORM_DOC_Structure.Query.SoftDelete(Connection, Transaction, ORM_DOC_Structure_Query);

                var ORM_CMN_BPT_Memo_RelatedParticipant_Query = new ORM_CMN_BPT_Memo_RelatedParticipant.Query();
                ORM_CMN_BPT_Memo_RelatedParticipant_Query.IsDeleted          = false;
                ORM_CMN_BPT_Memo_RelatedParticipant_Query.Tenant_RefID       = securityTicket.TenantID;
                ORM_CMN_BPT_Memo_RelatedParticipant_Query.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
                ORM_CMN_BPT_Memo_RelatedParticipant.Query.SoftDelete(Connection, Transaction, ORM_CMN_BPT_Memo_RelatedParticipant_Query);
            }


            return(returnValue);

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

            var doctorQuery = new ORM_HEC_Doctor.Query();
            doctorQuery.HEC_DoctorID = Parameter.Doctor_ID;
            var doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First();

            var practicesQuery = new ORM_HEC_MedicalPractis.Query();
            practicesQuery.HEC_MedicalPractiseID = Parameter.Practice_ID;
            var practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First();

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

            var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            var practice_bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).FirstOrDefault();

            ORM_CMN_BPT_Memo memo = new ORM_CMN_BPT_Memo();
            if (Parameter.CMN_BPT_MemoID != Guid.Empty)
            {
                var result = memo.Load(Connection, Transaction, Parameter.CMN_BPT_MemoID);
                if (result.Status != FR_Status.Success || memo.CMN_BPT_MemoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                memo.UpdatedBy_Account_RefID = securityTicket.AccountID;
                memo.UpdatedOn = Parameter.Creation_Timestamp;
            }
            else
            {
                ORM_DOC_Structure_Header docHeader = new ORM_DOC_Structure_Header();
                docHeader.Label        = Parameter.Memo_Abbreviation + "_Header_Label";
                docHeader.Tenant_RefID = securityTicket.TenantID;
                docHeader.Save(Connection, Transaction);

                ORM_DOC_Structure docStructure = new ORM_DOC_Structure();
                docStructure.Label                  = Parameter.Memo_Abbreviation + "_Structure";
                docStructure.Tenant_RefID           = securityTicket.TenantID;
                docStructure.Structure_Header_RefID = docHeader.DOC_Structure_HeaderID;
                docStructure.Save(Connection, Transaction);

                memo.DocumentStructureHeader_RefID = docHeader.DOC_Structure_HeaderID;
                memo.CreatedBy_Account_RefID       = securityTicket.AccountID;
                memo.Creation_Timestamp            = Parameter.Creation_Timestamp;
                memo.UpdatedOn = memo.Creation_Timestamp;
            }

            memo.Memo_Text         = Parameter.Memo_Text;
            memo.Memo_Title        = Parameter.Memo_Title;
            memo.Memo_Abbreviation = Parameter.Memo_Abbreviation;
            memo.Tenant_RefID      = securityTicket.TenantID;
            memo.Save(Connection, Transaction);

            if (Parameter.AdditionalFields != null)
            {
                foreach (var AdditionalField in Parameter.AdditionalFields)
                {
                    ORM_CMN_BPT_Memo_AdditionalField addFieldItem = new ORM_CMN_BPT_Memo_AdditionalField();
                    if (AdditionalField.CMN_BPT_Memo_AdditionalFieldID != Guid.Empty)
                    {
                        var result = addFieldItem.Load(Connection, Transaction, AdditionalField.CMN_BPT_Memo_AdditionalFieldID);
                        if (result.Status != FR_Status.Success || addFieldItem.CMN_BPT_Memo_AdditionalFieldID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    addFieldItem.Memo_RefID   = memo.CMN_BPT_MemoID;
                    addFieldItem.Field_Key    = AdditionalField.Field_Key;
                    addFieldItem.Field_Value  = AdditionalField.Field_Value;
                    addFieldItem.Tenant_RefID = securityTicket.TenantID;
                    addFieldItem.Save(Connection, Transaction);
                }
            }
            var memo2DocQuery = new ORM_CMN_BPT_Memo_RelatedParticipant.Query();
            memo2DocQuery.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2DocQuery.CMN_BPT_Memo_RelatedParticipantID = doctor.BusinessParticipant_RefID;
            var memo2DocQueryRes = ORM_CMN_BPT_Memo_RelatedParticipant.Query.Search(Connection, Transaction, memo2DocQuery).FirstOrDefault();
            ORM_CMN_BPT_Memo_RelatedParticipant memo2Doc;
            if (memo2DocQueryRes != null)
            {
                memo2Doc = memo2DocQueryRes;
            }
            else
            {
                memo2Doc = new ORM_CMN_BPT_Memo_RelatedParticipant();
                memo2Doc.CMN_BPT_Memo_RelatedParticipantID = Guid.NewGuid();
            }
            memo2Doc.Tenant_RefID       = securityTicket.TenantID;
            memo2Doc.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2Doc.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;
            memo2Doc.Save(Connection, Transaction);



            var memo2PracticeQuery = new ORM_CMN_BPT_Memo_RelatedParticipant.Query();
            memo2DocQuery.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2DocQuery.CMN_BPT_Memo_RelatedParticipantID = practice_bParticipant.CMN_BPT_BusinessParticipantID;
            var memo2PracticeQueryRes = ORM_CMN_BPT_Memo_RelatedParticipant.Query.Search(Connection, Transaction, memo2DocQuery).FirstOrDefault();
            ORM_CMN_BPT_Memo_RelatedParticipant memo2Practice;
            if (memo2DocQueryRes != null)
            {
                memo2Practice = memo2DocQueryRes;
            }
            else
            {
                memo2Practice = new ORM_CMN_BPT_Memo_RelatedParticipant();
                memo2Practice.CMN_BPT_Memo_RelatedParticipantID = Guid.NewGuid();
            }
            memo2Practice.Tenant_RefID       = securityTicket.TenantID;
            memo2Practice.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2Practice.CMN_BPT_BusinessParticipant_RefID = practice_bParticipant.CMN_BPT_BusinessParticipantID;
            memo2Practice.Save(Connection, Transaction);


            returnValue.Result = memo.CMN_BPT_MemoID;

            return(returnValue);

            #endregion UserCode
        }