public async Task <Tuple <string, JourneyViewModel> > JustToBeSafeFirstBuilder(JustToBeSafeViewModel model)
        {
            if (model.PathwayId != null)
            {
                model = await DoWorkPreviouslyDoneInQuestionBuilder(model); //todo refactor away
            }
            var identifiedModel = await BuildIdentifiedModel(model);

            var questionsJson = await _restfulHelper.GetAsync(_configuration.GetBusinessApiJustToBeSafePartOneUrl(identifiedModel.PathwayId));

            var questionsWithAnswers = JsonConvert.DeserializeObject <List <QuestionWithAnswers> >(questionsJson);

            if (!questionsWithAnswers.Any())
            {
                var journeyViewModel = new JourneyViewModel
                {
                    PathwayId         = identifiedModel.PathwayId,
                    PathwayNo         = identifiedModel.PathwayNo,
                    PathwayTitle      = identifiedModel.PathwayTitle,
                    DigitalTitle      = string.IsNullOrEmpty(identifiedModel.DigitalTitle) ? identifiedModel.PathwayTitle : identifiedModel.DigitalTitle,
                    UserInfo          = identifiedModel.UserInfo,
                    JourneyJson       = identifiedModel.JourneyJson,
                    State             = JsonConvert.DeserializeObject <Dictionary <string, string> >(identifiedModel.StateJson),
                    StateJson         = identifiedModel.StateJson,
                    CollectedKeywords = identifiedModel.CollectedKeywords,
                    Journey           = JsonConvert.DeserializeObject <Journey>(identifiedModel.JourneyJson),
                    SessionId         = model.SessionId,
                    JourneyId         = Guid.NewGuid(),
                    FilterServices    = model.FilterServices
                };
                var question = JsonConvert.DeserializeObject <QuestionWithAnswers>(await _restfulHelper.GetAsync(_configuration.GetBusinessApiFirstQuestionUrl(identifiedModel.PathwayId, identifiedModel.StateJson)));
                _mappingEngine.Mapper.Map(question, journeyViewModel);

                _userZoomDataBuilder.SetFieldsForQuestion(journeyViewModel);

                return(new Tuple <string, JourneyViewModel>("../Question/Question", journeyViewModel));
            }
            identifiedModel.Part           = 1;
            identifiedModel.JourneyId      = Guid.NewGuid();
            identifiedModel.Questions      = questionsWithAnswers;
            identifiedModel.QuestionsJson  = questionsJson;
            identifiedModel.JourneyJson    = string.IsNullOrEmpty(identifiedModel.JourneyJson) ? JsonConvert.SerializeObject(new Journey()) : identifiedModel.JourneyJson;
            identifiedModel.FilterServices = model.FilterServices;
            return(new Tuple <string, JourneyViewModel>("../JustToBeSafe/JustToBeSafe", identifiedModel));
        }
Ejemplo n.º 2
0
        public async Task <Tuple <string, QuestionViewModel> > JustToBeSafeFirstBuilder(JustToBeSafeViewModel model)
        {
            if (model.PathwayId != null)
            {
                model = await DoWorkPreviouslyDoneInQuestionBuilder(model); //todo refactor away
            }
            var identifiedModel = await BuildIdentifiedModel(model);

            var questionsWithAnswers = await _restClient.ExecuteAsync <IEnumerable <QuestionWithAnswers> >(new JsonRestRequest(_configuration.GetBusinessApiJustToBeSafePartOneUrl(identifiedModel.PathwayId), Method.GET));

            CheckResponse(questionsWithAnswers);

            if (!questionsWithAnswers.Data.Any())
            {
                var questionViewModel = new QuestionViewModel
                {
                    PathwayId          = identifiedModel.PathwayId,
                    PathwayNo          = identifiedModel.PathwayNo,
                    PathwayTitle       = identifiedModel.PathwayTitle,
                    PathwayTraumaType  = identifiedModel.PathwayTraumaType,
                    DigitalTitle       = string.IsNullOrEmpty(identifiedModel.DigitalTitle) ? identifiedModel.PathwayTitle : identifiedModel.DigitalTitle,
                    UserInfo           = identifiedModel.UserInfo,
                    JourneyJson        = identifiedModel.JourneyJson,
                    State              = JsonConvert.DeserializeObject <Dictionary <string, string> >(identifiedModel.StateJson),
                    StateJson          = identifiedModel.StateJson,
                    CollectedKeywords  = identifiedModel.CollectedKeywords,
                    Journey            = JsonConvert.DeserializeObject <Journey>(identifiedModel.JourneyJson),
                    SessionId          = model.SessionId,
                    JourneyId          = Guid.NewGuid(),
                    FilterServices     = model.FilterServices,
                    Campaign           = model.Campaign,
                    Source             = model.Source,
                    CurrentPostcode    = model.CurrentPostcode,
                    EntrySearchTerm    = model.EntrySearchTerm,
                    ViaGuidedSelection = model.ViaGuidedSelection,
                    StartParameter     = model.StartParameter
                };

                var question = await _restClient.ExecuteAsync <QuestionWithAnswers>(new JsonRestRequest(_configuration.GetBusinessApiFirstQuestionUrl(identifiedModel.PathwayId, identifiedModel.StateJson), Method.GET));

                CheckResponse(question);

                _mappingEngine.Mapper.Map(question.Data, questionViewModel);

                if (questionViewModel.IsViaGuidedSelection)
                {
                    _auditLogger.LogEvent(model, EventType.GuidedSelection, questionViewModel.PathwayTitle, "/GuidedSelection");
                }


                _userZoomDataBuilder.SetFieldsForQuestion(questionViewModel);
                if (questionViewModel.NodeType == NodeType.Page)
                {
                    // This replicates logic in ViewDeterminer so in future should ideally use that instead.
                    string viewName = "../Question/Page";
                    if (questionViewModel.PathwayNo.Equals("PC111"))
                    {
                        viewName = "../Question/Custom/NHSUKPage";
                    }
                    //replace placeholder for covid specific logic.
                    var covidPathways = await GetCovidPathways(model.UserInfo.Demography.Gender, new AgeCategory(model.UserInfo.Demography.Age));

                    questionViewModel.Content = PageCustomContent.ReplaceCovidPlaceHolderInPageContent(questionViewModel, covidPathways);
                    return(new Tuple <string, QuestionViewModel>(viewName, questionViewModel));
                }

                return(new Tuple <string, QuestionViewModel>("../Question/Question", questionViewModel));
            }
            identifiedModel.Part           = 1;
            identifiedModel.JourneyId      = Guid.NewGuid();
            identifiedModel.Questions      = questionsWithAnswers.Data.ToList();
            identifiedModel.QuestionsJson  = JsonConvert.SerializeObject(questionsWithAnswers.Data);
            identifiedModel.JourneyJson    = string.IsNullOrEmpty(identifiedModel.JourneyJson) ? JsonConvert.SerializeObject(new Journey()) : identifiedModel.JourneyJson;
            identifiedModel.FilterServices = model.FilterServices;
            return(new Tuple <string, QuestionViewModel>("../JustToBeSafe/JustToBeSafe", identifiedModel));
        }