Beispiel #1
0
        public virtual QuestionnaireOutcome Apply(Questionnaire questionnaire)
        {
            var questions = GetQuestions(questionnaire);

            var errorMessages = new Dictionary <string, ICollection <string> >();

            foreach (var question in questions)
            {
                var answer = questionnaire.Answers.SingleOrDefault(x => x.QuestionId == question.Id);
                if (answer != null)
                {
                    var errors = question.Validate(answer.Value);

                    if (errors.Count > 0)
                    {
                        errorMessages.Add(question.Id, errors);
                    }

                    if (question.Answer.HasConditional)
                    {
                        answer = questionnaire.Answers.SingleOrDefault(x => x.QuestionId == question.Answer.ConditionalQuestion.Id);
                        if (answer != null)
                        {
                            errors = question.Answer.ConditionalQuestion.Validate(answer.Value);

                            if (errors.Count > 0)
                            {
                                errorMessages.Add(question.Answer.ConditionalQuestion.Id, errors);
                            }
                        }
                    }
                }
            }

            if (errorMessages.Count > 0)
            {
                return(new QuestionnaireOutcome(questions, errorMessages));
            }

            if (questionnaire.Answers == null || questionnaire.Answers
                .Where(x => !x.QuestionId.Contains("."))
                .Select(x => x.QuestionId)
                .Distinct()
                .Count() < questions.Count)
            {
                return(new QuestionnaireOutcome(questions));
            }

            QuestionnaireOutcome questionnaireOutcome = ApplyRule(questionnaire);

            ApplyOutcomeToQuestionnaire(questionnaire, questionnaireOutcome);

            return(questionnaireOutcome);
        }
Beispiel #2
0
 protected abstract void ApplyOutcomeToQuestionnaire(Questionnaire questionnaire, QuestionnaireOutcome questionnaireOutcome);