def _lookup_id_in_couch(doc_id, db_name=None):
    db_result = namedtuple('db_result', 'dbname result status')
    STATUSES = defaultdict(lambda: 'warning', {
        'missing': 'default',
        'deleted': 'danger',
    })

    if db_name:
        dbs = [couch_config.get_db(None if db_name == 'commcarehq' else db_name)]
    else:
        dbs = couch_config.all_dbs_by_slug.values()

    db_results = []
    response = {"doc_id": doc_id}
    for db in dbs:
        try:
            doc = db.get(doc_id)
        except ResourceNotFound as e:
            db_results.append(db_result(db.dbname, e.msg, STATUSES[e.msg]))
        else:
            db_results.append(db_result(db.dbname, 'found', 'success'))
            response.update({
                "doc": json.dumps(doc, indent=4, sort_keys=True),
                "doc_type": doc.get('doc_type', 'Unknown'),
                "dbname": db.dbname,
            })

    response['db_results'] = db_results
    return response
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/hqadmin/views.py/_lookup_id_in_couch/original