示例#1
0
        private void WriteCategoryQuestionAnswer(SchemeQuestionWithChildQuestionsDto schemeQuestion,
                                                 CodedQuestionBase codedQuestion)
        {
            var orderedSchemeAnswers = schemeQuestion.PossibleAnswers.OrderBy(x => x.Order).ToList();

            foreach (var schemeAnswer in orderedSchemeAnswers)
            {
                var field = "NA";
                if (codedQuestion != null && codedQuestion.CodedAnswers.Count != 0)
                {
                    var codedAnswer = codedQuestion.CodedAnswers.SingleOrDefault(x => x.SchemeAnswerId == schemeAnswer.Id);
                    if (codedAnswer != null)
                    {
                        field = _codedTextExport ? schemeAnswer.Text : "1";
                    }
                    else
                    {
                        field = _codedTextExport ? "" : "0";
                    }

                    _csvWriter.WriteField(field);
                    WritePincite(codedAnswer);
                    WriteAnnotation(codedAnswer);
                }
                else
                {
                    _csvWriter.WriteField(field);
                    WritePincite(null);
                    WriteAnnotation(null);
                }
            }
        }
示例#2
0
        private async Task <int> WriteCategoriesQuestionAnswer(SchemeQuestionWithChildQuestionsDto schemeQuestion)
        {
            var error = ExportResult.NoError;

            foreach (var category in _schemeCategories)
            {
                _schemeCategory = category;
                dynamic codedQuestion;
                if (_validated)
                {
                    codedQuestion =
                        await _unitOfWork.ValidatedCategoryQuestions.SingleOrDefaultAsync(vcq =>
                                                                                          vcq.ProjectJurisdiction.Id == _projectJurisdiction.Id &&
                                                                                          vcq.SchemeQuestion.Id == schemeQuestion.Id && vcq.Category.Id == _schemeCategory.Id);
                }
                else
                {
                    codedQuestion =
                        await _unitOfWork.CodedCategoryQuestions.SingleOrDefaultAsync(vcq =>
                                                                                      vcq.ProjectJurisdiction.Id == _projectJurisdiction.Id &&
                                                                                      vcq.SchemeQuestion.Id == schemeQuestion.Id && vcq.Category.Id == _schemeCategory.Id && vcq.CodedBy.Id == _userId);
                }

                error = WriteQuestionAnswer(schemeQuestion, codedQuestion);

                if (error != ExportResult.NoError)
                {
                    return(error);
                }
            }

            return(error);
        }
示例#3
0
        /// <summary>
        /// Determines the type of question and then calls the appropriate method to write the header
        /// </summary>
        /// <param name="schemeQuestion"></param>
        private int WriteSchemeQuestionHeader(SchemeQuestionWithChildQuestionsDto schemeQuestion)
        {
            var errorCode = ExportResult.NoError;

            switch (schemeQuestion.QuestionType)
            {
            case QuestionType.Binary:
                WriteBinaryQuestionHeader(schemeQuestion);
                break;

            case QuestionType.Category:
                errorCode = WriteCategoryQuestionHeader(schemeQuestion);
                break;

            case QuestionType.Checkbox:
                errorCode = WriteCheckboxQuestionHeader(schemeQuestion);
                break;

            case QuestionType.MultipleChoice:
                WriteMultipleChoiceQuestionHeader(schemeQuestion);
                break;

            case QuestionType.TextField:
                WriteTextFieldQuestionHeader(schemeQuestion);
                break;

            default:
                errorCode = ExportResult.HeaderInvalidQuestionType;
                break;
            }

            return(errorCode);
        }
示例#4
0
        /// <summary>
        /// Given a category scheme question, write the header
        /// </summary>
        /// <param name="schemeQuestion"></param>
        private int WriteCategoryQuestionHeader(SchemeQuestionWithChildQuestionsDto schemeQuestion)
        {
            var categoryCount = schemeQuestion.PossibleAnswers.Count;

            for (var index = 1; index <= categoryCount; index++)
            {
                var header = "";
                try
                {
                    var answer = schemeQuestion.PossibleAnswers.Single(pa => pa.Order == index);
                    header = QuestionHeaderString() + CategoryHeaderPrefix + answer.Order;
                }
                catch (InvalidOperationException)
                {
                    _result.Code = ExportResult.CategoryHeaderInvalidOperation;
                    return(_result.Code);
                }
                catch (ArgumentNullException)
                {
                    _result.Code = ExportResult.CategoryHeaderArgumentNull;
                    return(_result.Code);
                }

                WriteHeader(header);
                WriteAnnotationHeader(header);
            }

            if (schemeQuestion.IncludeComment)
            {
                WriteCommentHeader();
            }

            return(ExportResult.NoError);
        }
示例#5
0
        private void WriteCodebookQuestionEntry(SchemeQuestionWithChildQuestionsDto question, string questionNumber,
                                                string answerVariableLabel, string questionType, string questionText, string valueLabel, string value)
        {
            questionNumber = questionNumber.Replace("c", ".");
            _csvWriter.WriteField(questionNumber);

            // write answer variable correctly for children of category/tabbed questions
            if (_schemeCategory != null)
            {
                answerVariableLabel = answerVariableLabel + CategoryHeaderPrefix + _schemeCategory.Order;
            }
            _csvWriter.WriteField(answerVariableLabel);

            _csvWriter.WriteField(questionType);
            _csvWriter.WriteField(questionText);
            if (question.QuestionType == QuestionType.TextField)
            {
                _csvWriter.WriteField("[text]");
            }
            else
            {
                _csvWriter.WriteField(valueLabel);
            }
            _csvWriter.WriteField(value);

            _csvWriter.NextRecord();
        }
示例#6
0
        public async Task <List <long> > DeleteSchemeQuestionAndAllNestedQuestions(SchemeQuestionWithChildQuestionsDto question)
        {
            var deletedQuestionIds = new List <long>();

            if (question == null)
            {
                return(deletedQuestionIds);
            }

            if (question.ChildQuestions != null && question.ChildQuestions.Count != 0)
            {
                foreach (var childQuestion in question.ChildQuestions)
                {
                    deletedQuestionIds.Add(childQuestion.Id);
                    await DeleteSchemeQuestionAndAllNestedQuestions(childQuestion);
                }
            }

            if (await DeleteDataAssociatedWithSchemeQuestion(question.Id))
            {
                deletedQuestionIds.Add(question.Id);
                var schemeQuestion =
                    await _unitOfWork.SchemeQuestions.SingleOrDefaultAsync(sq => sq.Id == question.Id);

                _unitOfWork.SchemeQuestions.Remove(schemeQuestion);
            }


            return(deletedQuestionIds);
        }
示例#7
0
        private int WriteCheckboxQuestionAnswer(SchemeQuestionWithChildQuestionsDto schemeQuestion,
                                                CodedQuestionBase codedQuestion)
        {
            var orderedSchemeAnswers = schemeQuestion.PossibleAnswers.OrderBy(x => x.Order).ToList();

            foreach (var schemeAnswer in orderedSchemeAnswers)
            {
                var field = "NA";

                if (WroteCategoryNotSelectedAnswer())
                {
                    continue;
                }

                if (codedQuestion == null || codedQuestion.CodedAnswers.Count == 0)
                {
                    _csvWriter.WriteField(field);
                    WritePincite(null);
                    WriteAnnotation(null);
                    continue;
                }

                try
                {
                    var codedAnswer = codedQuestion.CodedAnswers.SingleOrDefault(x => x.SchemeAnswerId == schemeAnswer.Id);
                    if (codedAnswer != null)
                    {
                        field = _codedTextExport ? schemeAnswer.Text : "1";
                    }
                    else
                    {
                        field = _codedTextExport ? "" : "0";
                    }

                    _csvWriter.WriteField(field);
                    WritePincite(codedAnswer);
                    WriteAnnotation(codedAnswer);
                }
                catch (InvalidOperationException)
                {
                    _result.SetError(ExportResult.BinaryAnswerInvalidOperation);
                    return(_result.Code);
                }
                catch (ArgumentNullException)
                {
                    _result.SetError(ExportResult.BinaryAnswerArgumentNull);
                    return(_result.Code);
                }
            }

            return(ExportResult.NoError);
        }
示例#8
0
        /// <summary>
        /// Write the header for each category for a given question
        /// </summary>
        /// <param name="schemeQuestion"></param>
        private int WriteSchemeCategoryQuestionHeader(SchemeQuestionWithChildQuestionsDto schemeQuestion)
        {
            foreach (var category in _schemeCategories)
            {
                _schemeCategory = category;
                var error = WriteSchemeQuestionHeader(schemeQuestion);
                if (error < ExportResult.NoError)
                {
                    return(error);
                }
            }

            return(ExportResult.NoError);
        }
示例#9
0
        private int WriteCategoryQuestionCodebookEntries(SchemeQuestionWithChildQuestionsDto categoryQuestion)
        {
            foreach (var category in _schemeCategories)
            {
                _schemeCategory = category;
                var error = WriteQuestionCodebookEntries(categoryQuestion);
                if (error < ExportResult.NoError)
                {
                    return(error);
                }
            }

            return(ExportResult.NoError);
        }
示例#10
0
        /// <summary>
        /// Given a text field scheme question, write the header
        /// </summary>
        /// <param name="schemeQuestion"></param>
        private void WriteTextFieldQuestionHeader(SchemeQuestionWithChildQuestionsDto schemeQuestion)
        {
            var header = "";

            if (_schemeCategory == null)
            {
                header = QuestionHeaderString();
            }
            else
            {
                header = QuestionHeaderString() + CategoryHeaderPrefix + _schemeCategory.Order;
            }

            WriteHeader(header);
            WriteAnnotationHeader(header);
            if (schemeQuestion.IncludeComment)
            {
                WriteCommentHeader();
            }
        }
示例#11
0
        /// <summary>
        /// Given a checkbox scheme question, write the header
        /// </summary>
        /// <param name="schemeQuestion"></param>
        private int WriteCheckboxQuestionHeader(SchemeQuestionWithChildQuestionsDto schemeQuestion)
        {
            var choicesCount = schemeQuestion.PossibleAnswers.Count;

            for (var index = 1; index <= choicesCount; index++)
            {
                try
                {
                    var header = "";
                    var answer = schemeQuestion.PossibleAnswers.Single(pa => pa.Order == index);
                    if (_schemeCategory == null)
                    {
                        header = QuestionHeaderString() + AnswerHeaderPrefix + answer.Order;
                    }
                    else
                    {
                        header = QuestionHeaderString() + AnswerHeaderPrefix + answer.Order
                                 + CategoryHeaderPrefix + _schemeCategory.Order;
                    }
                    WriteHeader(header);
                    WriteAnnotationHeader(header);
                }
                catch (InvalidOperationException)
                {
                    _result.SetError(ExportResult.CheckboxHeaderInvalidOperation);
                    return(_result.Code);
                }
                catch (ArgumentNullException)
                {
                    _result.SetError(ExportResult.CheckboxHeaderArgumentNull);
                    return(_result.Code);
                }
            }

            if (schemeQuestion.IncludeComment)
            {
                WriteCommentHeader();
            }

            return(ExportResult.NoError);
        }
示例#12
0
        private int WriteQuestionAnswer(SchemeQuestionWithChildQuestionsDto schemeQuestion,
                                        CodedQuestionBase codedQuestion)
        {
            var errorCode = ExportResult.NoError;

            switch (schemeQuestion.QuestionType)
            {
            case QuestionType.Binary:
                errorCode = WriteBinaryQuestionAnswer(codedQuestion);
                break;

            case QuestionType.Category:
                WriteCategoryQuestionAnswer(schemeQuestion, codedQuestion);
                break;

            case QuestionType.Checkbox:
                errorCode = WriteCheckboxQuestionAnswer(schemeQuestion, codedQuestion);
                break;

            case QuestionType.MultipleChoice:
                errorCode = WriteMultipleChoiceQuestionAnswer(codedQuestion);
                break;

            case QuestionType.TextField:
                errorCode = WriteTextFieldQuestionAnswer(codedQuestion);
                break;

            default:
                errorCode = ExportResult.AnswerInvalidQuestionType;
                break;
            }
            if (schemeQuestion.IncludeComment)
            {
                WriteQuestionComment(codedQuestion);
            }

            return(errorCode);
        }
示例#13
0
        private int WriteQuestionCodebookEntries(SchemeQuestionWithChildQuestionsDto question)
        {
            var questionNumber        = _outlineNumber;
            var questionText          = question.Text;
            var questionVariableLabel = "";
            var questionType          = "";
            var possibleAnswers       = question.PossibleAnswers.OrderBy(x => x.Order).ToImmutableList();



            switch (question.QuestionType)
            {
            case QuestionType.Binary:
                questionType          = "Binary";
                questionVariableLabel = QuestionHeaderString();
                break;

            case QuestionType.Category:
                questionType          = "Tabbed";
                questionVariableLabel = QuestionHeaderString() + CategoryHeaderPrefix;
                break;

            case QuestionType.Checkbox:
                questionType          = "Checkbox";
                questionVariableLabel = QuestionHeaderString() + AnswerHeaderPrefix;
                break;

            case QuestionType.MultipleChoice:
                questionType          = "Radio Button";
                questionVariableLabel = QuestionHeaderString();
                break;

            case QuestionType.TextField:
                questionType          = "Text Field";
                questionVariableLabel = QuestionHeaderString();
                break;

            default:
                break;
            }


            foreach (var answer in possibleAnswers)
            {
                switch (question.QuestionType)
                {
                case QuestionType.Binary:
                    var value = answer.Order == 1 ? "1" : "0";
                    WriteCodebookQuestionEntry(question, questionNumber, questionVariableLabel, questionType,
                                               questionText, answer.Text, value);
                    break;

                case QuestionType.Category:
                    var answerVariableLabel = questionVariableLabel + answer.Order;
                    WriteCodebookQuestionEntry(question, questionNumber, answerVariableLabel, questionType,
                                               questionText, answer.Text, answer.Order.ToString());
                    break;

                case QuestionType.Checkbox:
                    answerVariableLabel = questionVariableLabel + answer.Order;
                    WriteCodebookQuestionEntry(question, questionNumber, answerVariableLabel, questionType,
                                               questionText, answer.Text, "1");
                    WriteCodebookQuestionEntry(question, questionNumber, answerVariableLabel, questionType,
                                               questionText, "[blank]", "0");
                    break;

                default:
                    answerVariableLabel = questionVariableLabel;
                    WriteCodebookQuestionEntry(question, questionNumber, answerVariableLabel, questionType,
                                               questionText, answer.Text, answer.Order.ToString());
                    break;
                }
            }

            return(0);
        }