protected void MemberServiceAction_OnClick(Object sender, EventArgs eventArgs)
        {
            if (MercuryApplication == null)
            {
                return;
            }


            Int64 memberServiceId;

            Boolean success = false;

            String postScript = String.Empty;

            String postScriptArguments = String.Empty;


            if (Int64.TryParse(MemberServiceAction_MemberServiceId.Text, out memberServiceId))
            {
                switch (MemberServiceAction_CommandName.Text)
                {
                case "RemoveManual":

                    success = MercuryApplication.MemberServiceRemoveManual(memberServiceId);

                    if (!success)
                    {
                        postScript = ("alert (\"" + MercuryApplication.LastException.Message.Replace("\"", "\\") + "\");");
                    }

                    if ((TelerikAjaxManager != null) && (!String.IsNullOrEmpty(postScript)))
                    {
                        TelerikAjaxManager.ResponseScripts.Add(postScript);
                    }

                    break;

                default:

                    System.Diagnostics.Debug.WriteLine("Unknown Command: " + MemberServiceAction_CommandName);

                    break;
                }
            }


            MemberServicesGrid.DataSource = null;

            MemberServicesGrid.Rebind();

            return;
        }
        protected void MemberServicesGrid_OnPageSizeChanged(Object sender, Telerik.Web.UI.GridPageSizeChangedEventArgs eventArgs)
        {
            if (MemberServicesGrid_PageSize != eventArgs.NewPageSize)
            {
                MemberServicesGrid_PageSize = eventArgs.NewPageSize;

                MemberServicesGrid.PageSize = eventArgs.NewPageSize;

                MemberServicesGrid.DataSource = null;

                MemberServicesGrid.Rebind();
            }
        }
        protected void MemberServiceToolbar_OnButtonClick(Object sender, Telerik.Web.UI.RadToolBarEventArgs eventArgs)
        {
            switch (eventArgs.Item.Text)
            {
            case "Show Hidden":

                MemberServiceShowHidden = !MemberServiceShowHidden;

                MemberServicesGrid_CurrentPage = 0;

                MemberServicesGrid.CurrentPageIndex = MemberServicesGrid_CurrentPage;

                MemberServicesGrid.DataSource = null;

                MemberServicesGrid.Rebind();

                break;

            default: System.Diagnostics.Debug.WriteLine("MemberServiceToolbar_OnButtonClick: " + eventArgs.Item.Text); break;
            }

            return;
        }
        protected void MemberServicesGrid_OnItemCommand(Object sender, Telerik.Web.UI.GridCommandEventArgs eventArgs)
        {
            if (MercuryApplication == null)
            {
                return;
            }


            System.Data.DataTable detailTable = null;

            Telerik.Web.UI.RadToolBar gridToolBar = null;

            Boolean success = false;

            String postScript = String.Empty;


            switch (eventArgs.CommandName)
            {
            case "ExpandCollapse":

                #region Expand/Collapse

                Telerik.Web.UI.GridDataItem gridItem = (Telerik.Web.UI.GridDataItem)eventArgs.Item;

                Int64 memberServiceId;

                if (Int64.TryParse(gridItem["MemberServiceId"].Text, out memberServiceId))
                {
                    switch (gridItem["ServiceType"].Text)
                    {
                    case "Singleton":

                        #region Singleton Detail Table

                        detailTable = MemberServicesGrid_DataTableSingletonTable;

                        detailTable.Rows.Clear();

                        List <Mercury.Server.Application.MemberServiceDetailSingleton> detailSingletons;

                        detailSingletons = MercuryApplication.MemberServiceDetailSingletonGet(memberServiceId);

                        foreach (Mercury.Server.Application.MemberServiceDetailSingleton currentDetail in detailSingletons)
                        {
                            // String principalDiagnosisInformation = "<span title=\"" + MercuryApplication.DiagnosisDescription (currentDetail.PrincipalDiagnosisCode, currentDetail.PrincipalDiagnosisVersion) + "\">" + currentDetail.PrincipalDiagnosisCode + "</span>";

                            // String diagnosisInformation = "<span title=\"" + MercuryApplication.DiagnosisDescription (currentDetail.DiagnosisCode, currentDetail.DiagnosisVersion) + "\">" + currentDetail.DiagnosisCode + "</span>";

                            String principalDiagnosisInformation = CommonFunctions.DiagnosisDescription(MercuryApplication, currentDetail.PrincipalDiagnosisCode, currentDetail.PrincipalDiagnosisVersion);

                            String diagnosisInformation = CommonFunctions.DiagnosisDescription(MercuryApplication, currentDetail.DiagnosisCode, currentDetail.DiagnosisVersion);


                            String revenueCodeInformation = "<span title=\"" + MercuryApplication.RevenueCodeDescription(currentDetail.RevenueCode) + "\">" + currentDetail.RevenueCode + "</span>";

                            String procedureCodeInformation = "<span title=\"" + MercuryApplication.ProcedureCodeDescription(currentDetail.ProcedureCode) + "\">" + currentDetail.ProcedureCode + "</span>";

                            String billTypeInformation = "<span title=\"" + MercuryApplication.BillTypeDescription(currentDetail.BillType) + "\">" + currentDetail.BillType + "</span>";

                            String icd9ProcedureCodeInformation = "<span title=\"" + MercuryApplication.Icd9ProcedureCodeDescription(currentDetail.Icd9ProcedureCode) + "\">" + currentDetail.Icd9ProcedureCode + "</span>";

                            detailTable.Rows.Add(

                                currentDetail.MemberServiceId.ToString(),

                                currentDetail.SingletonDefinitionId.ToString(),

                                currentDetail.EventDate.ToString("MM/dd/yyyy"),

                                currentDetail.ExternalClaimId,

                                currentDetail.ClaimLine.ToString(),

                                currentDetail.ClaimType,

                                billTypeInformation,

                                principalDiagnosisInformation,

                                diagnosisInformation,

                                icd9ProcedureCodeInformation,

                                currentDetail.LocationCode,

                                revenueCodeInformation,

                                procedureCodeInformation,

                                currentDetail.ModifierCode,

                                currentDetail.SpecialtyName,

                                currentDetail.IsPcpClaim.ToString(),

                                currentDetail.NdcCode,

                                currentDetail.Units.ToString(),

                                currentDetail.TherapeuticClassification,

                                currentDetail.LabLoincCode,

                                currentDetail.LabValue.ToString(),

                                currentDetail.Description

                                );
                        }

                        MemberServicesGrid_DataTableSingletonTable = detailTable;

                        MemberServicesGrid.MasterTableView.DetailTables[0].DataSource = detailTable;


                        #endregion

                        break;

                    case "Set":

                        #region Set Detail Table

                        detailTable = MemberServicesGrid_DataTableSetTable;

                        detailTable.Rows.Clear();

                        List <Mercury.Server.Application.MemberServiceDetailSet> detailSets;

                        detailSets = MercuryApplication.MemberServiceDetailSetGet(memberServiceId);

                        foreach (Mercury.Server.Application.MemberServiceDetailSet currentDetail in detailSets)
                        {
                            detailTable.Rows.Add(

                                currentDetail.MemberServiceId.ToString(),

                                currentDetail.SetDefinitionId.ToString(),

                                currentDetail.DetailMemberServiceId.ToString(),

                                currentDetail.EventDate.ToString("MM/dd/yyyy"),

                                currentDetail.ServiceName,

                                currentDetail.ServiceType.ToString()

                                );
                        }

                        MemberServicesGrid_DataTableSetTable = detailTable;

                        MemberServicesGrid.MasterTableView.DetailTables[1].DataSource = detailTable;

                        #endregion

                        break;
                    }
                }

                #endregion

                break;

            case "MemberServiceAdd":

                #region Member Service Add

                gridToolBar = (Telerik.Web.UI.RadToolBar)eventArgs.Item.FindControl("MemberServiceToolbar");

                if (gridToolBar != null)
                {
                    Telerik.Web.UI.RadComboBox MemberServiceSelection = (Telerik.Web.UI.RadComboBox)(gridToolBar.Items[2].FindControl("MemberServiceSelection"));

                    Telerik.Web.UI.RadDateInput MemberServiceEventDate = (Telerik.Web.UI.RadDateInput)(gridToolBar.Items[2].FindControl("MemberServiceEventDate"));

                    if (MemberServiceSelection != null)
                    {
                        if (!String.IsNullOrEmpty(MemberServiceSelection.SelectedValue))
                        {
                            if (MemberServiceEventDate.SelectedDate.HasValue)
                            {
                                success = MercuryApplication.MemberServiceAddManual(Member.Id, Convert.ToInt64(MemberServiceSelection.SelectedValue), MemberServiceEventDate.SelectedDate.Value);

                                if (!success)
                                {
                                    postScript = ("alert (\"" + MercuryApplication.LastException.Message.Replace("\"", "\\") + "\");");
                                }

                                else
                                {
                                    MemberServicesGrid_Count = 0;

                                    MemberServicesGrid.DataSource = null;

                                    MemberServicesGrid.Rebind();
                                }
                            }

                            else
                            {
                                postScript = ("alert (\"Event Date of Service is Required.\");");
                            }
                        }

                        else
                        {
                            postScript = ("alert (\"No Service Selected for Manual Add.\");");
                        }
                    }

                    else
                    {
                        postScript = ("alert (\"Internal Error: Unable to Find Control MemberServiceSelection.\");");
                    }


                    if ((TelerikAjaxManager != null) && (!String.IsNullOrEmpty(postScript)))
                    {
                        TelerikAjaxManager.ResponseScripts.Add(postScript);
                    }
                }

                #endregion

                break;

            default:

                System.Diagnostics.Debug.WriteLine("MemberServicesGrid_OnItemCommand: " + eventArgs.CommandSource + " " + eventArgs.CommandName + " (" + eventArgs.CommandArgument + ")");

                break;
            }

            return;
        }