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;
        }
        protected void MemberClaimHistoryGrid_OnNeedDataSource(Object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs eventArgs)
        {
            #region Validate Call

            if (MercuryApplication == null)
            {
                return;
            }

            if (Member == null)
            {
                return;
            }

            #endregion


            Boolean needsData = false;

            needsData = needsData || (MemberClaimHistoryGrid_Count == 0);

            needsData = needsData || (MemberClaimHistoryGrid_DataTable.Rows.Count == 0);

            needsData = needsData || (MemberClaimHistoryGrid_PageSize != MemberClaimHistoryGrid.PageSize);

            needsData = needsData || (MemberClaimHistoryGrid_CurrentPage != MemberClaimHistoryGrid.CurrentPageIndex);



            System.Data.DataTable dataTable = MemberClaimHistoryGrid_DataTable;

            if (needsData)
            {
                MemberClaimHistoryGrid.PageSize = MemberClaimHistoryGrid_PageSize;

                dataTable.Rows.Clear();

                if (MemberClaimHistoryGrid_Count == 0)
                {
                    MemberClaimHistoryGrid_Count = Convert.ToInt32(MercuryApplication.MemberClaimsGetCount(Member.Id));

                    MemberClaimHistoryGrid.VirtualItemCount = Convert.ToInt32(MemberClaimHistoryGrid_Count);
                }

                MemberClaimHistoryGrid_CurrentPage = MemberClaimHistoryGrid.CurrentPageIndex;

                List <Server.Application.Claim> memberClaims;

                Int32 initialRow = MemberClaimHistoryGrid.CurrentPageIndex * MemberClaimHistoryGrid.PageSize + 1;

                memberClaims = MercuryApplication.MemberClaimsGetByPage(Member.Id, initialRow, MemberClaimHistoryGrid.PageSize);


                foreach (Server.Application.Claim currentClaim in memberClaims)
                {
                    // String diagnosisInformation = "<span title=\"" + currentClaim.PrimaryDiagnosisDescription + "\">" + currentClaim.PrimaryDiagnosisCode + "</span>";

                    String diagnosisInformation = CommonFunctions.DiagnosisDescription(MercuryApplication, currentClaim.PrincipalDiagnosisCode, currentClaim.PrincipalDiagnosisVersion);

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

                    Client.Core.Provider.Provider billingProvider = MercuryApplication.ProviderGet(currentClaim.PayToProviderId, true);

                    Client.Core.Provider.Provider serviceProvider = MercuryApplication.ProviderGet(currentClaim.ServiceProviderId, true);

                    String billingProviderName = String.Empty;

                    String serviceProviderName = String.Empty;

                    if (billingProvider != null)
                    {
                        billingProviderName = Web.CommonFunctions.ProviderProfileAnchor(billingProvider.Id, billingProvider.Name);
                    }

                    if (serviceProvider != null)
                    {
                        serviceProviderName = Mercury.Web.CommonFunctions.ProviderProfileAnchor(serviceProvider.Id, serviceProvider.Name);
                    }


                    String claimStatusInformation = "<span title=\"" + currentClaim.DenialReason + "\">" + currentClaim.Status + ((!String.IsNullOrEmpty(currentClaim.DenialReason)) ? "*" : String.Empty) + "</span>";


                    dataTable.Rows.Add(

                        currentClaim.Id.ToString(),

                        currentClaim.ClaimNumber,

                        currentClaim.MemberId.ToString(),

                        currentClaim.ServiceProviderId.ToString(),

                        currentClaim.PayToProviderId.ToString(),

                        currentClaim.ClaimType.ToString(),

                        currentClaim.ClaimFromDate.ToString("MM/dd/yyyy"),

                        currentClaim.ClaimThruDate.ToString("MM/dd/yyyy"),

                        (currentClaim.AdmissionDate.HasValue) ? currentClaim.AdmissionDate.Value.ToString("MM/dd/yyyy") : "&nbsp",

                        claimStatusInformation,

                        billTypeInformation,

                        diagnosisInformation,

                        currentClaim.PrincipalDiagnosisDescription,

                        billingProviderName,

                        serviceProviderName,

                        currentClaim.BilledAmount.ToString("$###,###,##0.00"),

                        currentClaim.PaidAmount.ToString("$###,###,##0.00"),

                        (currentClaim.PaidDate.HasValue) ? currentClaim.PaidDate.Value.ToString("MM/dd/yyyy") : "&nbsp"

                        );
                }

                MemberClaimHistoryGrid_DataTable = dataTable;
            }

            MemberClaimHistoryGrid.DataSource = MemberClaimHistoryGrid_DataTable;

            MemberClaimHistoryGrid.MasterTableView.DetailTables[0].DataSource = MemberClaimHistoryGrid_ClaimLineTable;

            return;
        }