Пример #1
0
        // This is the Insert method to insert the entered SurveyResponse item
        // USAGE: <asp:FormView InsertMethod="InsertItem">
        public void InsertItem()
        {
            using (_db)
            {
                var item = new SurveyPortal.Data.Models.SurveyResponse();

                TryUpdateModel(item);

                if (ModelState.IsValid)
                {
                    // Save changes
                    _db.SurveyResponses.Add(item);
                    _db.SaveChanges();

                    Response.Redirect("Default");
                }
            }
        }
Пример #2
0
        private void DependetQuestionState(SurveyResponse surveyResponse, UtilityBL.SectionType sectionType)
        {
            foreach (var section in surveyResponse.SurveyTitle.SurveySections.Where(s => s.SectionTypeId == (int)sectionType))
            {
                foreach (var question in section.Questions)
                {                    
                    var ctrl = "ctrl" + question.QuestionId.ToString();
                    dynamic rdbList = new RadioButtonList(); 
                    if (question.QuestionTypeId == 1)
                    {
                        rdbList = Form.FindControl(ctrl) as RadioButtonList;
                    }

                    if (question.QuestionTypeId == 2)
                    {
                        rdbList = Form.FindControl(ctrl) as CheckBoxList;
                    }
                  
                    if (question.QuestionsDependent != null && question.QuestionsDependent.Count > 0)
                    {
                        foreach (var dependent in question.QuestionsDependent)
                        {
                            var divId = "divQuestion" + dependent.QuestionId.ToString();
                            var div = Form.FindControl(divId);
                            rdbList.Attributes.Add("onclick", "JavaScript: radioButtonListOnClick(this,'" + divId + "','" + dependent.EnabledValue + "');");
                        }
                    }                   
                    
                }
            }

        }
Пример #3
0
        private void PopulateSurvey(SurveyResponse response, UtilityBL.Mode mode)
        {
            var survey = response.SurveyTitle;

            if (survey == null)
            {
                lblSurveyTitle.Text = "Invalid Survey";
                return;
            }
            lblSurveyTitle.Text = survey.SurveyTitle1;
            lblSurveyDescription.Text = survey.Description;

            var score = 0;
            var hasAnswers = false;
            if (response.QuestionResponses.Any())
                hasAnswers = true;

            foreach (var section in survey.SurveySections)
            {

                var divSection = new HtmlGenericControl("div");
                divSection.Attributes.Add("id", "divSection" + section.SurveySectionId.ToString());
                divSection.Attributes.Add("class", "panel panel-info");

                if (section.SectionTypeId == (int)UtilityBL.SectionType.Doctor)
                {
                    if (mode != UtilityBL.Mode.Entry)
                        pnlDoctorSection.Controls.Add(divSection);
                    else
                        continue;
                }
                else
                    Panel1.Controls.Add(divSection);

                var divSectionTitle = new HtmlGenericControl("div");
                divSectionTitle.Attributes.Add("id", "divSectionTitle" + section.SurveySectionId.ToString());
                divSectionTitle.Attributes.Add("class", "panel-heading");
                divSection.Controls.Add(divSectionTitle);

                if (section.DisplaySectionHeader && !string.IsNullOrEmpty(section.SurveySectionTtile))
                {
                    var lblSectionTitle = new Label();
                    lblSectionTitle.Text = section.SurveySectionTtile;
                    lblSectionTitle.Font.Bold = true;
                    lblSectionTitle.Font.Size = FontUnit.Large;
                    divSectionTitle.Controls.Add(lblSectionTitle);

                    if (!string.IsNullOrEmpty(section.SurveySectionDesc))
                    {
                        var sectionPara = new HtmlGenericControl("p");
                        sectionPara.Attributes.Add("id", "p" + section.SurveySectionId.ToString());
                        divSectionTitle.Controls.Add(sectionPara);

                        var lblSectionDescription = new Label();
                        lblSectionDescription.Text = section.SurveySectionDesc;
                        lblSectionDescription.Font.Size = FontUnit.Small;
                        sectionPara.Controls.Add(lblSectionDescription);
                    }
                }

                var divSectionBody = new HtmlGenericControl("div");
                divSectionBody.Attributes.Add("id", "divSectionBody" + section.SurveySectionId.ToString());
                divSectionBody.Attributes.Add("class", "panel-body");
                divSection.Controls.Add(divSectionBody);

                foreach (var q in section.Questions)
                {
                    var divQuestion = new HtmlGenericControl("div");
                    divQuestion.Attributes.Add("id", "divQuestion" + q.QuestionId.ToString());
                    divQuestion.Attributes.Add("class", "panel panel-default");
                    divSectionBody.Controls.Add(divQuestion);

                    var divQuestionTitle = new HtmlGenericControl("div");
                    divQuestionTitle.Attributes.Add("id", "divQuestionTitle" + q.QuestionId.ToString());
                    divQuestionTitle.Attributes.Add("class", "panel-heading");
                    divQuestion.Controls.Add(divQuestionTitle);


                    var lblQuestion = new Label();
                    lblQuestion.Text = q.Question1;
                    lblQuestion.ID = "lblQuestion" + q.QuestionId.ToString();
                    lblQuestion.Font.Bold = true;
                    divQuestionTitle.Controls.Add(lblQuestion);

                    var divQuestionBody = new HtmlGenericControl("div");
                    divQuestionBody.Attributes.Add("class", "panel-body");
                    divQuestionBody.Attributes.Add("id", "divQuestionBody" + q.QuestionId.ToString());
                    divQuestion.Controls.Add(divQuestionBody);

                    if (q.QuestionTypeId == 1)
                    {
                        var rdbList = new RadioButtonList();
                        rdbList.ID = "ctrl" + q.QuestionId.ToString();
                        rdbList.DataTextField = "QuestionOption1";
                        rdbList.DataValueField = "QuestionOptionId";
                        rdbList.DataSource = q.QuestionOptions;
                        rdbList.DataBind();
                        rdbList.Attributes.Add("class", "radio radiobuttonlist");

                        if (hasAnswers)
                        {
                            var answr = q.QuestionResponses.FirstOrDefault(r => r.SurveyResponse.SurveyResponseId == response.SurveyResponseId);
                            if (answr != null)
                                rdbList.SelectedValue = answr.QuestionOptionId.ToString();
                        }

                        if (q.DependentonQuestion != null)
                        {
                            var parentAnswer = q.DependentonQuestion.QuestionResponses.FirstOrDefault(r => r.SurveyResponse.SurveyResponseId == response.SurveyResponseId);
                            if (parentAnswer == null || q.EnabledValue != parentAnswer.ResponseText)
                            {
                                foreach (ListItem radio in rdbList.Items)
                                    radio.Enabled = false;
                            }
                        }
                            
                        divQuestionBody.Controls.Add(rdbList);
                    }

                    else if (q.QuestionTypeId == 2)
                    {
                        var chkList = new CheckBoxList();
                        chkList.ID = "ctrl" + q.QuestionId.ToString();
                        chkList.DataTextField = "QuestionOption1";
                        chkList.DataValueField = "QuestionOptionId";
                        chkList.DataSource = q.QuestionOptions;
                        chkList.DataBind();
                        chkList.Attributes.Add("class", "checkbox checked-list-box");

                        if (hasAnswers)
                        {
                            foreach (ListItem item in chkList.Items)
                            {
                                if (q.QuestionResponses.Any(r => r.QuestionOptionId == Convert.ToInt32(item.Value) && r.SurveyResponse.SurveyResponseId == response.SurveyResponseId))
                                {
                                    item.Selected = true;
                                    var qOption = q.QuestionOptions.FirstOrDefault(o => o.QuestionOptionId == Convert.ToInt32(item.Value));
                                }
                            }
                        }

                        if (q.DependentonQuestion != null)
                            chkList.Attributes.Add("disabled", "disabled");

                        divQuestionBody.Controls.Add(chkList);
                    }

                    if (q.QuestionTypeId == 3)
                    {
                        var txt = new TextBox();
                        txt.ID = "ctrl" + q.QuestionId.ToString();
                        txt.Attributes.Add("class", "form-control input-md col-md-10");
                        txt.Attributes.Add("style", "width:80%; max-width:700px;");

                        if (hasAnswers)
                        {
                            var answr = q.QuestionResponses.FirstOrDefault(r => r.SurveyResponse.SurveyResponseId == response.SurveyResponseId);
                            if (answr != null)
                                txt.Text = answr.ResponseText;
                        }

                        if (mode == UtilityBL.Mode.ViewMode || mode == UtilityBL.Mode.ApproveMode)
                            txt.ReadOnly = true;

                        if (q.DependentonQuestion != null)
                            txt.Attributes.Add("disabled", "disabled");

                        divQuestionBody.Controls.Add(txt);
                    }
                }
            }
            if ((mode == UtilityBL.Mode.ViewMode || mode == UtilityBL.Mode.ApproveMode)
                && survey.SurveySections.Any(s => s.Questions.Any(q => q.QuestionOptions.Sum(o => o.Value ?? 0) > 0)))
            {
                score = response.QuestionResponses.Where(x => x.Question.SurveySection.SectionTypeId == (int)UtilityBL.SectionType.Patient)
                                            .Select(s => s.QuestionOption.Value).Sum(r => r.Value);

                var interpretation = _db.InterpretationDetails.FirstOrDefault(d => d.SurveyInterpretation.SurveyTitleId == response.SurveyTitleId
                                                                && d.ScoreRangeStart >= score && score <= d.ScoreRangeEnd);

                if (interpretation != null)
                {
                    pnlSurveyInterpretation.Visible = true;

                    lblScore.Text = score.ToString();
                    lblResult.Text = interpretation.Result;

                    if (!string.IsNullOrEmpty(interpretation.Action))
                        lblAction.Text = interpretation.Action;
                    else
                        lblACtionCaption.Visible = false;
                }
            }

            if (mode == UtilityBL.Mode.ApproveMode)
                DependetQuestionState(response, UtilityBL.SectionType.Doctor);
            else if (mode == UtilityBL.Mode.Entry)
                DependetQuestionState(response, UtilityBL.SectionType.Patient);
        }       
Пример #4
0
        private void SaveSelection(SurveyResponse surveyResponse,  UtilityBL.SectionType sectionType)
        {
           foreach (var section in surveyResponse.SurveyTitle.SurveySections.Where(s => s.SectionTypeId == (int)sectionType))
            {
                foreach (var question in section.Questions)
                {
                    int responseValue;
                    string responseText;
                    var ctrl = "ctrl" + question.QuestionId.ToString();

                    if (question.QuestionTypeId == 1)
                    {
                        var rdbList = Form.FindControl(ctrl) as RadioButtonList;
                        if (rdbList.SelectedValue != "" && rdbList.Enabled)
                        {
                            responseValue = Convert.ToInt32(rdbList.SelectedValue);
                            responseText = rdbList.SelectedItem.Text;

                            var answer = new QuestionResponse
                            {
                                QuestionId = question.QuestionId,
                                QuestionOptionId = responseValue,
                                ResponseText = responseText,
                                SurveyResponseId = surveyResponse.SurveyResponseId,
                            };

                            _db.QuestionResponses.Add(answer);
                            _db.SaveChanges();
                        }
                    }

                    if (question.QuestionTypeId == 2)
                    {
                        var chkList = Form.FindControl(ctrl) as CheckBoxList;
                        foreach (ListItem item in chkList.Items)
                        {
                            if (item.Selected)
                            {
                                responseValue = Convert.ToInt32(item.Value);
                                responseText = item.Text;

                                var answer = new QuestionResponse
                                {
                                    QuestionId = question.QuestionId,
                                    QuestionOptionId = responseValue,
                                    ResponseText = responseText,
                                    SurveyResponseId = surveyResponse.SurveyResponseId,
                                };

                                _db.QuestionResponses.Add(answer);
                                _db.SaveChanges();
                            }
                        }
                    }

                    if (question.QuestionTypeId == 3)
                    {
                        var txtBox = Form.FindControl(ctrl) as TextBox;
                        responseText = txtBox.Text;

                        var answer = new QuestionResponse
                        {
                            QuestionId = question.QuestionId,
                            ResponseText = responseText,
                            SurveyResponseId = surveyResponse.SurveyResponseId,
                        };

                        _db.QuestionResponses.Add(answer);
                        _db.SaveChanges();
                    }
                }
            }

        }
Пример #5
0
        // This is the Insert method to insert the entered Customer item
        // USAGE: <asp:FormView InsertMethod="InsertItem">
        public void InsertItem()
        {
            using (_db)
            {
                var item = new SurveyPortal.Data.Models.Customer();

                TryUpdateModel(item);

                var ddlGender = (DropDownList)Formview1.FindControl("ddlGender");
                if (ddlGender != null)
                    item.Gender = ddlGender.SelectedValue;

                if (string.IsNullOrWhiteSpace(item.Name))
                {
                    ModelState.AddModelError("Name", "Name cannot be blank");
                    UtilityBL.Alert("Name cannot be blank", this);
                }

                if (item.DOB==null)
                {
                    ModelState.AddModelError("DOB", "DOB cannot be blank");
                    UtilityBL.Alert("DOB cannot be blank", this);
                }

                if (string.IsNullOrWhiteSpace(item.Gender))
                {
                    ModelState.AddModelError("Gender", "Gender cannot be blank");
                    UtilityBL.Alert("Gender cannot be blank", this);
                }
                int doctorId=0;
                var ddlDoctor = (DropDownList)Formview1.FindControl("ddlDoctor");
                if (ddlDoctor != null)
                    doctorId = Convert.ToInt32(ddlDoctor.SelectedValue);

                if(doctorId==0)
                {
                  ModelState.AddModelError("Name", "Doctor needs to be selected");
                    UtilityBL.Alert("Doctor needs to be selected", this);
                }

                item.Active = true;

                if (ModelState.IsValid)
                {
                    // Save changes
                    _db.Customers.Add(item);
                    _db.SaveChanges();

                    var surveyResponse = new SurveyResponse
                    {
                        SurveyTitleId = Convert.ToInt32(ViewState["sid"]),
                        CustomerId = item.CustomerId,
                        ApproverUserId = doctorId
                    };

                    _db.SurveyResponses.Add(surveyResponse);
                    _db.SaveChanges();

                    Response.Redirect(string.Format("~/SurveyForm/{0}?rid={1}&m=entry", ViewState["url"].ToString(), surveyResponse.SurveyResponseId.ToString()));
                }
            }
        }