def fixUsggapTableDims(lvl1Struct, level=0):
    foundTable = False
    emptyLinks = []
    foundHeadingItems = []
    foundLineItems = []
    for lvl1Entry in lvl1Struct:
        for lvl2Entry in lvl1Entry.childStruct:
            if any((lvl2Entry.name.endswith(suffix) for suffix in ('Table', '_table', 'Cube', '_cube'))):
                for lvl3Entry in lvl2Entry.childStruct:
                    if any((lvl3Entry.name.endswith(suffix) for suffix in ('LineItems', '_line_items'))):
                        foundLineItems.append((lvl1Entry, lvl2Entry, lvl3Entry))
                        foundTable = True
                        break
            else:
                foundHeadingItems.append((lvl1Entry, lvl2Entry))
        if (not foundLineItems):
            foundNestedTable = fixUsggapTableDims(lvl1Entry.childStruct, (level + 1))
            if ((level == 0) and (not foundNestedTable)):
                emptyLinks.append(lvl1Entry)
            foundTable |= foundNestedTable
            del foundHeadingItems[:]
    for (lvl1Entry, lvl2Entry, lvl3Entry) in foundLineItems:
        i1 = lvl1Entry.childStruct.index(lvl2Entry)
        lvl1Entry.childStruct.insert(i1, lvl3Entry)
        lvl3Entry.childStruct.insert(0, lvl2Entry)
        if any((lvl1Entry.name.endswith(suffix) for suffix in ('Abstract', '_abstract', 'Root', '_root', '_package', '_heading'))):
            lvl1Entry.childStruct.remove(lvl2Entry)
        lvl2Entry.childStruct.remove(lvl3Entry)
    for (lvl1Entry, lvl2Entry) in foundHeadingItems:
        lvl1Entry.childStruct.remove(lvl2Entry)
    for emptyLink in emptyLinks:
        lvl1Struct.remove(emptyLink)
    return foundTable
def fixUsggapTableDims(lvl1Struct, level=0):
    foundTable = False
    emptyLinks = []
    foundHeadingItems = []
    foundLineItems = []
    for lvl1Entry in lvl1Struct:
        for lvl2Entry in lvl1Entry.childStruct:
            if any((lvl2Entry.name.endswith(suffix) for suffix in ('Table', '_table', 'Cube', '_cube'))):
                for lvl3Entry in lvl2Entry.childStruct:
                    if any((lvl3Entry.name.endswith(suffix) for suffix in ('LineItems', '_line_items'))):
                        foundLineItems.append((lvl1Entry, lvl2Entry, lvl3Entry))
                        foundTable = True
                        break
            else:
                foundHeadingItems.append((lvl1Entry, lvl2Entry))
        if (not foundLineItems):
            foundNestedTable = fixUsggapTableDims(lvl1Entry.childStruct, (level + 1))
            if ((level == 0) and (not foundNestedTable)):
                emptyLinks.append(lvl1Entry)
            foundTable |= foundNestedTable
            del foundHeadingItems[:]
    for (lvl1Entry, lvl2Entry, lvl3Entry) in foundLineItems:
        i1 = lvl1Entry.childStruct.index(lvl2Entry)
        lvl1Entry.childStruct.insert(i1, lvl3Entry)
        lvl3Entry.childStruct.insert(0, lvl2Entry)
        if any((lvl1Entry.name.endswith(suffix) for suffix in ('Abstract', '_abstract', 'Root', '_root', '_package', '_heading'))):
            lvl1Entry.childStruct.remove(lvl2Entry)
        lvl2Entry.childStruct.remove(lvl3Entry)
    for (lvl1Entry, lvl2Entry) in foundHeadingItems:
        lvl1Entry.childStruct.remove(lvl2Entry)
    for emptyLink in emptyLinks:
        lvl1Struct.remove(emptyLink)
    return foundTable