示例#1
0
        private static QuestionReference generateQuestion32()
        {
            QuestionReference qr1 = new QuestionReference();
            Question          q1  = new Question();

            q1.IsMandatory  = true;
            q1.QuestionText = "Which of the following did cause an allergic reaction for you?";
            q1.AnswerType   = DataType.BOOLEAN;
            q1.QuestionType = new Choice(1, 7);
            List <AnswerOption> list = new List <AnswerOption> ();
            AnswerOption        a11  = new AnswerOption("Nuts");
            AnswerOption        a12  = new AnswerOption("Milk");
            AnswerOption        a13  = new AnswerOption("Egg");
            AnswerOption        a14  = new AnswerOption("Egg");
            AnswerOption        a15  = new AnswerOption("Soy");
            AnswerOption        a16  = new AnswerOption("Fish");
            AnswerOption        a17  = new AnswerOption("Other");

            list.Add(a11);
            list.Add(a12);
            list.Add(a13);
            list.Add(a14);
            list.Add(a15);
            list.Add(a16);
            list.Add(a17);
            q1.PossibleAnswers = list;
            qr1.Question       = q1;
            return(qr1);
        }
示例#2
0
        private static QuestionReference generateQuestion23()
        {
            QuestionReference qr1 = new QuestionReference();
            Question          q1  = new Question();

            q1.IsMandatory  = true;
            q1.QuestionText = "How would you describe your heat comfort?";
            q1.AnswerType   = DataType.STRING;
            q1.QuestionType = new Choice(1, 1);
            List <AnswerOption> list = new List <AnswerOption> ();
            AnswerOption        a11  = new AnswerOption("Freezing");
            AnswerOption        a12  = new AnswerOption("Cold");
            AnswerOption        a13  = new AnswerOption("Acceptable");
            AnswerOption        a14  = new AnswerOption("Warm");
            AnswerOption        a15  = new AnswerOption("Hot");

            list.Add(a11);
            list.Add(a12);
            list.Add(a13);
            list.Add(a14);
            list.Add(a15);
            q1.PossibleAnswers = list;
            qr1.Question       = q1;
            return(qr1);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Surveys.FreeValueView"/> class.
        /// </summary>
        /// <param name="qr">Qr.</param>
        /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
        public FreeValueView(QuestionReference qr, bool isMandatory) : base(qr, isMandatory)
        {
            QuestionLabel = new Label {
                Text     = "",
                FontSize = 32
            };

            // TODO Differentiate the keyboard type depending on the content
            AnswerEditor = new Editor {
                Keyboard        = Keyboard.Create(KeyboardFlags.All),
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            this.Children.Add(QuestionLabel);
            this.Children.Add(AnswerEditor);

            AnswerEditor.TextChanged += (sender, e) => {
                if (AnswerEditor.Text != null && AnswerEditor.Text != "")
                {
                    this.IsAnswered = true;
                    this.answers    = new HashSet <AnswerOption> {
                        new AnswerOption(AnswerEditor.Text)
                    };
                }
                else
                {
                    this.IsAnswered = false;
                }
            };
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Surveys.QuestionView"/> class.
 /// </summary>
 /// <param name="qr">Qr.</param>
 /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
 public QuestionView(QuestionReference qr, bool isMandatory)
 {
     this.VerticalOptions = LayoutOptions.FillAndExpand;
     this.IsMandatory     = isMandatory;
     question             = qr;
     answers = new HashSet <AnswerOption> ();
 }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Surveys.SingleChoiceView"/> class.
        /// </summary>
        /// <param name="qr">Qr.</param>
        /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
        public SingleChoiceView(QuestionReference qr, bool isMandatory) : base(qr, isMandatory)
        {
            QuestionLabel = new Label {
                Text     = "",
                FontSize = 32
            };

            AnswerPicker = new Picker();

            AnswerPicker.SelectedIndexChanged += (sender, e) => {
                if (AnswerPicker.SelectedIndex != -1)
                {
                    this.IsAnswered = true;
                    this.answers    = new HashSet <AnswerOption> {
                        new AnswerOption(AnswerPicker.Items [AnswerPicker.SelectedIndex])
                    };
                }
                else
                {
                    this.IsAnswered = false;
                };
            };

            this.Children.Add(QuestionLabel);

            this.Children.Add(AnswerPicker);
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Surveys.SingleChoiceView"/> class.
 /// </summary>
 /// <param name="qr">Qr.</param>
 /// <param name="questionText">Question text.</param>
 /// <param name="options">Options.</param>
 /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
 public SingleChoiceView(QuestionReference qr, string questionText, List <string> options, bool isMandatory) : this(qr, isMandatory)
 {
     QuestionLabel.Text = questionText;
     foreach (string answer in options)
     {
         AnswerPicker.Items.Add(answer);
     }
 }
示例#7
0
        private static Prerequisite generatePrerequisite33(QuestionReference qr)
        {
            List <AnswerOption> preq = new List <AnswerOption> ();
            AnswerOption        a    = new AnswerOption("Other");

            preq.Add(a);
            return(new Prerequisite(preq, qr, Prerequisite.PrOperator.OR));
        }
示例#8
0
        private static Prerequisite generatePrerequisite22(QuestionReference qr)
        {
            List <AnswerOption> preq = new List <AnswerOption> ();

            for (int i = 1; i < 4; i++)
            {
                AnswerOption a = new AnswerOption(i.ToString());
                preq.Add(a);
            }
            return(new Prerequisite(preq, qr, Prerequisite.PrOperator.OR));
        }
示例#9
0
        private static QuestionReference generateQuestionFreeM(String question, DataType answerType, Boolean mandatory)
        {
            QuestionReference qr1 = new QuestionReference();
            Question          q1  = new Question();

            q1.IsMandatory  = mandatory;
            q1.QuestionText = question;
            q1.AnswerType   = answerType;
            q1.QuestionType = new FreeValue();
            qr1.Question    = q1;
            return(qr1);
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Surveys.MultipleChocieView"/> class.
        /// </summary>
        /// <param name="qr">Qr.</param>
        /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
        public MultipleChocieView(QuestionReference qr, bool isMandatory) : base(qr, isMandatory)
        {
            QuestionLabel = new Label {
                Text     = "",
                FontSize = 32
            };

            answerOptions = new StackLayout {
            };


            this.Children.Add(QuestionLabel);
            this.Children.Add(answerOptions);
        }
示例#11
0
        /// <summary>
        /// Calculates the prerequisite.
        /// </summary>
        /// <returns><c>true</c>, if prerequisite was fullfilled, <c>false</c> otherwise.</returns>
        /// <param name="question">Question.</param>
        /// <param name="views">Views.</param>
        public static bool calculatePrerequisite(QuestionReference question, LinkedList <QuestionView> views)
        {
            bool value = false;
            bool found = false;

            if (question.Prerequisites.Count == 0)
            {
                return(true);
            }
            foreach (Prerequisite p in question.Prerequisites)
            {
                foreach (QuestionView qv in views)
                {
                    if (p.Question.Equals(qv.question))
                    {
                        foreach (AnswerOption a in p.Answers)
                        {
                            if (qv.answers.Contains(a))
                            {
                                value = true;
                                if (p.Op == Prerequisite.PrOperator.OR)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (p.Op == Prerequisite.PrOperator.AND)
                                {
                                    return(false);
                                }
                            }
                        }
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(false);
                }
                found = false;
            }
            return(value);
        }
示例#12
0
        private static SurveyPart generatePart2()
        {
            SurveyPart sp1 = new SurveyPart();

            sp1.Scheduler = new Scheduler(Schedule.DAILY);
            LinkedList <QuestionReference> list = new LinkedList <QuestionReference> ();
            QuestionReference qr21 = generateQuestion21();

            list.AddLast(qr21);
            QuestionReference qr22 = generateQuestionFreeM("What is the reason of your discomfort", DataType.STRING, true);

            qr22.Prerequisites.Add(generatePrerequisite22(qr21));
            list.AddLast(qr22);
            list.AddLast(generateQuestion23());
            list.AddLast(generateQuestionFreeM("What is the ambient temperature?", DataType.FLOAT, true));
            sp1.Questions = list;
            return(sp1);
        }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Surveys.MultipleChocieView"/> class.
 /// </summary>
 /// <param name="qr">Qr.</param>
 /// <param name="questionText">Question text.</param>
 /// <param name="options">Options.</param>
 /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
 public MultipleChocieView(QuestionReference qr, string questionText, List <string> options, bool isMandatory) : this(qr, isMandatory)
 {
     this.IsMandatory   = isMandatory;
     QuestionLabel.Text = questionText;
     foreach (string answer in options)
     {
         CheckBox answerCheckbox = new CheckBox();
         answerCheckbox.CheckedChanged += (sender, e) => {
             {
                 if (answerCheckbox.Checked == true)
                 {
                     this.answers.Add(new AnswerOption(answer));
                     this.IsAnswered = true;
                 }
                 else
                 {
                     this.answers.Remove(new AnswerOption(answer));
                     bool foundChecked = false;
                     foreach (StackLayout sl in this.answerOptions.Children)
                     {
                         CheckBox c = (CheckBox)sl.Children[0];
                         if (c.Checked == true)
                         {
                             foundChecked = true;
                         }
                     }
                     this.IsAnswered = foundChecked;
                 }
             };
         };
         answerOptions.Children.Add(new StackLayout {
             Orientation   = StackOrientation.Horizontal,
             HeightRequest = 40,
             Children      =
             {
                 answerCheckbox,
                 new Label {
                     Text = answer
                 }
             }
         });
     }
 }
示例#14
0
        private static QuestionReference generateQuestion31()
        {
            QuestionReference qr1 = new QuestionReference();
            Question          q1  = new Question();

            q1.IsMandatory  = true;
            q1.QuestionText = "Did you experience any allergic reactions recently?";
            q1.AnswerType   = DataType.BOOLEAN;
            q1.QuestionType = new Choice(1, 1);
            List <AnswerOption> list = new List <AnswerOption> ();
            AnswerOption        a11  = new AnswerOption("Yes");
            AnswerOption        a12  = new AnswerOption("No");

            list.Add(a11);
            list.Add(a12);
            q1.PossibleAnswers = list;
            qr1.Question       = q1;
            return(qr1);
        }
示例#15
0
        private static QuestionReference generateQuestion21()
        {
            QuestionReference qr1 = new QuestionReference();
            Question          q1  = new Question();

            q1.IsMandatory  = true;
            q1.QuestionText = "How are you feeling today?";
            q1.AnswerType   = DataType.INTEGER;
            q1.QuestionType = new Choice(1, 1);
            List <AnswerOption> list = new List <AnswerOption> ();

            for (int i = 1; i < 11; i++)
            {
                AnswerOption a = new AnswerOption(i.ToString());
                list.Add(a);
            }
            q1.PossibleAnswers = list;
            qr1.Question       = q1;
            return(qr1);
        }
示例#16
0
        /// <summary>
        /// Moves to the previous question.
        /// </summary>
        /// <returns>The previous question.</returns>
        public QuestionView PreviousQuestion()
        {
            QuestionView currentView = generatedViews [currentQuestion.Value];
            LinkedListNode <QuestionView> currentViewNode = CurrentViews.Find(currentView);

            if (currentViewNode.Previous == null)
            {
                return(null);
            }
            QuestionView      previousView      = currentViewNode.Previous.Value;
            QuestionReference previousReference = previousView.question;

            while (currentQuestion.Value != previousReference)
            {
                if (!RegressQuestion())
                {
                    throw new ArgumentOutOfRangeException("Could not find the predecessor for the question");
                }
            }
            return(previousView);
        }
示例#17
0
        private static QuestionReference generateQuestion11()
        {
            QuestionReference qr1 = new QuestionReference();
            Question          q1  = new Question();

            q1.IsMandatory  = true;
            q1.QuestionText = "What is your gender?";
            q1.AnswerType   = DataType.STRING;
            q1.QuestionType = new Choice(1, 1);
            List <AnswerOption> list = new List <AnswerOption> ();
            AnswerOption        a11  = new AnswerOption("Male");
            AnswerOption        a12  = new AnswerOption("Female");
            AnswerOption        a13  = new AnswerOption("Other");

            list.Add(a11);
            list.Add(a12);
            list.Add(a13);
            q1.PossibleAnswers = list;
            qr1.Question       = q1;
            return(qr1);
        }
示例#18
0
        /// <summary>
        /// Gets the question view specific to the reference.
        /// </summary>
        /// <returns>The question view.</returns>
        /// <param name="qref">Question reference.</param>
        private QuestionView GetQuestionView(QuestionReference qref)
        {
            var qtype = qref.Question.QuestionType;

            if (qtype is FreeValue)
            {
                string questionText = qref.Question.QuestionText;
                return(new FreeValueView(qref, questionText, qref.Question.IsMandatory));
            }
            else if (qtype is Choice)
            {
                string questionText = qref.Question.QuestionText;
                if (((Choice)qtype).minNumOfAnswers == 1 && ((Choice)qtype).maxNumOfAnswers == 1)
                {
                    List <string> answerStrings = new List <string> ();
                    foreach (AnswerOption ao in qref.Question.PossibleAnswers)
                    {
                        answerStrings.Add(ao.Content);
                    }

                    return(new SingleChoiceView(qref, questionText, answerStrings, qref.Question.IsMandatory));
                }
                else
                {
                    List <string> answerStrings = new List <string> ();
                    foreach (AnswerOption ao in qref.Question.PossibleAnswers)
                    {
                        answerStrings.Add(ao.Content);
                    }

                    return(new MultipleChocieView(qref, questionText, answerStrings, qref.Question.IsMandatory));
                }
            }
            else
            {
                throw new ArgumentException("Question Type not supported");
            }
        }
示例#19
0
        private static SurveyPart generatePart3()
        {
            SurveyPart sp1 = new SurveyPart();

            sp1.Scheduler = new Scheduler(Schedule.DAILY);
            LinkedList <QuestionReference> list = new LinkedList <QuestionReference> ();
            QuestionReference qr31 = generateQuestion31();

            list.AddLast(qr31);
            QuestionReference qr32 = generateQuestion32();

            qr32.Prerequisites.Add(generatePrerequisite32(qr31));
            list.AddLast(qr32);
            QuestionReference qr33 = generateQuestionFreeM("Please enter the other food(s) which caused an allergic reaction for you", DataType.STRING, true);

            qr33.Prerequisites.Add(generatePrerequisite33(qr32));
            list.AddLast(qr33);
            QuestionReference qr34 = generateQuestionFreeM("Do you have any additional comments?", DataType.STRING, true);

            list.AddLast(qr34);
            sp1.Questions = list;
            return(sp1);
        }
示例#20
0
 public Prerequisite(List <AnswerOption> answers, QuestionReference qr, PrOperator oper)
 {
     Answers  = answers;
     Question = qr;
     Op       = oper;
 }
示例#21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Surveys.FreeValueView"/> class.
 /// </summary>
 /// <param name="qr">Qr.</param>
 /// <param name="questionText">Question text.</param>
 /// <param name="isMandatory">If set to <c>true</c> is mandatory.</param>
 public FreeValueView(QuestionReference qr, string questionText, bool isMandatory) : this(qr, isMandatory)
 {
     QuestionLabel.Text = questionText;
     this.IsMandatory   = isMandatory;
     this.IsAnswered    = false;
 }