Example #1
0
def get_r_icd9():

    # 存icd9字典
    icd9_dict = []
    data = xlrd.open_workbook('../final_data/ICD9CM.xls')  # 打开xls文件
    table = data.sheets()[0]  # 打开第一张表
    nrows = table.nrows  # 获取表的行数
    for i in range(nrows):
        if i == 0:
            continue
        else:
            icd9_dict.append(table.row_values(i)[1])

    hpo_in = []
    pid_in = []
    pid_out = []
    hid_out = []
    data1 = xlrd.open_workbook('../final_data/system.xls')  # 打开xls文件
    table1 = data1.sheets()[0]  # 打开第一张表
    nrows1 = table1.nrows  # 获取表的行数
    for i in range(nrows1):
        if i == 0:
            continue
        else:
            hpo_in.append(table1.row_values(i)[7])
            pid_in.append(table1.row_values(i)[0])
    index = 0
    for d in hpo_in:
        try:
            d = d[d.index(":") + 1:]
        except:
            pid_out.append(pid_in[index])
            hid_out.append(-1)
        else:
            list = util.get_list_by_colon(d)
            for l in list:
                if l == "":
                    continue
                pid_out.append(pid_in[index])
                hid_out.append(icd9_dict.index(l) + 1)
        index = index + 1

    wb = xlwt.Workbook()
    sheet1 = wb.add_sheet('sheet1')
    sheet1.write(0, 0, 'id')
    sheet1.write(0, 1, 'pid')
    sheet1.write(0, 2, 'i9id')

    for i in range(len(pid_out)):
        # print(result[i][j])
        try:
            sheet1.write(i + 1, 0, i + 1)
            sheet1.write(i + 1, 1, pid_out[i])
            sheet1.write(i + 1, 2, hid_out[i])
        except:
            print(i, pid_out[i])
    wb.save("../final_data/ICD9CM_relationship.xls")

    print("end")
Example #2
0
def get_r_snomect():

    snomect_dict = []
    data = xlrd.open_workbook('../final_data/snomect.xls')  # 打开xls文件
    table = data.sheets()[0]  # 打开第一张表
    nrows = table.nrows  # 获取表的行数
    for i in range(nrows):
        if i == 0:
            continue
        else:
            snomect_dict.append(table.row_values(i)[1])

    snomect_in = []
    pid_in = []
    pid_out = []
    snomect_out = []
    data1 = xlrd.open_workbook('../final_data/system.xls')  # 打开xls文件
    table1 = data1.sheets()[0]  # 打开第一张表
    nrows1 = table1.nrows  # 获取表的行数
    for i in range(nrows1):
        if i == 0:
            continue
        else:
            snomect_in.append(table1.row_values(i)[4])
            pid_in.append(table1.row_values(i)[0])
    index = 0
    for d in snomect_in:

        d = d[d.index(":") + 1:]

        list = util.get_list_by_colon(d)
        if list[0] == "":
            pid_out.append(pid_in[index])
            snomect_out.append(-1)
        for l in list:
            if l == "":
                continue
            pid_out.append(pid_in[index])
            snomect_out.append(snomect_dict.index(l) + 1)
        index = index + 1

    wb = xlwt.Workbook()
    sheet1 = wb.add_sheet('sheet1')
    sheet1.write(0, 0, 'id')
    sheet1.write(0, 1, 'pid')
    sheet1.write(0, 2, 'sid')

    for i in range(len(pid_out)):
        # print(result[i][j])
        try:
            sheet1.write(i + 1, 0, i + 1)
            sheet1.write(i + 1, 1, pid_out[i])
            sheet1.write(i + 1, 2, snomect_out[i])
        except:
            print(i, pid_out[i])
    wb.save("../final_data/SNOMECT_relaitonship.xls")
    print("end")
def get_hpo():
    current_date = util.get_current_date()
    table = util.get_file_data('../final_data/system.xls')
    src = []
    dst = []
    for i in range(table.nrows):
        if i == 0:
            continue
        else:
            src.append(table.row_values(i)[8])

    for item in src:
        if item=="":
            continue
        item = item[item.index(":") + 1:]
        list = util.get_list_by_colon(item)
        for l in list:
            if l == "":
                continue
            else:
                try:
                    dst.index(l)
                except:
                    dst.append(l)

    wb = xlwt.Workbook()
    sheet1 = wb.add_sheet('sheet1')
    sheet1.write(0, 0, 'hid')
    sheet1.write(0, 1, 'hpo')

    for i in range(len(dst)):
        # print(result[i][j])
        try:
            sheet1.write(i + 1, 0, i + 1)
            sheet1.write(i + 1, 1, dst[i])
        except:
            print(i, dst[i])
    wb.save("../final_data/HPO.xls")
    print("end")