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
        private void CreateVariable(Action <Variable> action, QuestionVM question, int removeIndex)
        {
            Variable variableModel = new Variable();

            variableModel.Label      = question.Title;
            variableModel.ConceptId  = question.Question.ConceptId;
            variableModel.QuestionId = question.Id;
            variableModel.UniverseId = StudyUnit.DefaultUniverseGuid;
            variableModel.Response   = question.DupResponseModel();
            action(variableModel);

            variableModel.Response.Title      = null; //Stay this null because the title in Response Style of variables cannot be set.
            variableModel.GeneratorQuestionId = question.Id;

            VariableVM newVariable = new VariableVM(variableModel);

            InitVariable(newVariable);
            newVariable.Response = CreateResponse(variableModel.Response);
            Variables.Insert(removeIndex, newVariable);
        }