/// <summary>
        /// Select a list of all possible incident questions
        /// </summary>
        public static List <EHSIncidentQuestion> SelectIncidentQuestionList()
        {
            var questionList = new List <EHSIncidentQuestion>();

            try
            {
                var entities     = new PSsqmEntities();
                var allQuestions = (from q in entities.INCIDENT_QUESTION select q).ToList();

                foreach (var q in allQuestions)
                {
                    var typeInfo = (from ti in entities.INCIDENT_QUESTION_TYPE
                                    where q.INCIDENT_QUESTION_TYPE_ID == ti.INCIDENT_QUESTION_TYPE_ID
                                    select ti).FirstOrDefault();

                    var newQuestion = new EHSIncidentQuestion()
                    {
                        QuestionId         = q.INCIDENT_QUESTION_ID,
                        QuestionText       = q.QUESTION_TEXT,
                        QuestionType       = (EHSIncidentQuestionType)q.INCIDENT_QUESTION_TYPE_ID,
                        HasMultipleChoices = typeInfo.HAS_MULTIPLE_CHOICES,
                        HelpText           = q.HELP_TEXT
                    };

                    if (newQuestion.HasMultipleChoices)
                    {
                        List <EHSIncidentAnswerChoice> choices = (from qc in entities.INCIDENT_QUESTION_CHOICE
                                                                  where qc.INCIDENT_QUESTION_ID == q.INCIDENT_QUESTION_ID
                                                                  orderby qc.SORT_ORDER
                                                                  select new EHSIncidentAnswerChoice
                        {
                            Value = qc.QUESTION_CHOICE_VALUE,
                            IsCategoryHeading = qc.IS_CATEGORY_HEADING
                        }).ToList();
                        if (choices.Count > 0)
                        {
                            newQuestion.AnswerChoices = choices;
                        }
                    }
                    questionList.Add(newQuestion);
                }

                questionList.OrderBy(field => field.QuestionText);
                questionList.OrderBy(field => field.QuestionType);
            }
            catch (Exception e)
            {
                //SQMLogger.LogException(e);
            }

            return(questionList);
        }
        /// <summary>
        /// Select a list of all incident questions by company and incident type
        /// </summary>
        public static List <EHSIncidentQuestion> SelectIncidentQuestionList(decimal incidentTypeId, decimal companyId, int step)
        {
            var questionList = new List <EHSIncidentQuestion>();

            try
            {
                var entities           = new PSsqmEntities();
                var activeQuestionList = (from q in entities.INCIDENT_TYPE_COMPANY_QUESTION
                                          where q.INCIDENT_TYPE_ID == incidentTypeId && q.COMPANY_ID == companyId && q.STEP == step
                                          orderby q.SORT_ORDER
                                          select q
                                          ).ToList();

                foreach (var aq in activeQuestionList)
                {
                    var questionInfo = (from qi in entities.INCIDENT_QUESTION
                                        where qi.INCIDENT_QUESTION_ID == aq.INCIDENT_QUESTION_ID
                                        select qi).FirstOrDefault();

                    var typeInfo = (from ti in entities.INCIDENT_QUESTION_TYPE
                                    where questionInfo.INCIDENT_QUESTION_TYPE_ID == ti.INCIDENT_QUESTION_TYPE_ID
                                    select ti).FirstOrDefault();

                    var newQuestion = new EHSIncidentQuestion()
                    {
                        QuestionId         = questionInfo.INCIDENT_QUESTION_ID,
                        QuestionText       = questionInfo.QUESTION_TEXT,
                        QuestionType       = (EHSIncidentQuestionType)questionInfo.INCIDENT_QUESTION_TYPE_ID,
                        HasMultipleChoices = typeInfo.HAS_MULTIPLE_CHOICES,
                        IsRequired         = questionInfo.IS_REQUIRED,
                        IsRequiredClose    = questionInfo.IS_REQUIRED_CLOSE,
                        HelpText           = questionInfo.HELP_TEXT,
                        StandardType       = questionInfo.STANDARD_TYPE
                    };

                    if (newQuestion.HasMultipleChoices)
                    {
                        List <EHSIncidentAnswerChoice> choices = (from qc in entities.INCIDENT_QUESTION_CHOICE
                                                                  where qc.INCIDENT_QUESTION_ID == questionInfo.INCIDENT_QUESTION_ID
                                                                  orderby qc.SORT_ORDER
                                                                  select new EHSIncidentAnswerChoice
                        {
                            Value = qc.QUESTION_CHOICE_VALUE,
                            IsCategoryHeading = qc.IS_CATEGORY_HEADING
                        }).ToList();
                        if (choices.Count > 0)
                        {
                            newQuestion.AnswerChoices = choices;
                        }
                    }

                    // Question control logic
                    newQuestion.QuestionControls = (from qc in entities.INCIDENT_QUESTION_CONTROL
                                                    where qc.INCIDENT_TYPE_ID == incidentTypeId &&
                                                    qc.COMPANY_ID == companyId &&
                                                    qc.INCIDENT_QUESTION_ID == newQuestion.QuestionId
                                                    orderby qc.PROCESS_ORDER
                                                    select qc).ToList();

                    questionList.Add(newQuestion);
                }
            }
            catch (Exception e)
            {
                //SQMLogger.LogException(e);
            }

            return(questionList);
        }