Exemplo n.º 1
0
        private void CreateVariableFor(QuestionVM question, int questionIndex)
        {
            VariableGenerationInfo oldInfo = question.VariableGenerationInfo;
            VariableGenerationInfo newInfo = question.CreateVariableGenerationInfo();

            if (oldInfo != null && oldInfo.VariableGenerationType == newInfo.VariableGenerationType)
            {
                return;
            }
            question.VariableGenerationInfo = newInfo;

            // remove old variables
            List <VariableVM> generatedVariables = VariableVM.FindByQuestionId(Variables, question.Id);

            Debug.WriteLine(generatedVariables.Count);
            int removeIndex = Variables.Count;

            foreach (VariableVM variable in generatedVariables)
            {
                if (removeIndex == Variables.Count)
                {
                    removeIndex = Variables.IndexOf(variable);
                }
                StudyUnit.OnRemoveVariable(variable);
                Variables.Remove(variable);
            }

            // create single or multiple variables
            if (newInfo.VariableGenerationType == VariableGenerationType.SingleVariable)
            {
                CreateVariable((variableMovel) => {
                    variableMovel.Title = "V" + (questionIndex + 1);
                }, question, removeIndex);
            }
            else
            {
                CodeSchemeVM         codeScheme = question.Response.CodeScheme;
                ICollection <CodeVM> codes      = codeScheme.Codes;
                string variablePrefix           = "V" + (questionIndex + 1) + "_";
                foreach (CodeVM code in codes)
                {
                    CreateVariable((variableModel) => {
                        variableModel.Title                 = variablePrefix + code.Value;
                        variableModel.Label                 = code.Label;
                        variableModel.Response              = question.DupResponseModel();
                        variableModel.Response.TypeCode     = Options.RESPONSE_TYPE_CHOICES_CODE;
                        variableModel.Response.CodeSchemeId = StudyUnit.BinaryCodeSchemeId;
                    }, question, removeIndex++);
                }
            }
        }
Exemplo n.º 2
0
        public StatisticsTypes GetStatisticsType(VariableVM variable)
        {
            StatisticsTypes statisticsType = StatisticsTypes.Unknown;

            if (variable.IsResponseTypeDateTime)
            {
                statisticsType = StatisticsTypes.DateTime;
            }
            else if (variable.IsResponseTypeFree)
            {
                statisticsType = StatisticsTypes.Free;
            }
            else if (variable.IsResponseTypeNumber)
            {
                statisticsType = StatisticsTypes.Number;
            }
            else if (variable.IsResponseTypeChoices)
            {
                QuestionVM question = FindQuestion(variable.QuestionId);
                if (question != null && question.VariableGenerationInfo != null)
                {
                    VariableGenerationInfo generationInfo = question.VariableGenerationInfo;
                    if (generationInfo.VariableGenerationType == VariableGenerationType.MultipleVariable)
                    {
                        statisticsType = StatisticsTypes.ChoicesMultipleAnswer;
                    }
                    else if (generationInfo.VariableGenerationType == VariableGenerationType.SingleVariable)
                    {
                        statisticsType = StatisticsTypes.ChoicesSingleAnswer;
                    }
                }
                else
                {
                    statisticsType = StatisticsTypes.ChoicesSingleAnswer;
                }
            }
            return(statisticsType);
        }