#coding:utf-8

import sys
import cx_Oracle
import numpy as np
import pandas as pd
import tensorflow as tf

def main(argv):
    conn=cx_Oracle.connect('doctor/admin@localhost:1521/tszr')
    cursor = conn.cursor()
    sql = "select distinct surgery from menzhen"
    cursor.execute(sql)
    rows = cursor.fetchall()
    dipart = []
    for row in rows:
        dipart.append(row[0])
    ############################################
    sql = "select distinct surgery,surgerychest from menzhen"
    cursor.execute(sql)
    rows = cursor.fetchall()
    dipartmentSubj = []
    for row in rows:
        one = []
        one.append(row[0])
        one.append(row[1])
        dipartmentSubj.append(one)
    ###########################################################
    sql = "select illSubject,question from questb"
    cursor.execute(sql)
    rows = cursor.fetchall()
    subjectQues = []
    for row in rows:
        one = []
        one.append(row[0])
        one.append(row[1])
        subjectQues.append(one)
    #############################################################
    sym = ""
    for i in range(len(argv)):
        sym += argv[i]
    symptom = []
    symptom.extend(sym)
    subCount = []
    for j in range(len(subjectQues)):
        temp = []
        que = []
        que.extend(subjectQues[j][1])
        count = 0
        for i in range(len(symptom)):
            if(symptom[i]!="," or symptom[i]!=" "):
                for k in range(len(que)):
                    if(symptom[i]==que[k]):
                        count = count + 1
        temp.append(subjectQues[j][0])
        temp.append(count)
        subCount.append(temp)
    ############################################################
    for i in range(len(subCount)):
        for j in range(len(dipartmentSubj)):
            if(subCount[i][0]==dipartmentSubj[j][1]):
                subCount[i].append(dipartmentSubj[j][0])
    symMaxCount = sorted(subCount,key=(lambda x:x[1]),reverse=True)           
    print("根据你输入的问题,经过大数据分析建议你选择以下的门诊部和对应的科:")
    print("门诊部门:"+symMaxCount[0][2])
    print("对应的科:"+symMaxCount[0][0])
    
# if __name__ == '__main__':
#     main(sys.argv)

print("===================>>系统智能分诊功能模块<<===================")
inputInfo = input("请输入你的症状:")
main(inputInfo)

#系统健康公告
import sys
import cx_Oracle
import numpy as np
import pandas as pd
import tensorflow as tf

conn=cx_Oracle.connect('doctor/admin@localhost:1521/tszr')
cursor = conn.cursor()

sql = "select TITLE,ARTICLE from SYSTEMINFORMATION"
cursor.execute(sql)
rows = cursor.fetchall()
sysinfo = []
for row in rows:
    temp = []
    temp.append(row[0])
    temp.append(row[1])
    sysinfo.append(temp)
    
print("================>>系统养生推荐公告功能模块<<===============")
for i in sysinfo:
    print("节气:"+i[0])
    print("养生建议:"+i[1])