Beispiel #1
0
        /// <summary>
        /// Shows the result.
        /// </summary>
        private void ShowResult(EQInventoryService.AssessmentResults result, Assessment assessment, bool isPrevious = false)
        {
            pnlInstructions.Visible = false;
            pnlQuestion.Visible     = false;
            pnlResult.Visible       = true;
            btnRetakeTest.Visible   = false;

            if (isPrevious)
            {
                ShowNotification("A more recent assessment request has been made but has not been taken. Displaying the most recently completed test.", NotificationBoxType.Info);
            }

            bool requiresRequest = assessment.AssessmentType.RequiresRequest;
            var  minDays         = assessment.AssessmentType.MinimumDaysToRetake;

            if (!_isQuerystringPersonKey && !requiresRequest && assessment.CompletedDateTime.HasValue && assessment.CompletedDateTime.Value.AddDays(minDays) <= RockDateTime.Now)
            {
                btnRetakeTest.Visible = true;
            }

            // Resolve the text field merge fields
            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, _targetPerson);

            if (_targetPerson != null)
            {
                _targetPerson.LoadAttributes();
                mergeFields.Add("Person", _targetPerson);

                // The five Mode scores
                mergeFields.Add("SelfAwareness", result.SelfAwareConstruct);
                mergeFields.Add("SelfRegulating", result.SelfRegulatingConstruct);
                mergeFields.Add("OthersAwareness", result.OtherAwarenessContruct);
                mergeFields.Add("OthersRegulating", result.OthersRegulatingConstruct);
                mergeFields.Add("EQinProblemSolving", result.EQ_ProblemSolvingScale);
                mergeFields.Add("EQUnderStress", result.EQ_UnderStressScale);
            }

            lResult.Text = GetAttributeValue(AttributeKey.ResultsMessage).ResolveMergeFields(mergeFields);
        }
        /// <summary>
        /// Shows the result.
        /// </summary>
        private void ShowResult(EQInventoryService.AssessmentResults result, Assessment assessment)
        {
            pnlInstructions.Visible = false;
            pnlQuestion.Visible     = false;
            pnlResult.Visible       = true;

            var allowRetakes = GetAttributeValue(AttributeKeys.AllowRetakes).AsBoolean();
            var minDays      = assessment.AssessmentType.MinimumDaysToRetake;

            if (!_isQuerystringPersonKey && allowRetakes && assessment.CompletedDateTime.HasValue && assessment.CompletedDateTime.Value.AddDays(minDays) <= RockDateTime.Now)
            {
                btnRetakeTest.Visible = true;
            }
            else
            {
                btnRetakeTest.Visible = false;
            }

            // Resolve the text field merge fields
            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, _targetPerson);

            if (_targetPerson != null)
            {
                _targetPerson.LoadAttributes();
                mergeFields.Add("Person", _targetPerson);

                // The five Mode scores
                mergeFields.Add("SelfAwareness", result.SelfAwareConstruct);
                mergeFields.Add("SelfRegulating", result.SelfRegulatingConstruct);
                mergeFields.Add("OthersAwareness", result.OtherAwarenessContruct);
                mergeFields.Add("OthersRegulating", result.OthersRegulatingConstruct);
                mergeFields.Add("EQinProblemSolving", result.EQ_ProblemSolvingScale);
                mergeFields.Add("EQUnderStress", result.EQ_UnderStressScale);
            }

            lResult.Text = GetAttributeValue(AttributeKeys.ResultsMessage).ResolveMergeFields(mergeFields);
        }
Beispiel #3
0
        /// <summary>
        /// Shows the assessment.
        /// A null value for _targetPerson is already handled in OnInit() so this method assumes there is a value
        /// </summary>
        private void ShowAssessment()
        {
            /*
             * 2020-01-09 - ETD
             * This block will either show the assessment results of the most recent assessment test or give the assessment test.
             * The following use cases are considered:
             * 1. If the assessment ID "0" was provided then create a new test for the current user. This covers user directed retakes.
             * 2. If the assessment ID was provided and is not "0"
             *  Note: The assessment results are stored on the person's attributes and are overwritten if the assessment is retaken. So past Assessments will not be loaded by this block.
             *  The test data is saved in the assessment table but would need to be recomputed, which may be a future feature.
             *  a. The assessment ID is ignored and the current person is used.
             *  b. If the assessment exists for the current person and is completed then show the results
             *  c. If the assessment exists for the current person and is pending then show the questions.
             *  d. If the assessment does not exist for the current person then nothing loads.
             * 3. If the assessment ID was not provided and the PersonKey was provided
             *  a. If there is only one test of the type
             *      1. If the assessment is completed show the results
             *      2. If the assessment is pending and the current person is the one assigned the test then show the questions.
             *      3. If the assessment is pending and the current person is not the one assigned then show a message that the test has not been completed.
             *  b. If more than one of type
             *      1. If the latest requested assessment is completed show the results.
             *      2. If the latest requested assessment is pending and the current person is the one assigned then show the questions.
             *      3. If the latest requested assessment is pending and the current person is not the one assigned the show the results of the last completed test.
             *      4. If the latest requested assessment is pending and the current person is not the one assigned and there are no previous completed assessments then show a message that the test has not been completed.
             * 4. If an assessment ID or PersonKey were not provided or are not valid then show an error message
             */

            var        rockContext    = new RockContext();
            var        assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.EQ.AsGuid());
            Assessment assessment     = null;
            Assessment previouslyCompletedAssessment = null;

            // A "0" value indicates that the block should create a new assessment instead of looking for an existing one, so keep assessment null. e.g. a user directed re-take
            if (_assessmentId != 0)
            {
                var assessments = new AssessmentService(rockContext)
                                  .Queryable()
                                  .AsNoTracking()
                                  .Where(a => a.PersonAlias != null &&
                                         a.PersonAlias.PersonId == _targetPerson.Id &&
                                         a.AssessmentTypeId == assessmentType.Id)
                                  .OrderByDescending(a => a.CompletedDateTime ?? a.RequestedDateTime)
                                  .ToList();

                if (_assessmentId == null && assessments.Count == 0)
                {
                    // For this to happen the user has to have never taken the assessment, the user isn't using a link with the assessment ID, AND they are arriving at the block directly rather than through the assessment list block.
                    // So treat this as a user directed take/retake.
                    _assessmentId = 0;
                }
                else
                {
                    if (assessments.Count > 0)
                    {
                        // If there are any results then pick the first one. If the assesement ID was specified then the query will only return one result
                        assessment = assessments[0];
                    }
                    if (assessments.Count > 1)
                    {
                        // If there are more than one result then we need to pick the right one (see developer note)
                        // If the most recent assessment is "Completed" then it is already set as the assessment and we can move on. Otherwise check if there are previoulsy completed assessments.
                        if (assessment.Status == AssessmentRequestStatus.Pending)
                        {
                            // If the most recent assessment is pending then check for a prior completed one
                            previouslyCompletedAssessment = assessments.Where(a => a.Status == AssessmentRequestStatus.Complete).FirstOrDefault();
                        }
                    }
                }
            }

            if (assessment == null)
            {
                // If assessment is null and _assessmentId = 0 this is user directed. If the type does not require a request then show instructions
                if (_assessmentId == 0 && !assessmentType.RequiresRequest)
                {
                    hfAssessmentId.SetValue(0);
                    ShowInstructions();
                }
                else
                {
                    // If assessment is null and _assessmentId != 0 or is 0 but the type does require a request then show requires request error
                    HidePanelsAndShowError("Sorry, this test requires a request from someone before it can be taken.");
                }

                return;
            }

            hfAssessmentId.SetValue(assessment.Id);

            // If assessment is completed show the results
            if (assessment.Status == AssessmentRequestStatus.Complete)
            {
                EQInventoryService.AssessmentResults savedScores = EQInventoryService.LoadSavedAssessmentResults(_targetPerson);
                ShowResult(savedScores, assessment);
                return;
            }

            if (assessment.Status == AssessmentRequestStatus.Pending)
            {
                if (_targetPerson.Id != CurrentPerson.Id)
                {
                    // If assessment is pending and the current person is not the one assigned the show previouslyCompletedAssessment results
                    if (previouslyCompletedAssessment != null)
                    {
                        EQInventoryService.AssessmentResults savedScores = EQInventoryService.LoadSavedAssessmentResults(_targetPerson);
                        ShowResult(savedScores, previouslyCompletedAssessment, true);
                        return;
                    }

                    // If assessment is pending and the current person is not the one assigned and previouslyCompletedAssessment is null show a message that the test has not been completed.
                    HidePanelsAndShowError(string.Format("{0} has not yet taken the {1} Assessment.", _targetPerson.FullName, assessmentType.Title));
                }
                else
                {
                    // If assessment is pending and the current person is the one assigned then show the questions
                    ShowInstructions();
                }

                return;
            }

            // This should never happen, if the block gets to this point then something is not right
            HidePanelsAndShowError("Unable to load assessment");
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Click event of the btnNext control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnNext_Click(object sender, EventArgs e)
        {
            int pageNumber = hfPageNo.ValueAsInt() + 1;

            GetResponse();

            LinkButton btn             = ( LinkButton )sender;
            string     commandArgument = btn.CommandArgument;

            var totalQuestion = pageNumber * QuestionCount;

            if ((_assessmentResponses.Count > totalQuestion && !_assessmentResponses.All(a => a.Response.HasValue)) || "Next".Equals(commandArgument))
            {
                BindRepeater(pageNumber);
            }
            else
            {
                EQInventoryService.AssessmentResults result = EQInventoryService.GetResult(_assessmentResponses.ToDictionary(a => a.Code, b => b.Response.Value));
                EQInventoryService.SaveAssessmentResults(_targetPerson, result);
                var rockContext = new RockContext();

                var        assessmentService = new AssessmentService(rockContext);
                Assessment assessment        = null;

                if (hfAssessmentId.ValueAsInt() != 0)
                {
                    assessment = assessmentService.Get(int.Parse(hfAssessmentId.Value));
                }

                if (assessment == null)
                {
                    var assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.EQ.AsGuid());
                    assessment = new Assessment()
                    {
                        AssessmentTypeId = assessmentType.Id,
                        PersonAliasId    = _targetPerson.PrimaryAliasId.Value
                    };
                    assessmentService.Add(assessment);
                }

                assessment.Status               = AssessmentRequestStatus.Complete;
                assessment.CompletedDateTime    = RockDateTime.Now;
                assessment.AssessmentResultData = new { Result = result.AssessmentData, TimeToTake = RockDateTime.Now.Subtract(StartDateTime).TotalSeconds }.ToJson();
                rockContext.SaveChanges();

                // Since we are rendering chart.js we have to register the script or reload the page.
                if (_assessmentId == 0)
                {
                    var removeParams = new List <string>
                    {
                        PageParameterKey.AssessmentId
                    };

                    NavigateToCurrentPageReferenceWithRemove(removeParams);
                }
                else
                {
                    this.NavigateToCurrentPageReference();
                }
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var        rockContext    = new RockContext();
                var        assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.EQ.AsGuid());
                Assessment assessment     = null;

                if (_targetPerson != null)
                {
                    var primaryAliasId = _targetPerson.PrimaryAliasId;

                    if (_assessmentId == 0)
                    {
                        // This indicates that the block should create a new assessment instead of looking for an existing one. e.g. a user directed re-take
                        assessment = null;
                    }
                    else
                    {
                        // Look for an existing pending or completed assessment.
                        assessment = new AssessmentService(rockContext)
                                     .Queryable()
                                     .Where(a => (_assessmentId.HasValue && a.Id == _assessmentId) || (a.PersonAliasId == primaryAliasId && a.AssessmentTypeId == assessmentType.Id))
                                     .OrderByDescending(a => a.CreatedDateTime)
                                     .FirstOrDefault();
                    }

                    if (assessment != null)
                    {
                        hfAssessmentId.SetValue(assessment.Id);
                    }
                    else
                    {
                        hfAssessmentId.SetValue(0);
                    }

                    if (assessment != null && assessment.Status == AssessmentRequestStatus.Complete)
                    {
                        EQInventoryService.AssessmentResults savedScores = EQInventoryService.LoadSavedAssessmentResults(_targetPerson);
                        ShowResult(savedScores, assessment);
                    }
                    else if ((assessment == null && !assessmentType.RequiresRequest) || (assessment != null && assessment.Status == AssessmentRequestStatus.Pending))
                    {
                        if (_targetPerson.Id != CurrentPerson.Id)
                        {
                            // If the current person is not the target person and there are no results to show then show a not taken message.
                            HidePanelsAndShowError(string.Format("{0} does not have results for the EQ Inventory Assessment.", _targetPerson.FullName));
                        }
                        else
                        {
                            ShowInstructions();
                        }
                    }
                    else
                    {
                        HidePanelsAndShowError("Sorry, this test requires a request from someone before it can be taken.");
                    }
                }
            }
            else
            {
                // Hide notification panels on every postback
                nbError.Visible = false;
            }
        }