private HafModel GetHafModel(IEnumerable <KeyValuePair <long, List <long> > > keyValuePairs, IEnumerable <EventTest> eventTests, long eventId, long customerId, bool setChildQuestion, int versionNumber) { var questionsGroupByGroupName = _healthAssessmentRepository.GetAllQuestionGroupWithQuestion(); var dependencyRules = _haqDependencyRuleRepository.Get(); var genericQuestionIds = keyValuePairs.First(x => x.Key == 0).Value; IEnumerable <HealthAssessmentAnswer> answers = null; if (versionNumber > 0) { var archiveanswers = _healthAssessmentRepository.GetArchive(customerId, eventId, versionNumber); answers = archiveanswers.Select(aa => aa.HealthAssessmentAnswer).ToArray(); } else { answers = _healthAssessmentRepository.Get(customerId, eventId); } keyValuePairs = keyValuePairs.Where(x => x.Key > 0); var questions = questionsGroupByGroupName.Where(x => x.Questions != null).SelectMany(x => x.Questions); var questionHafModel = questions.Where( x => genericQuestionIds.Contains(x.Id) && (x.IsForFemale == null || x.IsForFemale == IsFemale)) .OrderBy(x => x.DisplaySequence) .ThenBy(x => x.Id) .Select( x => GetQuestion(x, dependencyRules.FirstOrDefault(d => d.QuestionId == x.Id), answers)) .ToList(); var genericModel = questionHafModel.Where(x => x.ParentQuestionId <= 0).ToArray(); var model = new HafModel { Name = string.Empty, Description = string.Empty, HafGroup = new HafQuestionGroup { Questions = setChildQuestion ? genericModel.Select(x => SetChildQuestions(x, questionHafModel.Where(c => c.ParentQuestionId == x.QuestoinId).ToArray(), questionHafModel.ToArray())) : questionHafModel }, HafTests = CreateTestLevelHafQuestion(keyValuePairs, eventTests, questionsGroupByGroupName.Where(x => x.Questions != null).ToArray(), dependencyRules, answers, setChildQuestion) }; long parentQuestionId = 0; var index = 0; foreach (var item in model.HafGroup.Questions.Where(x => x.ParentQuestionId > 0)) { if (parentQuestionId != item.ParentQuestionId) { index = 1; parentQuestionId = item.ParentQuestionId; } item.RelativeOrder = index++; } return(model); }
public HafModel FetchHealthAssessment([FromUri] HafFilter filter) { HafModel model; _logger.Info("Health Assessment (FetchHealthAssessment) CustomerId : " + filter.CustomerId); try { if (filter == null && filter.CustomerId <= 0 && filter.EventId <= 0) { model = new HafModel { IsSuccess = false, EventId = filter.EventId, CustomerId = filter.CustomerId }; } else { model = _customerHafQuestionService.Get(filter); model.IsSuccess = true; } } catch (Exception exception) { _logger.Error(string.Format("While fechinging health assessment exception {0}", exception.StackTrace)); model = new HafModel { IsSuccess = false }; } return(model); }