示例#1
0
        /// <summary>
        /// Load response value for question type date, number and text.
        /// </summary>
        /// <param name="question">The question that needs to be enabled or disabled</param>
        /// <returns>Response Value</returns>
        private string LoadSingleResponseValue(Question question)
        {
            string value = string.Empty;

            if (question.Responses.ToList().Any(x => x.QuestionId == question.QuestionId && x.QuestionnaireId == Questionnaire.QuestionnaireId))
            {
                var response = question.Responses.ToList().Single(x => x.QuestionId == question.QuestionId && x.QuestionnaireId == Questionnaire.QuestionnaireId);
                value = response.Value;
            }

            return value;
        }
示例#2
0
        private string DetermineQuestionStatus(Question question)
        {
            var returnValue = QuestionStatus.Active;

            if (question.DisplayLogic.IsNotNullOrEmpty())
            {
                var displayLogic = question.DisplayLogic;
                var questionCode = question.DisplayLogic.Split(' ')[0];

                var query = new QuestionByQuestionCode(questionCode);
                var parentCode = _repository.Find(query);

                if (parentCode != null)
                {
                    var parentResponses =
                        Questionnaire.Responses.Where(
                            x =>
                            x.QuestionnaireId == Questionnaire.QuestionnaireId && x.QuestionId == parentCode.QuestionId)
                            .Where(x => x.IsSelected == "True" || x.IsSelected == "_NA_");

                    foreach (var response in parentResponses)
                    {
                        var result = DisplayLogicEvaluator.Evaluate(questionCode, displayLogic, response.Value);
                        returnValue = result ? QuestionStatus.Disabled : QuestionStatus.Active;
                    }
                }
                else
                {
                    returnValue = QuestionStatus.Active;
                }
            }

            return returnValue;
        }
示例#3
0
        private IList<QuestionChoice> LoadQuestionChoices(Question question)
        {
            var questionChoices = new List<QuestionChoice>();
            var choices = question.AnswerChoices.OrderBy(x => x.AnswerChoiceId).ToList();

            List<Response> responses = question.Responses.ToList();
            /* Take care of checkbox, radiobutton, and dropdownlist type response */
            foreach (var choice in choices)
            {
                var result = responses.Where(x => x.QuestionId == choice.QuestionId && x.Value == choice.DisplayText && x.QuestionnaireId == Questionnaire.QuestionnaireId)
                                      .Select(x => new { x.IsSelected, x.Comment }).FirstOrDefault();

                var qc = new QuestionChoice();

                if (result != null)
                {
                    qc.Comment = result.Comment;
                    qc.SelectedInd = result.IsSelected;
                }
                qc.IsRequired = choice.Question.IsRequired;
                qc.DisplayText = choice.DisplayText;
                qc.Identifier = choice.AnswerChoiceId;

                questionChoices.Add(qc);
            }

            return questionChoices;
        }
示例#4
0
        private void AddToAnsnweredIds(Question question)
        {
            switch (question.InputType)
            {
                case QuestionInputType.Date:
                case QuestionInputType.Number:
                case QuestionInputType.Text:
                    {
                        var responses = question.Responses.Where(response => !string.IsNullOrEmpty(response.Value) && response.QuestionnaireId == Questionnaire.QuestionnaireId);

                        foreach (var response in responses)
                            if (!AnsweredQuestionIds.Contains(response.QuestionId.ToString(CultureInfo.InvariantCulture)))
                            {
                                AnsweredQuestionIds.Add(response.QuestionId.ToString(CultureInfo.InvariantCulture));
                                break;
                            }
                    }
                    break;

                default:
                    {
                        var responses = question.Responses.Where(response => response.IsSelected == "True" && response.QuestionnaireId == Questionnaire.QuestionnaireId);
                        foreach (var response in responses)
                        {
                            if (!AnsweredQuestionIds.Contains(response.QuestionId.ToString(CultureInfo.InvariantCulture)))
                            {
                                AnsweredQuestionIds.Add(response.QuestionId.ToString(CultureInfo.InvariantCulture));
                                //break;
                            }
                            /* Add comment box id to answer question id array */
                            if (string.IsNullOrEmpty(response.Comment) == false && response.Value == "Other")
                            {
                                if (AnsweredQuestionIds.Contains(response.QuestionId.ToString(CultureInfo.InvariantCulture) + "_Comment") == false)
                                {
                                    AnsweredQuestionIds.Add(response.QuestionId.ToString(CultureInfo.InvariantCulture) + "_Comment");
                                }
                            }
                        }

                        break;
                    }
            }
        }