protected void Page_Load(object sender, EventArgs e)
        {
            Int64 forCareOutcomeId = 0;


            if (MercuryApplication == null)
            {
                return;
            }

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

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


            if (!Page.IsPostBack)
            {
                #region Initial Page Load

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

                if (forCareOutcomeId != 0)
                {
                    careOutcome = MercuryApplication.CareOutcomeGet(forCareOutcomeId, false);

                    if (careOutcome == null)
                    {
                        careOutcome = new Mercury.Client.Core.Individual.CareOutcome(MercuryApplication);
                    }
                }

                else
                {
                    careOutcome = new Mercury.Client.Core.Individual.CareOutcome(MercuryApplication);
                }

                InitializeAll();

                Session[SessionCachePrefix + "CareOutcome"] = careOutcome;

                Session[SessionCachePrefix + "CareOutcomeUnmodified"] = careOutcome.Copy();

                #endregion
            } // Initial Page Load

            else   // Postback

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

            ApplySecurity();

            if (!String.IsNullOrEmpty(careOutcome.Name))
            {
                Page.Title = "Care Outcome - " + careOutcome.Name;
            }
            else
            {
                Page.Title = "Care Outcome";
            }

            return;
        }
        protected Boolean ApplyChanges()
        {
            Boolean isModified = false;

            Boolean success = false;


            Mercury.Client.Core.Individual.CareOutcome careOutcomeUnmodified = (Mercury.Client.Core.Individual.CareOutcome)Session[SessionCachePrefix + "CareOutcomeUnmodified"];

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


            careOutcome.Name = CareOutcomeName.Text.Trim();

            careOutcome.Description = CareOutcomeDescription.Text.Trim();

            careOutcome.Enabled = CareOutcomeEnabled.Checked;

            careOutcome.Visible = CareOutcomeVisible.Checked;

            if (!isModified)
            {
                isModified = !careOutcome.IsEqual(careOutcomeUnmodified);
            }

            if (isModified)
            {
                success = MercuryApplication.CareOutcomeSave(careOutcome);

                if (success)
                {
                    careOutcome = MercuryApplication.CareOutcomeGet(careOutcome.Id, false);

                    Session[SessionCachePrefix + "CareOutcome"] = careOutcome;

                    Session[SessionCachePrefix + "CareOutcomeUnmodified"] = careOutcome.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);
        }