public async Task CanGetQuestionnaires() { var response = await _client.GetAsync("/api/questionnaire/getall"); List <Questionnaire> r = await response.Content.ReadAsAsync <List <Questionnaire> >(); //Debug.WriteLine($"@@@ xx {r} "); Assert.True(r.Count() > 0); Questionnaire q = r.First(); Assert.Equal("Questionnaire1", q.Name); Assert.True(q.Sections.Count() == 2); QuestionnaireSection section = q.Sections.First(); Assert.Equal("Section1", section.SectionName); List <Question> sectionQuestions = section.Questions; Assert.True(sectionQuestions.Count() == 4); Question s1q1 = sectionQuestions.First(); Assert.Equal("What is your name?", s1q1.QuestionText); Assert.Equal(QuestionType.Text, s1q1.QuestionType); Question s1q2 = sectionQuestions[1]; Assert.Equal(QuestionType.Radio, s1q2.QuestionType); }
private static void LoadItemIntoSection(XmlElement e, ref QuestionnaireSection section) { QuestionnaireItem item = new QuestionnaireItem(); item.ActionId = GetNodeValue(e, "ActionId"); item.DisplayId = GetNodeValue(e, "DisplayId"); item.Attributes = QuestionnaireItemAttributes.CanSkip; //TODO item.ScoringNote = GetNodeValue(e, "ScoringNote"); if (GetNodeValue(e, "BestScore") == "Highest") { item.HigherIsBetter = true; } else { item.HigherIsBetter = false; } try { item.SummaryText = GetNodeValue(e, "Summary"); } catch (Exception exp) { Error = "The summary: \n doesn't exist"; Form1.Print("The summary: doesn't exist" + exp.ToString()); logReport.returnError("The summary: doesn't exist" + exp.ToString()); } QuestionnaireElement x = item; LoadTextVersionsIntoElement(e, ref x); LoadOptionGroupsIntoItem(e, ref item); section.Elements.Add(item); }
private static void LoadSectionInstructions(XmlElement s, ref QuestionnaireSection section) { foreach (XmlElement i in s.GetElementsByTagName("Instruction")) { QuestionnaireSectionInstruction inst = new QuestionnaireSectionInstruction(); inst.SetSupportedInstances(Instance.Baseline, Instance.Followup); //TODO inst.SetSupportedPlatforms(Platform.Chat, Platform.Classic, Platform.Mobile); //TODO inst.Text = GetNodeValue(i, "Text"); section.Instructions.Add(inst); } }
private static void LoadTextIntoSection(XmlElement e, ref QuestionnaireSection section) { QuestionnaireText text = new QuestionnaireText(); text.ActionId = GetNodeValue(e, "ActionId"); QuestionnaireElement x = text; LoadTextVersionsIntoElement(e, ref x); section.Elements.Add(text); }
private static void LoadSections(XmlElement root, ref Survey surv) { foreach (XmlElement s in root.GetElementsByTagName("Section")) { QuestionnaireSection sec = new QuestionnaireSection(); sec.ActionId = GetNodeValue(s, "ActionId"); LoadSectionElements(s, ref sec); LoadSectionInstructions(s, ref sec); surv.Sections.Add(sec); } }
private static void LoadSectionElements(XmlElement s, ref QuestionnaireSection section) { foreach (XmlElement e in s.GetElementsByTagName("Element")) { if (e.Attributes["type"].Value == "Item") { LoadItemIntoSection(e, ref section); } else { LoadTextIntoSection(e, ref section); } } }
private QuestionnaireItem AddItemToSection(QuestionnaireSection section, string actionId, string displayId, string text, Platform platform, Instance instance) { QuestionnaireItem item = new QuestionnaireItem() { ActionId = actionId, DisplayId = displayId, OrderInSection = section.Elements.Count + 1, Section = section, }; item.TextVersions.Add(new QuestionnaireElementTextVersion() { SupportedInstances = instance, SupportedPlatforms = platform, Text = text }); section.Elements.Add(item); return(item); }
private QuestionnaireText AddTextToSection(QuestionnaireSection section, string actionId, string text, Platform platform, Instance instance) { QuestionnaireText txt = new QuestionnaireText() { ActionId = actionId, OrderInSection = section.Elements.Count + 1, Section = section, }; txt.TextVersions.Add(new QuestionnaireElementTextVersion() { SupportedInstances = instance, SupportedPlatforms = platform, Text = text }); section.Elements.Add(txt); return(txt); }
private static void LoadItemIntoSection(XmlElement e, ref QuestionnaireSection section) { QuestionnaireItem item = new QuestionnaireItem(); item.ActionId = GetNodeValue(e, "ActionId"); item.DisplayId = GetNodeValue(e, "DisplayId"); item.Attributes = QuestionnaireItemAttributes.CanSkip; //TODO item.SummaryText = GetNodeValue(e, "Summary"); QuestionnaireElement x = item; LoadTextVersionsIntoElement(e, ref x); LoadOptionGroupsIntoItem(e, ref item); section.Elements.Add(item); }
public QuestionnaireSet getSet(string filepath) { if (String.IsNullOrEmpty(filepath)) { throw new ArgumentNullException("filename"); } if (!File.Exists(filepath)) { throw new ArgumentException("Missing XML questionnaire definition file"); } QuestionnaireSet qset = null; List <QuestionnaireQuestion> currentQuestions = null; Questionnaire currentQuestionnaire = null; QuestionnaireQuestion currentQuestion = null; QuestionnaireSection currentSection = null; QuestionnairePage currentPage = null; QuestionnaireSubsection currentSubsection = null; XmlReader reader = new XmlTextReader(filepath); while (reader.Read()) { switch ((int)reader.NodeType) { case (int)XmlNodeType.Element: string name = reader.Name; if (name == "QuestionnaireSet") { qset = new QuestionnaireSet(); qset.Name = reader.GetAttribute("name"); qset.Title = reader.GetAttribute("title"); qset.Description = reader.GetAttribute("description"); qset.Questionnaires = new List <Questionnaire>(); } else if (name == "Introduction") { currentQuestions = new List <QuestionnaireQuestion>(); } else if (name == "Questionnaire") { currentQuestionnaire = new Questionnaire(); currentQuestionnaire.Name = reader.GetAttribute("name"); currentQuestionnaire.Title = reader.GetAttribute("title"); currentQuestionnaire.Description = reader.GetAttribute("description"); currentQuestionnaire.Sections = new List <QuestionnaireSection>(); } else if (name == "Choices") { currentQuestion.Choices = new List <KeyValuePair <string, string> >(); } else if (name == "Choice") { string nbr = reader.GetAttribute("number"); string txt = reader.GetAttribute("text"); currentQuestion.Choices.Add(new KeyValuePair <string, string>(nbr, txt)); } else if (name == "Section") { currentSection = new QuestionnaireSection(); currentSection.Name = reader.GetAttribute("name"); currentSection.Title = reader.GetAttribute("title"); currentSection.Pages = new List <QuestionnairePage>(); } else if (name == "Page") { currentPage = new QuestionnairePage(); currentPage.Number = reader.GetAttribute("number"); currentPage.Sections = new List <QuestionnaireSubsection>(); } else if (name == "Subsection") { currentSubsection = new QuestionnaireSubsection(); currentSubsection.Name = reader.GetAttribute("name"); currentSubsection.Title = reader.GetAttribute("title"); } else if (name == "Questions") { currentQuestions = new List <QuestionnaireQuestion>(); } else if (name == "Question") { currentQuestion = new QuestionnaireQuestion(); currentQuestion.Number = reader.GetAttribute("number"); currentQuestion.Text = reader.GetAttribute("text"); currentQuestion.BranchFromQuestion = reader.GetAttribute("branchFrom"); currentQuestion.BranchCondition = reader.GetAttribute("if"); currentQuestions.Add(currentQuestion); } break; case (int)XmlNodeType.EndElement: name = reader.Name; if (name == "Introduction") { qset.Questions = currentQuestions; currentQuestions = null; } else if (name == "Questionnaire") { qset.Questionnaires.Add(currentQuestionnaire); currentQuestionnaire = null; } else if (name == "Choices") { } else if (name == "Section") { currentQuestionnaire.Sections.Add(currentSection); currentSection = null; } else if (name == "Page") { currentSection.Pages.Add(currentPage); currentPage = null; } else if (name == "Subsection") { currentPage.Sections.Add(currentSubsection); currentSubsection = null; } else if (name == "Questions") { currentSubsection.Questions = currentQuestions; currentQuestions = null; } break; } } return(qset); }
public QuestionnaireSectionTO(QuestionnaireSection mdo) { this.name = mdo.Name; this.title = mdo.Title; this.pages = new QuestionnairePageArray(mdo.Pages); }
public void AddFullProInstrumentTest() { ProInstrument pro = new ProInstrument(); pro.Name = "OES2"; pro.Status = QuestionnaireStatus.Indevelopment; pro.IsActive = true; pro.Tags.Add(new Tag() { TagName = "Gender", Value = "Male" }); pro.Tags.Add(new Tag() { TagName = "Gender", Value = "Female" }); { ProDomain d1 = new ProDomain(); d1.Name = "Total Domain"; d1.Audience = PCHI.Model.Users.UserTypes.Patient; d1.Description = "Hello"; d1.ScoreFormula = "{OES.1} + {OES.2}"; { ProDomainResultRange r1 = new ProDomainResultRange(); r1.Start = 0; r1.End = 10; r1.Meaning = "Great"; d1.ResultRanges.Add(r1); } { ProDomainResultRange r2 = new ProDomainResultRange(); r2.Start = 11; r2.End = 20; r2.Meaning = "Oops"; d1.ResultRanges.Add(r2); } pro.Domains.Add(d1); } { ProDomain d2 = new ProDomain(); d2.Name = "Sleep Domain"; d2.Audience = PCHI.Model.Users.UserTypes.Patient; d2.Description = "Hello"; d2.ScoreFormula = "{OES.1} + {OES.2}"; { ProDomainResultRange r1 = new ProDomainResultRange(); r1.Start = 0; r1.End = 10; r1.Meaning = "Great"; d2.ResultRanges.Add(r1); } { ProDomainResultRange r2 = new ProDomainResultRange(); r2.Start = 11; r2.End = 20; r2.Meaning = "Oops"; d2.ResultRanges.Add(r2); } pro.Domains.Add(d2); } pro.Concept = new QuestionnaireConcept() { Name = "Elbow", Description = "Tests Elbow Condition" }; { QuestionnaireSection section = new QuestionnaireSection() { OrderInInstrument = 1, Questionnaire = pro }; pro.Sections.Add(section); AddTextToSection(section, "Intro1", @"", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); AddTextToSection(section, "Intro2", @"Please make sure you answer all the questions that follow by ticking one option for every question.", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); } { //Dictionary<int, string> options = null; //var options;// = new MyDictionary(); QuestionnaireSection section = new QuestionnaireSection() { OrderInInstrument = 2, Questionnaire = pro }; pro.Sections.Add(section); { // same options apply to items 1 to 4 MyDictionary options = new MyDictionary() { { 4, new ValuesOption() { Action = "", Text = "No difficulty" } }, { 3, new ValuesOption() { Action = "", Text = "A little bit of difficulty" } }, { 2, new ValuesOption() { Action = "", Text = "Moderate difficulty" } }, { 1, new ValuesOption() { Action = "", Text = "Extreme difficulty" } }, { 0, new ValuesOption() { Action = "", Text = "Impossible to do" } } }; QuestionnaireItem qi = AddItemToSection(section, "OES.1", "1.", @"<strong>During the past 4 weeks</strong>, have you had difficulty lifting things in your home, such as putting out the rubbish, <u>because of your elbow problem</u>?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.List); qi = AddItemToSection(section, "OES.2", "2.", @"<strong>During the past 4 weeks</strong>, have you had difficulty lifting things in your home, such as putting out the rubbish, <u>because of your elbow problem</u>?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.List); qi = AddItemToSection(section, "OES.3", "3.", @"<strong>During the past 4 weeks</strong>, have you had difficulty washing yourself all over, <u>because of your elbow problem</u>?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.List); qi = AddItemToSection(section, "OES.4", "4.", @"<strong>During the past 4 weeks</strong>, have you had difficulty dressing yourself, <u>because of your elbow problem</u>?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.List); qi = AddItemToSection(section, "OES.5", "5.", @"How difficult is for you to get up and down off the floor/gound?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); options = new MyDictionary() { { 0, new ValuesOption() { Action = "", Text = "Extreme difficulty" } }, { 100, new ValuesOption() { Action = "", Text = "No difficulty at all" } } }; AddOptionGroupToItem(qi, options, 10, QuestionnaireResponseType.Range); qi = AddItemToSection(section, "OES.6", "6.", @"How much trouble do you have with sexual activity because of your hip?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); options = new MyDictionary() { { 0, new ValuesOption() { Action = "MakeItemNotApplicable", Text = "This is not relevant to me" } } }; AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.ConditionalItem); options = new MyDictionary() { { 0, new ValuesOption() { Action = "", Text = "Several trouble" } }, { 100, new ValuesOption() { Action = "", Text = "No trouble at all" } } }; AddOptionGroupToItem(qi, options, 10, QuestionnaireResponseType.Range); qi = AddItemToSection(section, "OES.7", "7.", @"How much trouble do you have pushing, pulling, lifting or carrying heavy objects at work?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); options = new MyDictionary() { { 0, new ValuesOption() { Action = "MakeItemNotApplicable", Text = "I do not do these actions in my activities" } } }; AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.ConditionalItem); options = new MyDictionary() { { 0, new ValuesOption() { Action = "", Text = "Several trouble" } }, { 100, new ValuesOption() { Action = "", Text = "No trouble at all" } } }; AddOptionGroupToItem(qi, options, 10, QuestionnaireResponseType.Range); qi = AddItemToSection(section, "OES.8", "8.", @"How concern are you about cutting/changing directions during your sport or recreational activities?", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); options = new MyDictionary() { { 0, new ValuesOption() { Action = "MakeItemNotApplicable", Text = "I do not do this action in my activities" } } }; AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.ConditionalItem); options = new MyDictionary() { { 0, new ValuesOption() { Action = "", Text = "Extremly concerned" } }, { 100, new ValuesOption() { Action = "", Text = "Not concerned at all" } } }; AddOptionGroupToItem(qi, options, 10, QuestionnaireResponseType.Range); qi = AddItemToSection(section, "OES.9", "9.", @"Please indicate the sport or instrument which is most important to you:", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); options = new MyDictionary() { { 0, new ValuesOption() { Action = "", Text = "" } } }; AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.Text); qi = AddItemToSection(section, "OES.10", "10.", @"Enter your comments below:", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.Text); //Part to add the definition for the body control qi = AddItemToSection(section, "OES.11", "11.", @"Select the parts of your body with some kind of mal functioning:", Platform.Classic | Platform.Chat, Instance.Baseline | Instance.Followup); options = new MyDictionary() { { 0, new ValuesOption() { Action = "", Text = "Burning" } }, { 1, new ValuesOption() { Action = "", Text = "Numbness" } }, { 2, new ValuesOption() { Action = "", Text = "Pins-Needles" } }, { 3, new ValuesOption() { Action = "", Text = "Stabbing" } }, { 4, new ValuesOption() { Action = "", Text = "Ache" } } }; AddOptionGroupToItem(qi, options, 0, QuestionnaireResponseType.MultiSelect); //Optiongroup for each body part /* * qiog1.OrderInItem = 1; * { * qiog1.Options.Add(new QuestionnaireItemOption() { Text = "None", Value = 0, Group = qiog1 }); * qiog1.Options.Add(new QuestionnaireItemOption() { Text = "Mild", Value = 1, Group = qiog1 }); * qiog1.Options.Add(new QuestionnaireItemOption() { Text = "Moderate", Value = 2, Group = qiog1 }); * qiog1.Options.Add(new QuestionnaireItemOption() { Text = "Severe", Value = 3, Group = qiog1 }); * qiog1.Options.Add(new QuestionnaireItemOption() { Text = "Unbearable", Value = 4, Group = qiog1 }); * qiog1.Item = q1; * } * * q1.OptionGroups.Add(qiog1); * section.Elements.Add(q1); * q1.Section = section; * */ } } { QuestionnaireSection section = new QuestionnaireSection() { OrderInInstrument = 3, Questionnaire = pro }; pro.Sections.Add(section); AddTextToSection(section, "Footer1", @"Thank you for answering. You are done now and the results will be reported to your physician.", Platform.Classic, Instance.Baseline | Instance.Followup); AddTextToSection(section, "Footer1", @"Thank you for answering. You are done now and I will evaluate the results as soon as possible.", Platform.Chat, Instance.Baseline | Instance.Followup); } new AccessHandlerManager().QuestionnaireAccessHandler.AddFullQuestionnaire(pro); }
public static void Initialize(QuestionnairesContext context) { context.Database.EnsureCreated(); if (context.Questionnaires.Any()) { return; //If this happens the DB already exists and has been seeded with test data } var questionnaires = new Questionnaire[] { new Questionnaire { Title = "Example questionnaire", IntroText = "A questionnaire on an example topic" } }; foreach (Questionnaire q in questionnaires) { context.Questionnaires.Add(q); } context.SaveChanges(); var sections = new QuestionnaireSection[] { new QuestionnaireSection { QuestionnaireID = 1, Title = "Section 1", IntroText = "Intro 1" }, new QuestionnaireSection { QuestionnaireID = 1, Title = "Section 2", IntroText = "Intro 2" } }; foreach (QuestionnaireSection s in sections) { context.QuestionnaireSections.Add(s); } context.SaveChanges(); var items = new QuestionnaireItem[] { new QuestionnaireItem { QuestionnaireSectionID = 1, ItemText = "Item 1", ItemType = ItemTypes.Text }, new QuestionnaireItem { QuestionnaireSectionID = 1, ItemText = "Item 2", ItemType = ItemTypes.Value }, new QuestionnaireItem { QuestionnaireSectionID = 1, ItemText = "Item 3", ItemType = ItemTypes.Likert }, new QuestionnaireItem { QuestionnaireSectionID = 2, ItemText = "Item 4", ItemType = ItemTypes.Text }, new QuestionnaireItem { QuestionnaireSectionID = 2, ItemText = "Item 5", ItemType = ItemTypes.Value }, new QuestionnaireItem { QuestionnaireSectionID = 2, ItemText = "Item 6", ItemType = ItemTypes.Likert } }; foreach (QuestionnaireItem i in items) { context.QuestionnaireItems.Add(i); } context.SaveChanges(); }
public QuestionnaireSet getSet(string filepath) { if (String.IsNullOrEmpty(filepath)) { throw new ArgumentNullException("filename"); } if (!File.Exists(filepath)) { throw new ArgumentException("Missing XML questionnaire definition file"); } QuestionnaireSet qset = null; List<QuestionnaireQuestion> currentQuestions = null; Questionnaire currentQuestionnaire = null; QuestionnaireQuestion currentQuestion = null; QuestionnaireSection currentSection = null; QuestionnairePage currentPage = null; QuestionnaireSubsection currentSubsection = null; XmlReader reader = new XmlTextReader(filepath); while (reader.Read()) { switch ((int)reader.NodeType) { case (int)XmlNodeType.Element: string name = reader.Name; if (name == "QuestionnaireSet") { qset = new QuestionnaireSet(); qset.Name = reader.GetAttribute("name"); qset.Title = reader.GetAttribute("title"); qset.Description = reader.GetAttribute("description"); qset.Questionnaires = new List<Questionnaire>(); } else if (name == "Introduction") { currentQuestions = new List<QuestionnaireQuestion>(); } else if (name == "Questionnaire") { currentQuestionnaire = new Questionnaire(); currentQuestionnaire.Name = reader.GetAttribute("name"); currentQuestionnaire.Title = reader.GetAttribute("title"); currentQuestionnaire.Description = reader.GetAttribute("description"); currentQuestionnaire.Sections = new List<QuestionnaireSection>(); } else if (name == "Choices") { currentQuestion.Choices = new List<KeyValuePair<string, string>>(); } else if (name == "Choice") { string nbr = reader.GetAttribute("number"); string txt = reader.GetAttribute("text"); currentQuestion.Choices.Add(new KeyValuePair<string, string>(nbr, txt)); } else if (name == "Section") { currentSection = new QuestionnaireSection(); currentSection.Name = reader.GetAttribute("name"); currentSection.Title = reader.GetAttribute("title"); currentSection.Pages = new List<QuestionnairePage>(); } else if (name == "Page") { currentPage = new QuestionnairePage(); currentPage.Number = reader.GetAttribute("number"); currentPage.Sections = new List<QuestionnaireSubsection>(); } else if (name == "Subsection") { currentSubsection = new QuestionnaireSubsection(); currentSubsection.Name = reader.GetAttribute("name"); currentSubsection.Title = reader.GetAttribute("title"); } else if (name == "Questions") { currentQuestions = new List<QuestionnaireQuestion>(); } else if (name == "Question") { currentQuestion = new QuestionnaireQuestion(); currentQuestion.Number = reader.GetAttribute("number"); currentQuestion.Text = reader.GetAttribute("text"); currentQuestion.BranchFromQuestion = reader.GetAttribute("branchFrom"); currentQuestion.BranchCondition = reader.GetAttribute("if"); currentQuestions.Add(currentQuestion); } break; case (int)XmlNodeType.EndElement: name = reader.Name; if (name == "Introduction") { qset.Questions = currentQuestions; currentQuestions = null; } else if (name == "Questionnaire") { qset.Questionnaires.Add(currentQuestionnaire); currentQuestionnaire = null; } else if (name == "Choices") { } else if (name == "Section") { currentQuestionnaire.Sections.Add(currentSection); currentSection = null; } else if (name == "Page") { currentSection.Pages.Add(currentPage); currentPage = null; } else if (name == "Subsection") { currentPage.Sections.Add(currentSubsection); currentSubsection = null; } else if (name == "Questions") { currentSubsection.Questions = currentQuestions; currentQuestions = null; } break; } } return qset; }