public OnlineHealthAssessmentQuestionModel Get(OnlineHealthAssessmentQuestionModel model) { var tempCart = model.RequestValidationModel.TempCart; var eventId = tempCart.EventId.Value; var customerId = tempCart.CustomerId.Value; var customer = _customerRepository.GetCustomer(customerId); var iskynPurchased = IsTestPurchased(eventId, tempCart.CustomerId.Value, (long)TestType.Kyn); var isKynIntegrationEnabled = _eventPodRepository.IsKynIntegrationEnabled(eventId); model.HafModel = _customerHafQuestionService.Get(new HafFilter { CustomerId = tempCart.CustomerId.Value, EventId = tempCart.EventId.Value, SetChildQuestion = true, VersionNumber = 0 }); model.Height = customer.Height != null ? (int)customer.Height.TotalInches : 0; model.Weight = customer.Weight != null ? (int)customer.Weight.Pounds : 0; model.Race = (int)customer.Race; model.Waist = customer.Waist; model.IsKynPurchased = isKynIntegrationEnabled && iskynPurchased; 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); }
private bool CheckHafPrefilled(Customer customer, long eventid, int versionNumber = 0) { var model = _customerHafQuestionService.Get(new HafFilter { CustomerId = customer.CustomerId, EventId = eventid, SetChildQuestion = false, VersionNumber = versionNumber }); if (model == null) { return(false); } var questions = _healthAssessmentService.GetQuestions(eventid, customer.CustomerId); if (questions == null || !questions.Any()) { return(false); } var questionIds = questions.Select(x => x.Id).Distinct(); var hafQuestions = new List <HafQuestion>(); if (model.HafGroup != null) { hafQuestions.AddRange(model.HafGroup.Questions.ToList()); } if (model.HafTests.Any()) { hafQuestions.AddRange(model.HafTests.SelectMany(x => x.HafQuestionGroups.SelectMany(q => q.Questions)).ToList()); } if (!hafQuestions.Any()) { return(false); } if (customer.Gender != Gender.Female) { hafQuestions = hafQuestions.Where(x => !_womenOnlyQuestionIds.Contains(x.QuestoinId) && x.QuestoinId != 100).ToList(); } var hafNotDependent = hafQuestions.Where(x => x.DependentQuestionId == 0).ToList(); var isPrefilled = !hafNotDependent.Any(x => questionIds.Contains(x.QuestoinId) && !_insuranceQuestoin.Contains(x.QuestoinId) && !_excludeQuestion.Contains(x.QuestoinId) && string.IsNullOrEmpty(x.Answer) && x.ControlType == (long)DisplayControlType.Radio); //var temp = hafNotDependent.Where(x => questionIds.Contains(x.QuestoinId) && !_insuranceQuestoin.Contains(x.QuestoinId) && string.IsNullOrEmpty(x.Answer) && x.ControlType == (long)DisplayControlType.Radio).Select(x => x).ToArray(); if (isPrefilled) { var hafDependent = hafQuestions.Where(x => questionIds.Contains(x.QuestoinId) && x.DependentQuestionId > 0 && !_insuranceQuestoin.Contains(x.DependentQuestionId) && !_excludeQuestion.Contains(x.QuestoinId)).ToList(); foreach (var hafQuestion in hafDependent) { var dependentAnswer = hafQuestions.FirstOrDefault(h => h.QuestoinId == hafQuestion.DependentQuestionId && h.Answer.ToLower() == hafQuestion.DependencyRule.ToLower()); if (dependentAnswer != null) { if (_yesNoDependencyQuestion.Contains(dependentAnswer.QuestoinId)) { var allDependentQuestions = hafQuestions.Where(h => h.DependentQuestionId == hafQuestion.DependentQuestionId); allDependentQuestions = allDependentQuestions.Where(h => !string.IsNullOrEmpty(h.Answer)); if (!allDependentQuestions.Any()) { isPrefilled = false; break; } } else if (string.IsNullOrEmpty(hafQuestion.Answer) && hafQuestion.ControlType == (long)DisplayControlType.Radio) { isPrefilled = false; break; } else if (hafQuestion.ControlType == (long)DisplayControlType.CheckBox) { var allDependentQuestions = hafQuestions.Where(h => h.DependentQuestionId == hafQuestion.DependentQuestionId && hafQuestion.ControlType == (long)DisplayControlType.CheckBox); allDependentQuestions = allDependentQuestions.Where(h => !string.IsNullOrEmpty(h.Answer)); if (!allDependentQuestions.Any()) { isPrefilled = false; break; } } } } } return(isPrefilled); }