public void should_return_a_QuestionWithAnswer_Answer_Title_Uppercase()
        {
            //Arrange
            QuestionWithAnswers questionWithAnswers =

                new QuestionWithAnswers()
            {
                Question = new Question(),
                Answers  = new List <Answer>()
                {
                    new Answer()
                    {
                        Title = "title",
                        SymptomDiscriminator = "SymptomDiscriminatorCode"
                    }
                },
                Labels = new List <string>()
                {
                    "Label1"
                }
            };

            //Act
            var resultQuestionWithAnswers = QuestionTransformer.AsQuestionWithAnswers(questionWithAnswers);

            //Assert
            Assert.That(resultQuestionWithAnswers.Answers[0].Title, Is.EqualTo("Title"));
        }
        public void Collect_QuestionWithAnswers_with_symptonDiscriminator_returns_symptomDiscriminator_Test()
        {
            var testViewModel       = new JourneyViewModel();
            var questionWithAnswers = new QuestionWithAnswers()
            {
                Answered = new Answer()
                {
                    Order = 0, Title = "Yes", SymptomDiscriminator = TEST_SD_CODE
                },
                Answers = new List <Answer>()
                {
                    new Answer()
                    {
                        Order = 0, Title = "Yes"
                    }, new Answer()
                    {
                        Order = 1, Title = "No"
                    }
                },
                Question = new Question()
                {
                    Order = "0", Title = "Test Question"
                }
            };

            _symptomDiscriminatorCollector.Collect(questionWithAnswers, testViewModel);
            Assert.AreEqual(TEST_SD_CODE, testViewModel.SymptomDiscriminatorCode);
        }
        public JourneyViewModel MapJourneyViewModel(QuestionViewModel model, QuestionWithAnswers nextNode)
        {
            model.ProgressState();

            model.Journey.Steps.Add(model.ToStep());
            model.ResetAnswerInputValue();
            if (!string.IsNullOrEmpty(nextNode.NonQuestionKeywords))
            {
                model.Journey.Steps.Last().Answer.Keywords += "|" + nextNode.NonQuestionKeywords;
            }
            if (!string.IsNullOrEmpty(nextNode.NonQuestionExcludeKeywords))
            {
                model.Journey.Steps.Last().Answer.ExcludeKeywords += "|" + nextNode.NonQuestionExcludeKeywords;
            }
            model.JourneyJson = JsonConvert.SerializeObject(model.Journey);

            var answer = JsonConvert.DeserializeObject <Answer>(model.SelectedAnswer);

            if (nextNode.Labels.First() == "Outcome")
            {
                answer.Keywords        += "|" + nextNode.NonQuestionKeywords;
                answer.ExcludeKeywords += "|" + nextNode.NonQuestionExcludeKeywords;
            }
            _symptomDiscriminatorCollector.Collect(nextNode, model);
            var journeyViewModel = _keywordCollector.Collect(answer, model);

            journeyViewModel = _mappingEngine.Mapper.Map(nextNode, journeyViewModel);
            return(journeyViewModel);
        }
        public async Task <JourneyViewModel> Build(QuestionViewModel model, QuestionWithAnswers nextNode)
        {
            var journeyViewModel = MapJourneyViewModel(model, nextNode);

            switch (journeyViewModel.NodeType)
            {
            case NodeType.Outcome:
                var outcome = _mappingEngine.Mapper.Map <OutcomeViewModel>(journeyViewModel);
                outcome.UserInfo.CurrentAddress.IsInPilotArea =
                    _postCodeAllowedValidator.IsAllowedPostcode(model.CurrentPostcode) == PostcodeValidatorResponse.InPathwaysArea;
                return(await _outcomeViewModelBuilder.DispositionBuilder(outcome));

            case NodeType.Pathway:
                var jtbs = _mappingEngine.Mapper.Map <JustToBeSafeViewModel>(journeyViewModel);
                return((await _justToBeSafeFirstViewModelBuilder.JustToBeSafeFirstBuilder(jtbs))
                       .Item2); //todo refactor tuple away

            case NodeType.DeadEndJump:
                var deadEndJump = _mappingEngine.Mapper.Map <OutcomeViewModel>(journeyViewModel);
                return(await _outcomeViewModelBuilder.DeadEndJumpBuilder(deadEndJump));

            case NodeType.PathwaySelectionJump:
                var pathwaySelectionJump = _mappingEngine.Mapper.Map <OutcomeViewModel>(journeyViewModel);
                return(await _outcomeViewModelBuilder.PathwaySelectionJumpBuilder(pathwaySelectionJump));
            }

            return(model);
        }
        public JourneyViewModel BuildPreviousQuestion(QuestionWithAnswers lastStep, QuestionViewModel model)
        {
            model.RemoveLastStep();

            model.CollectedKeywords = _keywordCollector.CollectKeywordsFromPreviousQuestion(model.CollectedKeywords,
                                                                                            model.Journey.Steps);

            return(_mappingEngine.Mapper.Map(lastStep, model));
        }
        public void Collect(QuestionWithAnswers quesionWithAnswers, JourneyViewModel exitingJourneyModel)
        {
            if (quesionWithAnswers.Answered == null)
            {
                return;
            }

            Collect(quesionWithAnswers.Answered, exitingJourneyModel);
        }
        public NodeDetailsViewModel BuildNodeDetails(QuestionWithAnswers nextNode)
        {
            var outcomeGroup = _mappingEngine.Mapper.Map <OutcomeGroup>(nextNode);
            var nodeType     = _mappingEngine.Mapper.Map <NodeType>(nextNode);

            return(new NodeDetailsViewModel()
            {
                OutcomeGroup = outcomeGroup, NodeType = nodeType
            });
        }
Beispiel #8
0
        public void CreateQuestion(int questionnaireNumber, int questionNumber, string question, List <string> answers, short correctAnswer)
        {
            StreamWriter        streamWriter       = new StreamWriter(@"...\\...\\...\\Questionnaires\\Questionnary " + questionnaireNumber + @"\\Question " + questionNumber + ".txt");
            QuestionWithAnswers questionWithAnswer = new QuestionWithAnswers(question, answers, correctAnswer);

            using (streamWriter)
            {
                streamWriter.WriteLine(questionWithAnswer.ToStringWithCorrectAnswer());
            }
        }
        public JsonResult GetAnswersAndQuestion(int choosenAnswerId)
        {
            QuestionWithAnswers questionWithAnswers = _questionService.GetQuestionWithAnswersById(choosenAnswerId);

            if (questionWithAnswers == null)
            {
                return(null);
            }
            return(Json(questionWithAnswers, JsonRequestBehavior.AllowGet));
        }
Beispiel #10
0
        private void AddQuestionWithAnswer()
        {
            if (!string.IsNullOrWhiteSpace(_currentQuestion) && !string.IsNullOrWhiteSpace(_currentAnswer))
            {
                _currentAnswer += $"\\n\\nIf you need more help, then try my [Help center]({KnowledgebaseUrl.TrimEnd(new[] { '/' })}/{Name}) to learn more about what I can do.";

                QuestionWithAnswers.Add(new QuestionWithAnswer {
                    Question = _currentQuestion, Answer = _currentAnswer.Trim()
                });
            }
        }
 public QuestionWithAnswersBuilder(string questionId, string questionTitle)
 {
     _mockQuestionWithAnswers = new QuestionWithAnswers()
     {
         Labels = new List <string>()
         {
             "Question"
         }, Question = new Question()
         {
             Id = questionId, QuestionNo = "TX" + questionId, Title = questionTitle
         }
     };
 }
        public IHttpActionResult GetQuestionWithAnswer(int _id)
        {
            QuestionWithAnswers question = _questionService.GetQuestionWithAnswersById(_id);

            if (question == null)
            {
                return(BadRequest("The entity could not be found by id"));
            }
            else
            {
                return(Ok(question));
            }
        }
Beispiel #13
0
        private static OutcomeGroup BuildOutcomeGroup(QuestionWithAnswers questionWithAnswers)
        {
            var mappedOutcomeGroup = new OutcomeGroup();

            if (questionWithAnswers.Group != null)
            {
                mappedOutcomeGroup = questionWithAnswers.Group;
                //this needs to be mapped better, ultimately this should be data driven from data layers so the above line is all that's needed.
                var outcomeGroup = OutcomeGroup.OutcomeGroups[questionWithAnswers.Group.Id];
                mappedOutcomeGroup.Label = outcomeGroup.Label;
                mappedOutcomeGroup.ITK   = outcomeGroup.ITK;
            }
            return(mappedOutcomeGroup);
        }
        public List <QuestionWithAnswers> GetQuestionAnswers(SqlConnection conn = null)
        {
            List <QuestionWithAnswers> questionsWithAnswers = new List <QuestionWithAnswers>();

            try
            {
                bool nullConnection = false;
                QuestionWithAnswers questionAnswer = null;
                UtilitiesClass.CreateConnection(ref nullConnection, ref conn, base.GetConnectionString());

                using (var cmd = new SqlCommand("sp_getQuestionAnswers", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    if (nullConnection)
                    {
                        conn.Open();
                    }

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            questionAnswer = new QuestionWithAnswers
                            {
                                QuestionID = DataUtil.GetDataReaderValue <int>("QuestionID", reader),
                                AnswerID   = DataUtil.GetDataReaderValue <int>("AnswerID", reader),
                                Correct    = DataUtil.GetDataReaderValue <bool>("Correct", reader)
                            };

                            questionsWithAnswers.Add(questionAnswer);
                        }
                    }

                    if (conn.State == ConnectionState.Open && nullConnection)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("GetQuestionAnswers() error.", e);
            }

            return(questionsWithAnswers);
        }
        public async Task <JourneyViewModel> Build(JourneyViewModel model, QuestionWithAnswers nextNode)
        {
            model.ProgressState();

            model.Journey.Steps.Add(model.ToStep());

            if (!string.IsNullOrEmpty(nextNode.NonQuestionKeywords))
            {
                model.Journey.Steps.Last().Answer.Keywords += "|" + nextNode.NonQuestionKeywords;
            }
            if (!string.IsNullOrEmpty(nextNode.NonQuestionExcludeKeywords))
            {
                model.Journey.Steps.Last().Answer.ExcludeKeywords += "|" + nextNode.NonQuestionExcludeKeywords;
            }
            model.JourneyJson = JsonConvert.SerializeObject(model.Journey);

            var answer = JsonConvert.DeserializeObject <Answer>(model.SelectedAnswer);

            _symptomDiscriminatorCollector.Collect(nextNode, model);
            model = _keywordCollector.Collect(answer, model);

            model = _mappingEngine.Mapper.Map(nextNode, model);

            switch (model.NodeType)
            {
            case NodeType.Outcome:
                var outcome = _mappingEngine.Mapper.Map <OutcomeViewModel>(model);
                return(await _outcomeViewModelBuilder.DispositionBuilder(outcome));

            case NodeType.Pathway:
                var jtbs = _mappingEngine.Mapper.Map <JustToBeSafeViewModel>(model);
                return((await _justToBeSafeFirstViewModelBuilder.JustToBeSafeFirstBuilder(jtbs)).Item2);    //todo refactor tuple away

            case NodeType.DeadEndJump:
                var deadEndJump = _mappingEngine.Mapper.Map <OutcomeViewModel>(model);
                return(await _outcomeViewModelBuilder.DeadEndJumpBuilder(deadEndJump));

            case NodeType.PathwaySelectionJump:
                var pathwaySelectionJump = _mappingEngine.Mapper.Map <OutcomeViewModel>(model);
                return(await _outcomeViewModelBuilder.PathwaySelectionJumpBuilder(pathwaySelectionJump));
            }

            return(model);
        }
Beispiel #16
0
        public async void should_return_next_question()
        {
            //Arrange

            QuestionWithAnswers questionWithAnswers = new QuestionWithAnswers();

            var answer = "answer";
            var id     = "qId1";

            _questionRepository.Setup(x => x.GetNextQuestion(id, answer)).Returns(Task.FromResult(questionWithAnswers));


            //Act
            var result = await _sut.GetNextQuestion(id, answer);

            //Assert
            _questionRepository.Verify(x => x.GetNextQuestion(id, answer), Times.Once);
            Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        }
        public async Task <JourneyViewModel> Build(QuestionViewModel model, QuestionWithAnswers nextNode)
        {
            var journeyViewModel = MapJourneyViewModel(model, nextNode);

            switch (journeyViewModel.NodeType)
            {
            case NodeType.Outcome:
                if (journeyViewModel.OutcomeGroup.Id.Equals("111_Search_Jump"))
                {
                    return(_mappingEngine.Mapper.Map <SearchJourneyViewModel>(journeyViewModel));
                }

                if (journeyViewModel.OutcomeGroup.IsSendSMSVerify)
                {
                    return(_outcomeViewModelBuilder.SendSmsVerifyDetailsBuilder(journeyViewModel,
                                                                                model.SelectedAnswer));
                }

                if (journeyViewModel.OutcomeGroup.IsSendSMS)
                {
                    return(_outcomeViewModelBuilder.SendSmsDetailsBuilder(journeyViewModel));
                }

                var outcome = _mappingEngine.Mapper.Map <OutcomeViewModel>(journeyViewModel);
                var postcodeValidatorRepsonse = _postCodeAllowedValidator.IsAllowedPostcode(outcome.CurrentPostcode);
                return(await _outcomeViewModelBuilder.DispositionBuilder(outcome));

            case NodeType.Pathway:
                var jtbs = _mappingEngine.Mapper.Map <JustToBeSafeViewModel>(journeyViewModel);
                return((await _justToBeSafeFirstViewModelBuilder.JustToBeSafeFirstBuilder(jtbs))
                       .Item2); //todo refactor tuple away

            case NodeType.DeadEndJump:
                var deadEndJump = _mappingEngine.Mapper.Map <OutcomeViewModel>(journeyViewModel);
                return(await _outcomeViewModelBuilder.DeadEndJumpBuilder(deadEndJump));

            case NodeType.PathwaySelectionJump:
                var pathwaySelectionJump = _mappingEngine.Mapper.Map <OutcomeViewModel>(journeyViewModel);
                return(await _outcomeViewModelBuilder.PathwaySelectionJumpBuilder(pathwaySelectionJump));
            }

            return(model);
        }
        public async void read_state_contains_system_variables()
        {
            var set = new QuestionWithAnswers()
            {
                Question = new Question {
                    Title = "READ_STATE"
                },
                Labels = new[]
                {
                    "Read"
                },
            };
            var question = new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new[]
                {
                    "Question"
                },
            };
            var answers = new[] { new Answer {
                                      Title = "readstate"
                                  }, };

            _questionService.Setup(x => x.GetFirstQuestion(It.IsAny <string>())).Returns(Task.FromResult(set));
            _questionService.Setup(x => x.GetAnswersForQuestion(It.IsAny <string>())).Returns(Task.FromResult(answers));
            _questionService.Setup(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(question));
            _answersForNodeBuilder.Setup(x => x.SelectAnswer(It.IsAny <IEnumerable <Answer> >(), It.IsAny <string>())).Returns(new Answer {
                Title = "readstate"
            });

            _sut = new QuestionController(_questionService.Object, new QuestionTransformer(), _answersForNodeBuilder.Object);
            var result = await _sut.GetFirstQuestion(It.IsAny <string>(), "{\"PATIENT_AGE\":\"24\",\"PATIENT_GENDER\":\"M\",\"READ_STATE\":\"readstate\"}");

            var node = result.Content;

            Assert.IsTrue(node.State.ContainsKey("READ_STATE"));
            Assert.AreEqual(node.State["READ_STATE"], "readstate");
            Assert.IsTrue(node.State.ContainsKey("SYSTEM_ONLINE"));
            Assert.AreEqual(node.State["SYSTEM_ONLINE"], "online");
            Assert.IsTrue(node.State.ContainsKey("SYSTEM_MERS"));
        }
        public void should_return_Question_With_Dead_End()
        {
            //Arrange
            QuestionWithAnswers questionWithAnswers =

                new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new List <string>()
                {
                    "DeadEndJump"
                }
            };

            //Act
            var resultQuestionWithDeadEnd = QuestionTransformer.AsQuestionWithDeadEnd(questionWithAnswers);

            //Assert
            Assert.That(resultQuestionWithDeadEnd.Labels.First(), Is.EqualTo("DeadEndJump"));
        }
        public async void should_return_a_question_with_answers()
        {
            var question = new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new[]
                {
                    "Question"
                },
                State = new Dictionary <string, string>()
            };

            _questionService.Setup(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(question));

            _questionTransformer.Setup(x => x.AsQuestionWithAnswers(It.IsAny <QuestionWithAnswers>())).Returns(question);

            var result = await _sut.GetNextNode("1", NodeType.Question, "2", "", "yes");

            _questionService.Verify(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            Assert.IsInstanceOf <QuestionWithAnswers>(result.Content);
        }
        public void FromQuestionToJourneyViewModelConverter_FromQuestionWithAnswersToJourneyViewModelConverter_Test()
        {
            var questionsWithAnswers = new QuestionWithAnswers()
            {
                Answered = new Answer()
                {
                    Title = "No", Order = 3
                },
                Answers = new List <Answer>()
                {
                    new Answer()
                    {
                        Title = "test answer1", Order = 1
                    }
                    , new Answer()
                    {
                        Title = "test answer2", Order = 2
                    }
                    , new Answer()
                    {
                        Title = "test answer3", Order = 3
                    }
                },
                Question = new Question()
                {
                    Title = TEST_QUESTION_TITLE, Id = TEST_QUESTION_ID, Rationale = TEST_QUESTION_RATIONALE, QuestionNo = TEST_QUESTION_NO
                },
                Labels = new List <string>()
                {
                    "Question"
                }
            };

            var result =
                Mapper.Map <QuestionWithAnswers, JourneyViewModel>(
                    questionsWithAnswers);

            AssertValidModel(result);
        }
        public JourneyViewModel BuildPreviousQuestion(QuestionWithAnswers lastStep, QuestionViewModel model)
        {
            //TODO Check whether this is an appropriate test - should the code apply more broadly than just this pathway
            if (!string.IsNullOrWhiteSpace(model.DigitalTitle) && model.DigitalTitle.ToLower() == "sms service pathway")
            {
                var lastRecordedStep = model.Journey.Steps.LastOrDefault();
                if (lastRecordedStep.QuestionType == QuestionType.Telephone ||
                    lastRecordedStep.QuestionType == QuestionType.Integer)
                {
                    model.AnswerInputValue = lastRecordedStep.AnswerInputValue;
                }
            }

            model.RemoveLastStep();



            model.CollectedKeywords = _keywordCollector.CollectKeywordsFromPreviousQuestion(model.CollectedKeywords,
                                                                                            model.Journey.Steps);

            return(_mappingEngine.Mapper.Map(lastStep, model));
        }
Beispiel #23
0
        public async void should_return_a_question_with_answers()
        {
            var question = new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new[]
                {
                    "Question"
                },
                State = new Dictionary <string, string>()
            };
            var json = JsonConvert.SerializeObject(question);

            _questionService.Setup(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(json.AsHttpResponse()));

            _questionTransformer.Setup(x => x.AsQuestionWithAnswers(It.IsAny <string>())).Returns(json);

            var result = await _sut.GetNextNode("1", "2", "", "yes");

            _questionService.Verify(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            Assert.IsInstanceOf <QuestionWithAnswers>(JsonConvert.DeserializeObject <QuestionWithAnswers>(await result.Content.ReadAsStringAsync()));
        }
        public async void should_return_a_question_with_dead_end()
        {
            var question = new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new[]
                {
                    "DeadEndJump"
                },
                State = new Dictionary <string, string>()
            };

            _questionService.Setup(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(question));

            //_questionTransformer.Setup(x => x.AsQuestionWithDeadEnd(It.IsAny<QuestionWithAnswers>())).Returns(question);

            var result = await _sut.GetNextNode("1", NodeType.Question, "2", "", "yes");

            _questionService.Verify(x => x.GetNextQuestion(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            //Assert.IsInstanceOf<QuestionWithDeadEnd>(JsonConvert.DeserializeObject<QuestionWithDeadEnd>(await result.Content.ReadAsStringAsync()));
            Assert.IsTrue(result.Content.Labels.Contains("DeadEndJump"));
        }
        public async void question_state_contains_system_variables()
        {
            var question = new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new[]
                {
                    "Question"
                },
            };

            _questionService.Setup(x => x.GetFirstQuestion(It.IsAny <string>())).Returns(Task.FromResult(question));
            _questionTransformer.Setup(x => x.AsQuestionWithAnswers(It.IsAny <QuestionWithAnswers>())).Returns(question);

            var result = await _sut.GetFirstQuestion(It.IsAny <string>(), "{\"PATIENT_AGE\":\"24\",\"PATIENT_GENDER\":\"M\"}");

            var node = result.Content;

            Assert.IsTrue(node.State.ContainsKey("SYSTEM_ONLINE"));
            Assert.AreEqual(node.State["SYSTEM_ONLINE"], "online");
            Assert.IsTrue(node.State.ContainsKey("SYSTEM_MERS"));
        }
        public void should_return_Question_With_Dead_End()
        {
            //Arrange
            QuestionWithAnswers questionWithAnswers =

                new QuestionWithAnswers()
            {
                Question = new Question(),
                Labels   = new List <string>()
                {
                    "DeadEndJump"
                }
            };

            var json = JsonConvert.SerializeObject(questionWithAnswers);

            //Act
            var result = QuestionTransformer.AsQuestionWithDeadEnd(json);
            var resultQuestionWithDeadEnd = JsonConvert.DeserializeObject <QuestionWithDeadEnd>(result);

            //Assert
            Assert.IsInstanceOf <QuestionWithDeadEnd>(resultQuestionWithDeadEnd);
        }
Beispiel #27
0
 private static NodeType BuildNodeType(QuestionWithAnswers questionWithAnswers)
 {
     return((NodeType)Enum.Parse(typeof(NodeType), questionWithAnswers.Labels.FirstOrDefault()));
 }
Beispiel #28
0
        private static JourneyViewModel BuildJourneyViewModel(JourneyViewModel modelToPopulate, QuestionWithAnswers questionWithAnswers)
        {
            var journeyViewModel = modelToPopulate;

            if (journeyViewModel == null)
            {
                journeyViewModel = new JourneyViewModel();
            }

            if (questionWithAnswers == null)
            {
                return(journeyViewModel);
            }

            if (questionWithAnswers.Labels.Any())
            {
                journeyViewModel.NodeType = BuildNodeType(questionWithAnswers);
            }

            if (journeyViewModel.NodeType == NodeType.NotFound)
            {
                return(journeyViewModel);
            }

            journeyViewModel.Id                     = questionWithAnswers.Question.Id;
            journeyViewModel.Title                  = questionWithAnswers.Question.Title;
            journeyViewModel.TimeFrameText          = questionWithAnswers.Question.TimeFrameText;
            journeyViewModel.TimeFrameMinutes       = questionWithAnswers.Question.TimeFrame;
            journeyViewModel.WaitTimeText           = questionWithAnswers.Question.WaitTimeText;
            journeyViewModel.DispositionUrgencyText = questionWithAnswers.Question.DispositionUrgencyText;
            journeyViewModel.Content                = questionWithAnswers.Question.Content;
            journeyViewModel.NextButtonText         = string.IsNullOrEmpty(questionWithAnswers.Question.NextButtonText) ? "Next question" : questionWithAnswers.Question.NextButtonText;
            var questionAndBullets = questionWithAnswers.Question.TitleWithBullets();

            journeyViewModel.TitleWithoutBullets = questionAndBullets.Item1;
            journeyViewModel.Bullets             = questionAndBullets.Item2;
            journeyViewModel.QuestionType        = questionWithAnswers.Question.QuestionType;
            journeyViewModel.Answers             = questionWithAnswers.Answers ?? Enumerable.Empty <Answer>().ToList();
            journeyViewModel.QuestionNo          = questionWithAnswers.Question.QuestionNo;
            journeyViewModel.Rationale           = questionWithAnswers.Question.Rationale;

            journeyViewModel.OutcomeGroup = BuildOutcomeGroup(questionWithAnswers);

            if (questionWithAnswers.State != null)
            {
                journeyViewModel.State     = questionWithAnswers.State;
                journeyViewModel.StateJson = JsonConvert.SerializeObject(questionWithAnswers.State);
            }
            return(journeyViewModel);
        }
        public async Task <Tuple <string, JourneyViewModel> > BuildNextAction(List <QuestionWithAnswers> questions, Journey journey, JustToBeSafeViewModel model, Answer selectedAnswer, QuestionWithAnswers selectedQuestion, string questionsJson)
        {
            if (!questions.Any())
            {
                journey.Steps = journey.Steps.Where(step => step.QuestionId != model.SelectedQuestionId).ToList();
                var journeyViewModel = new JourneyViewModel
                {
                    PathwayId            = model.PathwayId,
                    PathwayNo            = model.PathwayNo,
                    PathwayTitle         = model.PathwayTitle,
                    SymptomDiscriminator = model.SymptomDiscriminator,
                    UserInfo             = model.UserInfo,
                    JourneyJson          = JsonConvert.SerializeObject(journey),
                    SelectedAnswer       = JsonConvert.SerializeObject(selectedAnswer),
                };

                _mappingEngine.Map(selectedQuestion, journeyViewModel);
                journeyViewModel = _mappingEngine.Map(selectedAnswer, journeyViewModel);

                return(await _questionViewModelBuilder.BuildQuestion(journeyViewModel));
            }

            if (questions.Count() == 1)
            {
                var journeyViewModel = new JourneyViewModel
                {
                    PathwayId    = model.PathwayId,
                    PathwayNo    = model.PathwayNo,
                    PathwayTitle = model.PathwayTitle,
                    UserInfo     = model.UserInfo,
                    JourneyJson  = JsonConvert.SerializeObject(journey),
                };

                _mappingEngine.Map(questions.First(), journeyViewModel);
                journeyViewModel = _mappingEngine.Map(selectedAnswer, journeyViewModel);

                return(new Tuple <string, JourneyViewModel>("../Question/Question", journeyViewModel));
            }

            var viewModel = new JustToBeSafeViewModel
            {
                PathwayId            = model.PathwayId,
                PathwayNo            = model.PathwayNo,
                PathwayTitle         = model.PathwayTitle,
                JourneyJson          = JsonConvert.SerializeObject(journey),
                SymptomDiscriminator = selectedAnswer.SymptomDiscriminator ?? model.SymptomDiscriminator,
                Part          = model.Part + 1,
                Questions     = questions,
                QuestionsJson = questionsJson,
                UserInfo      = model.UserInfo
            };

            return(new Tuple <string, JourneyViewModel>("JustToBeSafe", viewModel));
        }
 private string FindStateValue(IDictionary <string, string> state, QuestionWithAnswers step)
 {
     return(FindStateValue(state, step.Question.Title));
 }