def _parse_answer(self, schema, questionnaire): """Parse a answer element :param schema: The answer schema :returns: A Answer object :raises: SchemaParserException """ answer_type = ParserUtils.get_required_string(schema, 'type') answer_id = ParserUtils.get_required_string(schema, 'id') answer = self.answer_factory.create(answer_type.upper(), answer_id) answer.type = answer_type answer.code = ParserUtils.get_optional_string(schema, 'q_code') answer.label = ParserUtils.get_optional_string(schema, 'label') answer.description = ParserUtils.get_optional_string( schema, 'description') answer.guidance = ParserUtils.get_optional_string(schema, 'guidance') answer.mandatory = ParserUtils.get_required_boolean( schema, 'mandatory') answer.options = ParserUtils.get_optional_array(schema, 'options') answer.alias = ParserUtils.get_optional_string(schema, 'alias') if 'validation' in schema.keys(): self._parse_validation(answer, schema['validation']) # register the answer questionnaire.register(answer) return answer
def _parse_answer(self, schema, questionnaire): """Parse a answer element :param schema: The answer schema :returns: A Answer object :raises: SchemaParserException """ try: answer_type = ParserUtils.get_required_string(schema, 'type') answer_id = ParserUtils.get_required_string(schema, 'id') answer = self.answer_factory.create(answer_type.upper(), answer_id) answer.type = answer_type answer.code = ParserUtils.get_required_string(schema, 'q_code') answer.label = ParserUtils.get_optional_string(schema, 'label') answer.guidance = ParserUtils.get_optional_string(schema, 'guidance') answer.mandatory = ParserUtils.get_required_boolean(schema, 'mandatory') answer.options = ParserUtils.get_optional_array(schema, 'options') answer.alias = ParserUtils.get_optional_string(schema, 'alias') display = ParserUtils.get_optional(schema, "display") if display: answer.display = self._parse_display(display) if 'validation' in schema.keys(): self._parse_validation(answer, schema['validation']) # register the answer questionnaire.register(answer) except Exception as e: logging.error('Error parsing schema') logging.info(e) raise e return answer