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_block(self, schema, questionnaire): """Parse a block element :param schema: The block schema :returns: A Block object :raises: SchemaParserException """ block = Block() try: block.id = ParserUtils.get_required_string(schema, "id") block.title = ParserUtils.get_optional_string(schema, "title") block.routing_rules = ParserUtils.get_optional_array(schema, 'routing_rules') # register the block questionnaire.register(block) except Exception as e: logging.error('Error parsing schema') logging.info(e) raise e if "sections" in schema.keys(): for section_schema in schema['sections']: block.add_section(self._parse_section(section_schema, questionnaire)) else: raise SchemaParserException('Block must contain at least one section') return block
def _parse_introduction(self, intro_schema): introduction = Introduction() introduction.legal = ParserUtils.get_optional_string(intro_schema, 'legal') introduction.description = ParserUtils.get_optional_string(intro_schema, 'description') introduction.information_to_provide = ParserUtils.get_optional_array(intro_schema, 'information_to_provide') return introduction
def _parse_introduction(intro_schema): introduction = Introduction() introduction.legal = ParserUtils.get_optional_string( intro_schema, 'legal') introduction.description = ParserUtils.get_optional_string( intro_schema, 'description') introduction.information_to_provide = ParserUtils.get_optional_array( intro_schema, 'information_to_provide') return introduction
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