protected void ProblemStatementTreeView_OnNodeClick(Object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
        {
            Int64 problemStatementId = 0;

            if (Int64.TryParse(e.Node.Value, out problemStatementId))
            {
                Client.Core.Individual.ProblemStatement problemStatement = MercuryApplication.ProblemStatementGet(problemStatementId, true);


                ProblemStatementDomainName.Text = (problemStatement != null) ? problemStatement.ProblemDomainName : String.Empty;

                ProblemStatementClassName.Text = (problemStatement != null) ? problemStatement.ProblemClassName : String.Empty;

                ProblemStatementName.Text = (problemStatement != null) ? problemStatement.Name : String.Empty;

                ProblemStatementDescription.Text = (problemStatement != null) ? problemStatement.Description : String.Empty;


                ProblemStatementDefiningCharacteristics.Text = (problemStatement != null) ? problemStatement.DefiningCharacteristics : String.Empty;

                ProblemStatementRelatedFactors.Text = (problemStatement != null) ? problemStatement.RelatedFactors : String.Empty;



                Client.Core.Individual.CarePlan defaultCarePlan = (problemStatement != null) ? problemStatement.DefaultCarePlan : null;


                DefaultCarePlanName.Text = (defaultCarePlan != null) ? defaultCarePlan.Name : String.Empty;

                DefaultCarePlanGoals.DataSource = (defaultCarePlan != null) ? defaultCarePlan.Goals : null;

                DefaultCarePlanGoals.DataBind();


                DefaultCarePlanInterventions.DataSource = null;

                if (defaultCarePlan != null)
                {
                    var careInterventions =

                        (from currentCarePlanGoal in defaultCarePlan.Goals

                         from currentCarePlanIntervention in currentCarePlanGoal.Interventions

                         orderby currentCarePlanGoal.Name, currentCarePlanIntervention.Name

                         select currentCarePlanIntervention.CareIntervention).Distinct();

                    DefaultCarePlanInterventions.DataSource = careInterventions;
                }

                DefaultCarePlanInterventions.DataBind();
            }

            return;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Int64 forProblemStatementId = 0;


            if (MercuryApplication == null)
            {
                return;
            }

            if ((!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.ProblemStatementReview))

                && (!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.ProblemStatementManage)))
            {
                Response.Redirect("/PermissionDenied.aspx", true); return;
            }


            if (!Page.IsPostBack)
            {
                // CACHE AVAILABLE PROBLEM STATEMENT TREE

                List <Client.Core.Individual.ProblemStatement> problemStatementsAvailable = MercuryApplication.ProblemStatementsAvailable(false);

                #region Initial Page Load

                if (Request.QueryString["ProblemStatementId"] != null)
                {
                    forProblemStatementId = Int64.Parse(Request.QueryString["ProblemStatementId"]);
                }

                if (forProblemStatementId != 0)
                {
                    problemStatement = MercuryApplication.ProblemStatementGet(forProblemStatementId, false);

                    if (problemStatement == null)
                    {
                        problemStatement = new Mercury.Client.Core.Individual.ProblemStatement(MercuryApplication);
                    }
                }

                else if (Request.QueryString["CopyProblemStatementId"] != null)
                {
                    forProblemStatementId = Int64.Parse(Request.QueryString["CopyProblemStatementId"]);

                    if (forProblemStatementId != 0)
                    {
                        problemStatement = MercuryApplication.ProblemStatementGet(forProblemStatementId, false);

                        if (problemStatement == null)
                        {
                            problemStatement = new Client.Core.Individual.ProblemStatement(MercuryApplication);
                        }

                        problemStatement.Id = 0;
                    }

                    else
                    {
                        problemStatement = new Client.Core.Individual.ProblemStatement(MercuryApplication);
                    }
                }

                else
                {
                    problemStatement = new Mercury.Client.Core.Individual.ProblemStatement(MercuryApplication);
                }

                InitializeAll();

                Session[SessionCachePrefix + "ProblemStatement"] = problemStatement;

                Session[SessionCachePrefix + "ProblemStatementUnmodified"] = problemStatement.Copy();

                #endregion
            } // Initial Page Load

            else   // Postback

            {
                problemStatement = (Mercury.Client.Core.Individual.ProblemStatement)Session[SessionCachePrefix + "ProblemStatement"];
            }

            ApplySecurity();

            if (!String.IsNullOrEmpty(problemStatement.Name))
            {
                Page.Title = "Problem Statement - " + problemStatement.Name;
            }
            else
            {
                Page.Title = "Problem Statement";
            }

            return;
        }
        //protected void ProblemStatementCategoryOnChange () {

        //    if (ProblemStatementCategorySelection.SelectedItem != null) {

        //        problemStatement.ProblemCategoryId = Convert.ToInt64 (ProblemStatementCategorySelection.SelectedValue);

        //        problemStatement.ProblemCategoryName = ProblemStatementCategorySelection.SelectedItem.Text;

        //    }

        //    else {

        //        problemStatement.ProblemCategoryId = 0;

        //        problemStatement.ProblemCategoryName = ProblemStatementCategorySelection.Text;

        //    }

        //    problemStatement.ProblemSubcategoryId = 0;

        //    problemStatement.ProblemSubcategoryName = String.Empty;


        //    ProblemStatementSubcategorySelection.SelectedValue = String.Empty;

        //    ProblemStatementSubcategorySelection.Text = String.Empty;


        //    InitializeClassification ();

        //    return;

        //}

        //protected void ProblemStatementCategorySelection_OnSelectedIndexChanged (Object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) {

        //    ProblemStatementCategoryOnChange ();

        //    return;

        //}

        //protected void ProblemStatementCategorySelection_OnTextChanged (Object sender, EventArgs e) {

        //    ProblemStatementCategoryOnChange ();

        //    return;

        //}

        #endregion


        #region Dialog Button Event Handlers

        protected Boolean ApplyChanges()
        {
            Boolean isModified = false;

            Boolean success = false;


            Mercury.Client.Core.Individual.ProblemStatement problemStatementUnmodified = (Mercury.Client.Core.Individual.ProblemStatement)Session[SessionCachePrefix + "ProblemStatementUnmodified"];

            if (problemStatementUnmodified.Id == 0)
            {
                isModified = true;
            }


            // CLASSIFICATION

            if (ProblemStatementDomainSelection.SelectedItem != null)
            {
                problemStatement.ProblemDomainId = Convert.ToInt64(ProblemStatementDomainSelection.SelectedItem.Value);
            }

            problemStatement.ProblemDomainName = ProblemStatementDomainSelection.Text.Trim();



            if (ProblemStatementClassSelection.SelectedItem != null)
            {
                problemStatement.ProblemClassId = Convert.ToInt64(ProblemStatementClassSelection.SelectedItem.Value);
            }

            problemStatement.ProblemClassName = ProblemStatementClassSelection.Text.Trim();


            //if (ProblemStatementCategorySelection.SelectedItem != null) {

            //    problemStatement.ProblemCategoryId = Convert.ToInt64 (ProblemStatementCategorySelection.SelectedItem.Value);

            //}

            //problemStatement.ProblemCategoryName = ProblemStatementCategorySelection.Text;


            //if (ProblemStatementSubcategorySelection.SelectedItem != null) {

            //    problemStatement.ProblemSubcategoryId = Convert.ToInt64 (ProblemStatementSubcategorySelection.SelectedItem.Value);

            //}

            //problemStatement.ProblemSubcategoryName = ProblemStatementSubcategorySelection.Text;



            problemStatement.Name = ProblemStatementName.Text.Trim();

            problemStatement.Description = ProblemStatementDescription.Text.Trim();

            problemStatement.DefiningCharacteristics = ProblemStatementDefiningCharacteristics.Text.Trim();

            problemStatement.RelatedFactors = ProblemStatementRelatedFactors.Text.Trim();

            problemStatement.Enabled = ProblemStatementEnabled.Checked;

            problemStatement.Visible = ProblemStatementVisible.Checked;


            if (ProblemStatementDefaultCarePlanSelection.SelectedItem != null)
            {
                problemStatement.DefaultCarePlanId = Convert.ToInt64(ProblemStatementDefaultCarePlanSelection.SelectedValue);
            }


            if (!isModified)
            {
                isModified = !problemStatement.IsEqual(problemStatementUnmodified);
            }

            if (isModified)
            {
                success = MercuryApplication.ProblemStatementSave(problemStatement);

                if (success)
                {
                    problemStatement = MercuryApplication.ProblemStatementGet(problemStatement.Id, false);

                    Session[SessionCachePrefix + "ProblemStatement"] = problemStatement;

                    Session[SessionCachePrefix + "ProblemStatementUnmodified"] = problemStatement.Copy();

                    SaveResponseLabel.Text = "Save Successful";

                    InitializeAll();
                }

                else
                {
                    SaveResponseLabel.Text = "Unable to Save.";

                    if (MercuryApplication.LastException != null)
                    {
                        SaveResponseLabel.Text = SaveResponseLabel.Text + " [" + MercuryApplication.LastException.Message + "]";
                    }

                    success = false;
                }
            }

            else
            {
                SaveResponseLabel.Text = "No Changes Detected."; success = true;
            }

            return(success);
        }