def compute_relation(proxy, relationData, hospital, disease): stack = Stack() root_node = model2relation(proxy, relationData.widget_id) root_node.level = relationData.level stack.push(root_node) while (False == stack.isEmpty()): node = stack.pop() node.children_node = [] children = proxy.query_for_relation_parent_detail(hospital, disease, node.widget_id).all() for child in children: child_node = model2relation(proxy, child.widget_id) child_node.level = child.level child_node.path = node.path + '|' + child_node.path stack.push(child_node) node.children_node.append(child_node) return root_node
def hierarchy_flat(data): stack = Stack() res = {} node = {} node['options'] = data.options node['desc'] = data.alias node['multi'] = data.is_repeatable node['tpl'] = data.tpl res[data.path] = node stack.push(data) while (False == stack.isEmpty()): parent_node = stack.pop(); for child in parent_node.children_node: tmp = {} tmp['options'] = child.options tmp['desc'] = child.alias tmp['multi'] = child.is_repeatable tmp['tpl'] = child.tpl res[child.path] = tmp stack.push(child) return res