public async Task <JsonResult <IEnumerable <CareAdvice> > > GetCareAdvice(int age, string gender, [FromUri] string markers)
        {
            markers = markers ?? string.Empty;
            var careAdvice = await _careAdviceService.GetCareAdvice(age, gender, markers.Split(','));

            return(Json(careAdvice));
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> GetCareAdvice(int age, string gender, [FromUri] string markers)
        {
            #if !DEBUG
            var cacheKey = string.Format("CareAdvice-{0}-{1}-{2}", age, gender, markers);

            var cacheValue = await _cacheManager.Read(cacheKey);

            if (cacheValue != null)
            {
                return(cacheValue.AsHttpResponse());
            }
            #endif

            markers = markers ?? string.Empty;
            var response = await _careAdviceService.GetCareAdvice(age, gender, markers.Split(',')).AsHttpResponse();

            #if !DEBUG
            _cacheManager.Set(cacheKey, response.Content.ReadAsStringAsync().Result);
            #endif
            return(response);
        }
        public async Task <IEnumerable <QuestionWithAnswers> > GetFullPathwayJourney(string traumaType, JourneyStep[] steps, string startingPathwayId, string dispositionCode, IDictionary <string, string> state)
        {
            var age               = GetAgeFromState(state);
            var gender            = GetGenderFromState(state);
            var moduleZeroJourney = await GetModuleZeroJourney(gender, age, traumaType);

            var pathwaysJourney = await GetPathwayJourney(steps, startingPathwayId, dispositionCode, gender, age);

            var filteredJourneySteps = NavigateReadNodeLogic(steps, pathwaysJourney.ToList(), state).ToArray();

            //keywords from pathways
            var pathwayKeywords        = filteredJourneySteps.Where(q => q.Labels.Contains("Pathway")).Select(q => q.Question.Keywords);
            var pathwayExcludeKeywords = filteredJourneySteps.Where(q => q.Labels.Contains("Pathway")).Select(q => q.Question.ExcludeKeywords);
            var keywords = _keywordCollector.CollectKeywords(pathwayKeywords, pathwayExcludeKeywords);

            // keywords from answers
            var journeySteps = filteredJourneySteps.Where(q => q.Answered != null).Select(q => new JourneyStep {
                Answer = q.Answered
            }).ToList();

            keywords = _keywordCollector.CollectKeywordsFromPreviousQuestion(keywords, journeySteps);

            var consolidatedKeywords = _keywordCollector.ConsolidateKeywords(keywords).ToArray();

            if (!consolidatedKeywords.Any())
            {
                return(moduleZeroJourney.Concat(filteredJourneySteps));
            }

            var careAdvice = await _careAdviceService.GetCareAdvice(new AgeCategory(age).Value, gender,
                                                                    consolidatedKeywords.Aggregate((i, j) => i + '|' + j), dispositionCode);

            var careAdviceAsQuestionWithAnswersListString = _careAdviceTransformer.AsQuestionWithAnswersList(careAdvice);
            var careAdviceAsQuestionWithAnswers           = JsonConvert.DeserializeObject <List <QuestionWithAnswers> >(careAdviceAsQuestionWithAnswersListString);

            return(moduleZeroJourney.Concat(filteredJourneySteps).Concat(careAdviceAsQuestionWithAnswers));
        }
 public async Task <HttpResponseMessage> GetCareAdvice(int age, string gender, [FromUri] string markers)
 {
     markers = markers ?? string.Empty;
     return(await _careAdviceService.GetCareAdvice(age, gender, markers.Split(',')).AsHttpResponse());
 }