def get_hierarchy(settings):
    '''
    Gets main mapping source according to what a data classification is made
    Gets the hierarchy groups (only for GUI)
    Gets the hierarchy values
    '''
    hierarchy, hierarchy_groups, hierarchy_values = [], [], {}
    hgroup_ids, enumerated_vals = {}, set()
    session = connect_database(settings)
    for item in session.query(model.Hierarchy_value).all():
        try:
            hierarchy_values[item.cid].update({item.num: item.name})
        except KeyError:
            hierarchy_values[item.cid] = {item.num: item.name}
        enumerated_vals.add(item.cid)
    try:
        for item in session.query(model.Hierarchy).all():
            if item.has_facet and not item.has_topic: raise RuntimeError('Fatal error: "has_facet" implies "has_topic"')
            if item.slider and not '.' in item.slider: raise RuntimeError('Fatal error: "has_slider" must have a reference to some table field')
            hierarchy.append({
                'cid':item.cid,
                'category':item.name,
                'source':item.source,
                'html':item.html,
                'has_slider':item.slider,
                'sort':item.sort,
                'multiple':item.multiple,
                'optional':item.optional,
                'has_summary_contrb':item.has_summary_contrb,
                'has_column':item.has_column,
                'has_facet':item.has_facet,
                'creates_topic':item.has_topic,
                'is_chem_formula':item.chem_formula,
                'plottable':item.plottable,
                'enumerated':True if item.cid in enumerated_vals else False
            })
            try: hgroup_ids[item.hgroup_id].append(item.cid)
            except KeyError: hgroup_ids[item.hgroup_id] = [item.cid]
    except RuntimeError as e:
        session.close()
        sys.exit(e)
    for item in session.query(model.Hierarchy_group).all():
        hierarchy_groups.append({
            'id': item.hgroup_id,
            'category': item.name,
            'html_pocket': '', # specially for JavaScript client
            'landing_group': item.landing_group,
            'settings_group': item.settings_group,
            'includes': hgroup_ids[item.hgroup_id]
        })
    session.close()
    return hierarchy, hierarchy_groups, hierarchy_values