def add_clinic():
    # medicaldb_clinic
    sql = 'select id,name,abbr from medicaldb_clinic;'
    id_prefix = "clinic_"
    o = get_medical_entity_handler(False).do_one(sql)

    docs = []

    for item in o:
        id = item[0]
        name = item[1].lower().replace(" ", "")
        abbr = item[2].lower().replace(" ", "")
        name_list = [name, abbr] if abbr else [name]
        docs.append(
            {
                "id": id_prefix + str(id),
                "name": name_list,
                "name_string": name_list,
                "type": "clinic",
                "timestamp": int(time.time() * 1000)
            }
        )

    solr = SolrCloud(ZooKeeper("md4:2181"), "simple_medical_entity")
    add_all(docs, solr)
def add_bdpart():
    '''
    fields:
     id : "bodypart_1231231"
     name : ["眼睛"]
     type: "bodypart"
    '''

    sql = 'select id,name,abbr from medicaldb_bodypart;'
    id_prefix = "bodypart_"
    o = get_medical_entity_handler(False).do_one(sql)

    docs = []

    for item in o:
        id = item[0]
        name = item[1].lower().replace(" ", "")
        abbr = item[2].lower().replace(" ", "")
        name_list = [name, abbr] if abbr else [name]
        docs.append(
            {
                "id": id_prefix + str(id),
                "name": name_list,
                "name_string":name_list,
                "type": "bodypart",
                "timestamp": int(time.time() * 1000)
            }
        )

    solr = SolrCloud(ZooKeeper("md4:2181"), "simple_medical_entity")
    add_all(docs, solr)
def add_symptom():
    # medicaldb_newsymptoms
    sql = "select id,name,abbr,alias from medicaldb_newsymptoms;"
    id_prefix = "symptom_"
    o = get_medical_entity_handler(False).do_one(sql)
    docs = []

    for item in o:
        id = item[0]
        name = item[1].lower().replace(" ", "")
        abbr = item[2].lower().replace(" ", "")
        alias = item[3].lower().replace(" ", "")
        name_list = [name]
        if abbr:
            name_list.append(abbr)
        if alias:
            alias_list = alias.split('|')
            name_list.extend(alias_list)

        name_set = set(name_list)
        name_set.discard("")
        name_list = list(name_set)

        docs.append(
            {
                "id": id_prefix + str(id),
                "name": name_list,
                "name_string": name_list,
                "type": "symptom",
                "timestamp": int(time.time() * 1000)
            }
        )
    solr = SolrCloud(ZooKeeper("md4:2181"), "simple_medical_entity")
    add_all(docs, solr)
예제 #4
0
def get_bodypart_data():
    all_bodypart = set()
    sql = 'select name from medicaldb_bodypart;'
    o = get_medical_entity_handler(False).do_one(sql)
    for item in o:
        name = item[0]
        all_bodypart.add(name)
    print "all_bodypart len is", len(all_bodypart)
    pickle_to_file(all_bodypart, BODYPART_FILE)
예제 #5
0
def test4():
    from general_utils.db_utils import get_medical_entity_handler
    sql = 'select id,name,frequency from medicaldb_newdiseases;'
    o = get_medical_entity_handler(False).do_one(sql)
    fo = open("diseases_frequency.csv", "w")
    csvwriter = csv.writer(fo, dialect='excel')
    first = ["id", "name", "freq"]
    csvwriter.writerow(first)
    for item in o:
        id = item[0]
        name = item[1]
        freq = item[2]
        rows = [id, name, freq]
        rows = convert2gbk(rows)
        csvwriter.writerow(rows)
    fo.close()