(cls, root_group_schema, forms, repeats)
return [subcase_schema] if subcase_schema.group_schemas else []
Updates the root_group_schema in place and also returns a new schema for subcases
        in repeats (if any).

        :param root_group_schema:
        :param forms: List of forms. Assume all have the same XMLNS
        :param repeats: List of repeat paths in the form.
        :return: FormDataExportSchema containing one group schema for each
Updates the root_group_schema in place and also returns a new schema for subcases
        in repeats (if any).
Updates the root_group_schema in place and also returns a new schema for subcases in repeats ( if any ) .
def _add_export_items_for_cases(cls, root_group_schema, forms, repeats):
        """Updates the root_group_schema in place and also returns a new schema for subcases
        in repeats (if any).

        :param root_group_schema:
        :param forms: List of forms. Assume all have the same XMLNS
        :param repeats: List of repeat paths in the form.
        :return: FormDataExportSchema containing one group schema for each
        """
        assert root_group_schema.path == []

        case_updates = OrderedSet()
        for form in forms:
            for update in form.get_case_updates_for_case_type(form.get_module().case_type):
                case_updates.add(update)

        for form in forms:
            if not form.uses_cases:
                continue

            if form.form_type == 'module_form':
                case_properties = {}
                actions = form.active_actions()
                if 'open_case' in actions:
                    action = actions['open_case']
                    if 'external_id' in action and action.external_id:
                        case_properties['external_id'] = action.external_id
                if 'update_case' in actions:
                    case_properties.update(actions['update_case'].update)

                cls._add_export_items_for_case(
                    root_group_schema, '/data', case_properties,
                    'case', repeats=[], create='open_case' in actions, close='close_case' in actions
                )

                if 'usercase_update' in actions and actions['usercase_update'].update:
                    cls._add_export_items_for_case(
                        root_group_schema, '/data/commcare_usercase', actions['usercase_update'].update,
                        'case', repeats=[], create='open_case' in actions, close='close_case' in actions
                    )
            else:
                all_actions = [form.actions]
                if hasattr(form, 'extra_actions'):
                    # shadow forms can have extra actions
                    all_actions.append(form.extra_actions)
                for actions in all_actions:
                    for action in actions.load_update_cases:
                        cls._add_export_items_for_case(
                            root_group_schema, '/data/{}'.format(action.form_element_name),
                            action.case_properties, action.case_tag, repeats=[],
                            create=False, close=action.close_condition.is_active()
                        )

                    for action in actions.open_cases:
                        if not action.is_subcase:
                            cls._add_export_items_for_case(
                                root_group_schema, '/data/{}'.format(action.form_element_name),
                                action.case_properties, action.case_tag, repeats=[],
                                create=True, close=action.close_condition.is_active()
                            )

        subcase_schema = cls()
        for form in forms:
            if isinstance(form.actions, AdvancedFormActions):
                actions = list(form.actions.get_open_subcase_actions())
            else:
                actions = list(form.actions.get_subcases())

            repeat_context_count = form.actions.count_subcases_per_repeat_context()

            for subcase_action in actions:
                if subcase_action.repeat_context:
                    root_path = subcase_action.repeat_context
                    if repeat_context_count[subcase_action.repeat_context] > 1:
                        root_path = '{}/{}'.format(root_path, subcase_action.form_element_name)

                    group_schema = ExportGroupSchema(
                        path=_question_path_to_path_nodes(root_path, repeats),
                        last_occurrences=root_group_schema.last_occurrences,
                    )
                    subcase_schema.group_schemas.append(group_schema)
                    cls._add_export_items_from_subcase_action(group_schema, root_path, subcase_action, repeats)
                else:
                    root_path = "/data/{}".format(subcase_action.form_element_name)  # always nest in root
                    cls._add_export_items_from_subcase_action(root_group_schema, root_path, subcase_action, [])

        return [subcase_schema] if subcase_schema.group_schemas else []
def _add_export_items_for_cases ( cls , root_group_schema , forms , repeats ) : assert root_group_schema . path == [ ] case_updates = OrderedSet ( ) for form in forms : for update in form . get_case_updates_for_case_type ( form . get_module ( ) . case_type ) : case_updates . add ( update ) for form in forms : if not form . uses_cases : continue if form . form_type == 'module_form' : case_properties = { } actions = form . active_actions ( ) if 'open_case' in actions : action = actions [ 'open_case' ] if 'external_id' in action and action . external_id : case_properties [ 'external_id' ] = action . external_id if 'update_case' in actions : case_properties . update ( actions [ 'update_case' ] . update ) cls . _add_export_items_for_case ( root_group_schema , '/data' , case_properties , 'case' , repeats = [ ] , create = 'open_case' in actions , close = 'close_case' in actions ) if 'usercase_update' in actions and actions [ 'usercase_update' ] . update : cls . _add_export_items_for_case ( root_group_schema , '/data/commcare_usercase' , actions [ 'usercase_update' ] . update , 'case' , repeats = [ ] , create = 'open_case' in actions , close = 'close_case' in actions ) else : all_actions = [ form . actions ] if hasattr ( form , 'extra_actions' ) : # shadow forms can have extra actions all_actions . append ( form . extra_actions ) for actions in all_actions : for action in actions . load_update_cases : cls . _add_export_items_for_case ( root_group_schema , '/data/{}' . format ( action . form_element_name ) , action . case_properties , action . case_tag , repeats = [ ] , create = False , close = action . close_condition . is_active ( ) ) for action in actions . open_cases : if not action . is_subcase : cls . _add_export_items_for_case ( root_group_schema , '/data/{}' . format ( action . form_element_name ) , action . case_properties , action . case_tag , repeats = [ ] , create = True , close = action . close_condition . is_active ( ) ) subcase_schema = cls ( ) for form in forms : if isinstance ( form . actions , AdvancedFormActions ) : actions = list ( form . actions . get_open_subcase_actions ( ) ) else : actions = list ( form . actions . get_subcases ( ) ) repeat_context_count = form . actions . count_subcases_per_repeat_context ( ) for subcase_action in actions : if subcase_action . repeat_context : root_path = subcase_action . repeat_context if repeat_context_count [ subcase_action . repeat_context ] > 1 : root_path = '{}/{}' . format ( root_path , subcase_action . form_element_name ) group_schema = ExportGroupSchema ( path = _question_path_to_path_nodes ( root_path , repeats ) , last_occurrences = root_group_schema . last_occurrences , ) subcase_schema . group_schemas . append ( group_schema ) cls . _add_export_items_from_subcase_action ( group_schema , root_path , subcase_action , repeats ) else : root_path = "/data/{}" . format ( subcase_action . form_element_name ) # always nest in root cls . _add_export_items_from_subcase_action ( root_group_schema , root_path , subcase_action , [ ] ) return [ subcase_schema ] if subcase_schema . group_schemas else [ ]