import sys
import os
import time
import operator
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()

def printHistory(userid):
    sql = "select username,sex,age,province,area,bumen,ke,result,chufang,jianyi,yiyuaan,yisheng,jianchaxiang,zhenduanriqi from zhenduanjilutable where userid='%d'" % userid
    cursor.execute(sql)
    rows = cursor.fetchall()
    zhenduanjilu = []
    for row in rows:
        temp = []
        temp.append(row[0])
        temp.append(row[1])
        temp.append(row[2])
        temp.append(row[3])
        temp.append(row[4])
        temp.append(row[5])
        temp.append(row[6])
        temp.append(row[7])
        temp.append(row[8])
        temp.append(row[9])
        temp.append(row[10])
        temp.append(row[11])
        temp.append(row[12])
        temp.append(row[13])
        zhenduanjilu.append(temp)
    print("===================打印诊断历史记录=====================")
    for i in range(len(zhenduanjilu)):
        print("-------------->>第:"+str(i+1)+"次诊断<<-------------------")
        print("     姓名:"+zhenduanjilu[i][0])
        print("     性别:"+zhenduanjilu[i][1])
        print("     年龄:"+str(zhenduanjilu[i][2]))
        print("     省份:"+zhenduanjilu[i][3])
        print("     市区:"+zhenduanjilu[i][4])
        print("     门诊部门:"+zhenduanjilu[i][5])
        print("     门诊科目:"+zhenduanjilu[i][6])
        print("     诊断结果:"+zhenduanjilu[i][7])
        print("     医疗处方:"+zhenduanjilu[i][8])
        print("     养生建议:"+zhenduanjilu[i][9])
        print("     推荐医院:"+zhenduanjilu[i][10])
        print("     推荐医生:"+zhenduanjilu[i][11])
        print("     建议检查项:"+zhenduanjilu[i][12])
        print("     诊断日期:"+str(zhenduanjilu[i][13]))
        
# printHistory(6)

 

 

<%-- 
    Document   : ALSelectHistory
    Created on : 2018-10-9, 21:28:13
    Author     : acer
--%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>智能复诊页</title>
    </head>
    <%    request.setCharacterEncoding("UTF-8");    %>
    <body>
    <center><h2>智能复诊</h2></center>
    <hr>
    <%
        String userid = request.getParameter("userid");
        String username = request.getParameter("username");
        String province = request.getParameter("province");
        String administ = request.getParameter("administ");
        String[] userInfo = new String[]{"python", "F:\\HostitalProject\\src\\java\\pyFile\\printzhenduanjilu.py", userid};
        Process pr = Runtime.getRuntime().exec(userInfo);
        BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        List<String> allList = new ArrayList<>();
        String line;
        while ((line = in.readLine()) != null) {
            allList.add(line);
        }
        Iterator<String> iter = allList.iterator();
        int length = allList.size();
        String[] str_back = new String[length];
        for (int i = 0; i < str_back.length; i++) {
            str_back[i] = iter.next();
        }
    %> 
    <table width="874" cellspacing="0" cellpadding="0">
        <tr>
            <td><div align="center">编号:<%=userid%> 就诊历史记录</div></td>
        </tr>
        <%
            for (int i = 0; i < str_back.length; i++) {
        %>
        <tr>
            <td><%=str_back[i]%></td>
        </tr>
        <%
            }
        %>         
    </table>
    <form action="ALgetquestion.jsp" method="post">
        <h2>请输入上面你需要复诊记录的编号:<input type="text" name="hisid" value=""/></h2>
        <input type="hidden" name="userid" value="<%=userid%>"/>
        <input type="hidden" name="username" value="<%=username%>"/>
        <input type="hidden" name="province" value="<%=province%>"/>
        <input type="hidden" name="administ" value="<%=administ%>"/>
        <input type="submit" name="Submit" value="下一步" />
    </form>
</body>
</html>

<%-- 
    Document   : ALquestion
    Created on : 2019-5-13, 15:40:45
    Author     : Administrator
--%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>复诊页</title>
    </head>
    <%    request.setCharacterEncoding("UTF-8");%>
    <body>
    <center><h2>智能复诊</h2></center>
    <hr>
    <%
        String userid = request.getParameter("userid");
        String username = request.getParameter("username");
        String province = request.getParameter("province");
        String administ = request.getParameter("administ");
        String hisid = request.getParameter("hisid");
        String[] userInfo = new String[]{"python", "F:\\HostitalProject\\src\\java\\pyFile\\getidcishu.py", userid,hisid};
        Process pr = Runtime.getRuntime().exec(userInfo);
        BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        List<String> allList = new ArrayList<>();
        String line;
        while ((line = in.readLine()) != null) {
            allList.add(line);
        }
        Iterator<String> iter = allList.iterator();
        int length = allList.size();
        String[] str_back = new String[length];
        for (int i = 0; i < str_back.length; i++) {
            str_back[i] = iter.next();
        }
    %> 
    
    <form action="ALgetquestion.jsp" method="post">
        <input type="hidden" name="userid" value="<%=str_back[0]%>"/>
        <input type="hidden" name="username" value="<%=str_back[1]%>"/>
        <input type="hidden" name="sex" value="<%=str_back[2]%>"/>
        <input type="hidden" name="age" value="<%=str_back[3]%>"/>
        <input type="hidden" name="province" value="<%=str_back[4]%>"/>
        <input type="hidden" name="area" value="<%=str_back[5]%>"/>
        <input type="hidden" name="bumen" value="<%=str_back[6]%>"/>
        <input type="hidden" name="ke" value="<%=str_back[7]%>"/>
        <input type="submit" name="Submit" value="下一步" />
    </form>
</body>
</html>
<%-- 
    Document   : ALgetquestion
    Created on : 2018-10-9, 21:48:40
    Author     : acer
--%>

<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.regex.Pattern"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>智能复诊页</title>
    </head>
    <%    request.setCharacterEncoding("UTF-8");    %>
    <body>
    <center><h2>智能复诊</h2></center>
    <hr>
    <%
        String userid = request.getParameter("userid");
        String username = request.getParameter("username");
        String sex = request.getParameter("sex");
        String age = request.getParameter("age");
        String province = request.getParameter("province");
        String administ = request.getParameter("area");
        String surgest = request.getParameter("bumen");
        String subject = request.getParameter("ke");     
    %>    
    <form action="ALfuzhengetAnswer.jsp" method="post">
        <table width="874" cellspacing="0" cellpadding="0" border="1">
            <tr><td><h3>就诊编号:<%=userid%></h3></td></tr>
            <tr><td><h3>用户账号:<%=username%></h3></td></tr>
            <tr><td><h3>门诊部门:<%=surgest%></h3></td></tr>
            <tr><td><h3>病理科室:<%=subject%></h3></td></tr>
            <tr><td><h3>请认真如实选择回答问题:
                        <%
                            String[] userInf = new String[]{"python", "F:\\HostitalProject\\src\\java\\pyFile\\getQuestion.py", subject};
                            Process p = Runtime.getRuntime().exec(userInf);
                            BufferedReader ii = new BufferedReader(new InputStreamReader(p.getInputStream()));
                            List<String> alList = new ArrayList<>();
                            String lin;
                            while ((lin = ii.readLine()) != null) {
                                alList.add(lin);
                            }
                            Iterator<String> ite = alList.iterator();
                            int lengt = alList.size();                     
                            String[] str_bac = new String[lengt];
                            for (int i = 0; i < str_bac.length; i++) {
                                str_bac[i] = ite.next();
                            }      
                        %>
                        <h3><%=str_bac[0]%></h3>
                        <label><input name="one" type="radio" value="正常" />正常</label>
                        <label><input name="one" type="radio" value="轻度" />轻度</label>
                        <label><input name="one" type="radio" value="偏重" />偏重</label>
                        <label><input name="one" type="radio" value="严重" />严重</label>
                        <h3><%=str_bac[1]%></h3>
                        <label><input name="two" type="radio" value="正常" />正常</label>
                        <label><input name="two" type="radio" value="轻度" />轻度</label>
                        <label><input name="two" type="radio" value="偏重" />偏重</label>
                        <label><input name="two" type="radio" value="严重" />严重</label>
                        <h3><%=str_bac[2]%></h3>
                        <label><input name="three" type="radio" value="正常" />正常</label>
                        <label><input name="three" type="radio" value="轻度" />轻度</label>
                        <label><input name="three" type="radio" value="偏重" />偏重</label>
                        <label><input name="three" type="radio" value="严重" />严重</label>
                        <h3><%=str_bac[3]%></h3>
                        <label><input name="force" type="radio" value="正常" />正常</label>
                        <label><input name="force" type="radio" value="轻度" />轻度</label>
                        <label><input name="force" type="radio" value="偏重" />偏重</label>
                        <label><input name="force" type="radio" value="严重" />严重</label>
                        <h3><%=str_bac[4]%></h3>
                        <label><input name="five" type="radio" value="正常" />正常</label>
                        <label><input name="five" type="radio" value="轻度" />轻度</label>
                        <label><input name="five" type="radio" value="偏重" />偏重</label>
                        <label><input name="five" type="radio" value="严重" />严重</label>
                    </h3></td></tr>
            <tr><td><input type="hidden" name="userid" value="<%=userid%>"/>
                    <input type="hidden" name="username" value="<%=username%>"/>
                    <input type="hidden" name="province" value="<%=province%>"/>
                    <input type="hidden" name="administ" value="<%=administ%>"/>
                    <input type="hidden" name="surgest" value="<%=surgest%>"/>
                    <input type="hidden" name="subject" value="<%=subject%>"/>
                    <input type="hidden" name="q1" value="<%=str_bac[0]%>"/>
                    <input type="hidden" name="q2" value="<%=str_bac[1]%>"/>
                    <input type="hidden" name="q3" value="<%=str_bac[2]%>"/>
                    <input type="hidden" name="q4" value="<%=str_bac[3]%>"/>
                    <input type="hidden" name="q5" value="<%=str_bac[4]%>"/>                  
                    <input type="submit" name="Submit" value="下一步" />                    
                </td></tr>
        </table>
    </form>
    <form action="ALSelectHistory.jsp" method="post">
        <table width="874" cellspacing="0" cellpadding="0" border="1">
            <tr><td>
                    <input type="hidden" name="userid" value="<%=userid%>"/>
                    <input type="hidden" name="username" value="<%=username%>"/>
                    <input type="hidden" name="province" value="<%=province%>"/>
                    <input type="hidden" name="administ" value="<%=administ%>"/>                                   
                    <input type="submit" name="Submit" value="上一步" /> 
                </td></tr>
        </table>
    </form>
</body>
</html>

<%-- 
    Document   : ALfuzhengetAnswer
    Created on : 2018-10-10, 11:00:12
    Author     : acer
--%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>智能复诊页</title>
    </head>
    <%    request.setCharacterEncoding("UTF-8");%>
    <body>
    <center><h2>智能复诊结果单</h2></center>
    <hr>
    <%
        String userid = request.getParameter("userid");
        String username = request.getParameter("username");
        String province = request.getParameter("province");
        String administ = request.getParameter("administ");
        String surgest = request.getParameter("surgest");
        String subject = request.getParameter("subject");
        String one = request.getParameter("one");
        String two = request.getParameter("two");
        String three = request.getParameter("three");
        String force = request.getParameter("force");
        String five = request.getParameter("five");
        String q1 = request.getParameter("q1");
        q1 = q1 + one;
        String q2 = request.getParameter("q2");
        q2 = q2 + two;
        String q3 = request.getParameter("q3");
        q3 = q3 + three;
        String q4 = request.getParameter("q4");
        q4 = q4 + force;
        String q5 = request.getParameter("q5");
        q5 = q5 + five;
        String qone = "";
        if (one.equals("正常")) {
            qone = "1";
        } else if (one.equals("轻度")) {
            qone = "2";
        } else if (one.equals("偏重")) {
            qone = "3";
        } else {
            qone = "4";
        }
        String qtow = "";
        if (two.equals("正常")) {
            qtow = "1";
        } else if (two.equals("轻度")) {
            qtow = "2";
        } else if (two.equals("偏重")) {
            qtow = "3";
        } else {
            qtow = "4";
        }
        String qthree = "";
        if (three.equals("正常")) {
            qthree = "1";
        } else if (three.equals("轻度")) {
            qthree = "2";
        } else if (three.equals("偏重")) {
            qthree = "3";
        } else {
            qthree = "4";
        }
        String qforce = "";
        if (force.equals("正常")) {
            qforce = "1";
        } else if (force.equals("轻度")) {
            qforce = "2";
        } else if (force.equals("偏重")) {
            qforce = "3";
        } else {
            qforce = "4";
        }
        String qfive = "";
        if (five.equals("正常")) {
            qfive = "1";
        } else if (five.equals("轻度")) {
            qfive = "2";
        } else if (five.equals("偏重")) {
            qfive = "3";
        } else {
            qfive = "4";
        }
    %>
    <table width="874" cellspacing="0" cellpadding="0" border="1">
        <tr><td><h3>就诊编号:<%=userid%></h3></td></tr>
        <tr><td><h3>用户账号:<%=username%></h3></td></tr>
        <tr><td><h3>门诊部门:<%=surgest%></h3></td></tr>
        <tr><td><h3>病理科室:<%=subject%></h3></td></tr>
        <tr><td><h3>问诊一:<%=q1%></h3></td></tr>
        <tr><td><h3>问诊二:<%=q2%></h3></td></tr>
        <tr><td><h3>问诊三:<%=q3%></h3></td></tr>
        <tr><td><h3>问诊四:<%=q4%></h3></td></tr>
        <tr><td><h3>问诊五:<%=q5%></h3></td></tr>
        <tr><td>
                <%
                    String[] userInfo = new String[]{"python", "F:\\HostitalProject\\src\\java\\pyFile\\chuzhen.py", qone, qtow, qthree, qforce, qfive, userid, username, surgest, subject, province, administ};
                    Process pr = Runtime.getRuntime().exec(userInfo);
                    BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                    List<String> allList = new ArrayList<>();
                    String line;
                    while ((line = in.readLine()) != null) {
                        allList.add(line);
                    }
                    Iterator<String> iter = allList.iterator();
                    int length = allList.size();
                    String[] str_back = new String[length];
                    for (int i = 0; i < str_back.length; i++) {
                        str_back[i] = iter.next();
                    }
                %>
                <h3>诊断结果:<%=str_back[0]%>                </h3>
                <h3><%=str_back[1]%></h3>
                <h3><%=str_back[2]%></h3>
                <h3><%=str_back[3]%></h3>
                <h3><%=str_back[4]%></h3>
                <h3><%=str_back[5]%></h3>
                <h3><%=str_back[6]%></h3>
                <h3><%=str_back[7]%></h3>
                <h3><%=str_back[8]%></h3>
                <h3><%=str_back[9]%></h3>
                <h3><%=str_back[10]%></h3>
                <h3><%=str_back[11]%></h3>
                <h3><%=str_back[12]%></h3>
                <h3><%=str_back[13]%></h3>
            </td></tr>            
    </table>   
    <h2><a href="log.html">返回登录页</a></h2>
</body>
</html>

#诊断逻辑代码
import sys
import os
import time
import operator
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()

# one-hot编码
def onehot(labels):
    n_sample = len(labels)
    n_class = max(labels) + 1
    onehot_labels = np.zeros((n_sample, n_class))
    onehot_labels[np.arange(n_sample), labels] = 1
    return onehot_labels


# 获取数据集
def getdata(surgery ,surgeryChest):
    sql = "select feature1,feature2,feature3,feature4,feature5,trainLable from menzhen where surgery='%s' and surgeryChest='%s'" % \
    (surgery, surgeryChest)
    cursor.execute(sql)
    rows = cursor.fetchall()
    dataset = []
    lables = []
    for row in rows:
        temp = []
        temp.append(row[0])
        temp.append(row[1])
        temp.append(row[2])
        temp.append(row[3])
        temp.append(row[4])
        dataset.append(temp)
        if (row[5] == 3):
            lables.append(0)
        elif (row[5] == 6):
            lables.append(1)
        else:
            lables.append(2)
    dataset = np.array(dataset)
    lables = np.array(lables)
    dataset = dataset.astype(np.float32)
    labless = onehot(lables)
    return dataset, labless


def getAnswer(a1, a2, a3, a4, a5):
    answers = []
    answers.append(int(a1))
    answers.append(int(a2))
    answers.append(int(a3))
    answers.append(int(a4))
    answers.append(int(a5))
    str_answers = []
    if (int(a1) == 1):
        str_answers.append("正常")
    elif (int(a1) == 2):
        str_answers.append("轻度")
    elif (int(a1) == 3):
        str_answers.append("偏重")
    else:
        str_answers.append("严重")
    if (int(a2) == 1):
        str_answers.append("正常")
    elif (int(a2) == 2):
        str_answers.append("轻度")
    elif (int(a2) == 3):
        str_answers.append("偏重")
    else:
        str_answers.append("严重")
    if (int(a3) == 1):
        str_answers.append("正常")
    elif (int(a3) == 2):
        str_answers.append("轻度")
    elif (int(a3) == 3):
        str_answers.append("偏重")
    else:
        str_answers.append("严重")
    if (int(a4) == 1):
        str_answers.append("正常")
    elif (int(a4) == 2):
        str_answers.append("轻度")
    elif (int(a4) == 3):
        str_answers.append("偏重")
    else:
        str_answers.append("严重")
    if (int(a5) == 1):
        str_answers.append("正常")
    elif (int(a5) == 2):
        str_answers.append("轻度")
    elif (int(a5) == 3):
        str_answers.append("偏重")
    else:
        str_answers.append("严重")
    return answers, str_answers


def getSugessiones(sujects, resultName):
    sql = "select prescription_1,prescription_2,prescription_3,prescription_4,prescription_5,prescription_6,prescription_7,prescription_8,prescription_9,prescription_10,prescription_11,prescription_12,prescription_13,prescription_14,prescription_15 from prescription where SURGERYCHEST='%s' and illName='%s'" % (
    sujects, resultName)
    cursor.execute(sql)
    rows = cursor.fetchall()
    prescriptionData = []
    for row in rows:
        one = []
        one.append(row[0])
        one.append(row[1])
        one.append(row[2])
        one.append(row[3])
        one.append(row[4])
        one.append(row[5])
        one.append(row[6])
        one.append(row[7])
        one.append(row[8])
        one.append(row[9])
        one.append(row[10])
        one.append(row[11])
        one.append(row[12])
        one.append(row[13])
        one.append(row[14])
        prescriptionData.append(one)
    prescriptionDataFrame = pd.DataFrame(prescriptionData)
    prescriptionDataSum = prescriptionDataFrame.sum(axis=0)
    prescriptionDataSumSorted = sorted(enumerate(prescriptionDataSum), key=lambda x: x[1], reverse=True)
    prescriptionDataSumSortedThirst = prescriptionDataSumSorted[:3]
    prescriptionIndex = []
    for i in range(len(prescriptionDataSumSortedThirst)):
        prescriptionIndex.append(prescriptionDataSumSortedThirst[i][0])
    sql = "select prescriptionInfo,health from prescriptionInfo where FAMILY='%s' and ill_name='%s'" % (
    sujects, resultName)
    cursor.execute(sql)
    rows = cursor.fetchall()
    prescriptionInfoData = []
    healthData = []
    for row in rows:
        prescriptionInfoData.append(row[0])
        healthData.append(row[1])
    prescriptionInfoResult = []
    for i in range(len(prescriptionIndex)):
        prescriptionInfoResult.append(prescriptionInfoData[prescriptionIndex[i]])
    healthResult = []
    for i in range(len(prescriptionIndex)):
        healthResult.append(healthData[prescriptionIndex[i]])
    return prescriptionInfoResult, healthResult


def getSeeProject(subject):
    sql = "select CHACKPRO from chackProject where FAMILY='%s'" % (subject)
    cursor.execute(sql)
    rows = cursor.fetchall()
    seeproject = []
    for row in rows:
        seeproject.append(rows[0])
    return seeproject[0][0]


def getDoctors(sujects):
    sql = "select addraction,name,summary from doctors where family='%s'" % (sujects)
    cursor.execute(sql)
    rows = cursor.fetchall()
    doctorInfo = []
    for row in rows:
        doctorInfo.append(row[0])
        doctorInfo.append(row[1])
        doctorInfo.append(row[2])
    print("主治专家姓名:" + doctorInfo[1])
    print("主治专家简介:" + doctorInfo[2])
    print("主治专家所在医院:" + doctorInfo[0])
    return doctorInfo


def getPAH(province, administrative):
    sql = "select hostitalname from hostitalAdrrest where province='%s' and administrative='%s'" % (
    province, administrative)
    cursor.execute(sql)
    rows = cursor.fetchall()
    hostitalName = []
    for row in rows:
        hostitalName.append(row[0])
    yiyuaan = ""
    for i in range(len(hostitalName)):
        print(hostitalName[i])
        yiyuaan += hostitalName[i]
    return yiyuaan


def addUser_SeeIll(userid, username, sex, age, province, area, bumen, ke, result, chufang, jianyi, yiyuaan, yisheng,
                   jianchaxiang):
    sql = "insert into zhenduanjilutable (userid,username,sex,age,province,area,bumen,ke,result,chufang,jianyi,yiyuaan,yisheng,jianchaxiang) values (%d,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (
    userid, username, sex, age, province, area, bumen, ke, result, chufang, jianyi, yiyuaan, yisheng, jianchaxiang)
    cursor.execute(sql)
    conn.commit()
    if (cursor.rowcount == 1):
        print("新看病记录添加成功")
    else:
        print("新看病记录添加失败")


def zhenduan_n(a1, a2, a3, a4, a5, userid, username, surgery, surgeryChest, province, administ):
    answers, str_answers = getAnswer(a1, a2, a3, a4, a5)
    useranswer = [answers] * 3
    dataset, labless = getdata(surgery, surgeryChest)
    x_data = tf.placeholder("float32", [None, 5])
    y_data = tf.placeholder("float32", [None, 3])
    weight = tf.Variable(tf.ones([5, 3]))
    bias = tf.Variable(tf.ones([3]))
    # 使用softmax激活函数
    y_model = tf.nn.softmax(tf.matmul(x_data, weight) + bias)
    # y_model = tf.nn.relu(tf.matmul(x_data, weight) + bias)
    # loss = tf.reduce_sum(tf.pow((y_model - y_data), 2))
    # 使用交叉熵作为损失函数
    loss = -tf.reduce_sum(y_data * tf.log(y_model))
    # train_step = tf.train.GradientDescentOptimizer(1e-4).minimize(loss)
    # 使用AdamOptimizer优化器
    # train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)
    train_step = tf.train.MomentumOptimizer(1e-4, 0.9).minimize(loss)
    # 评估模型
    correct_prediction = tf.equal(tf.argmax(y_model, 1), tf.argmax(y_data, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
    init = tf.initialize_all_variables()
    sess = tf.Session()
    sess.run(init)
    for _ in range(10):
        for i in range(int(len(dataset) / 100)):
            sess.run(train_step, feed_dict={x_data: dataset[i:i + 100, :], y_data: labless[i:i + 100, :]})
    xl_weight = sess.run(weight)
    W = np.dot(xl_weight, useranswer)
    result = 0
    for i in range(len(W[0])):
        for j in range(len(W[0, :])):
            if (i == j):
                result += W[i][j]
    result = int(result / 5)
    if (result <= 3):
        result = 3
    elif (result <= 6):
        result = 6
    else:
        result = 9
    sql = "select ILL_NAME from ill_result_tbZ where FAMILY='%s' and ILL_ID=%d" % (surgeryChest, result)
    cursor.execute(sql)
    rows = cursor.fetchall()
    ILL_NAME = []
    for row in rows:
        ILL_NAME.append(row[0])

    firstResult = ILL_NAME[0]
    if (firstResult[:2] == "疑似"):
        firstResult = "疑似患病"
    print(firstResult)
    prescriptionInfoResult, healthResult = getSugessiones(surgeryChest, firstResult)
    chufang = ''
    for i in range(len(prescriptionInfoResult)):
        chufang = chufang + '诊断处方' + str(i + 1) + '' + prescriptionInfoResult[i] + ''
        print('诊断处方' + str(i + 1) + '' + prescriptionInfoResult[i])
    jianyi = ''
    for i in range(len(healthResult)):
        jianyi = jianyi + '养生建议' + str(i + 1) + '' + healthResult[i] + ''
        print('养生建议' + str(i + 1) + '' + healthResult[i])
    if (firstResult != '正常'):
        print("根据你的情况,系统推荐重点检查身体以下几项健康指标:")
        seeproject = getSeeProject(surgeryChest)
        print("推荐检查:", seeproject)
        print("根据你的情况,系统向你推荐以下在这一治疗领域专家:")
        doctorInfo = getDoctors(surgeryChest)
        yisheng = ""
        for i in range(len(doctorInfo)):
            yisheng += doctorInfo[i]
        print("===============================================================================================")
        print("根据你所处的位置,系统找到以下与你距离最近的医院:")
        yiyuaan = getPAH(province, administ)
        sex = ""
        age = 13
        addUser_SeeIll(userid, username, sex, age, province, administ, surgery, surgeryChest, firstResult, chufang,
                       jianyi, yiyuaan, yisheng, seeproject)

# zhenduan_n("1","2","3","4","4",6,"小东东","外科","胸外科","广东省","广州市")
# prescriptionInfoResult,healthResult = getSugessiones("胸外科","胸壁结核")
# a = getDoctors("胸外科")
# getPAH("广东省","广州市")

def action(infon):
    zhenduan_n(int(infon[0]),int(infon[1]),int(infon[2]),int(infon[3]),int(infon[4]),int(infon[5]),infon[6],infon[7],infon[8],infon[9],infon[10])

if __name__ == '__main__':
    infon = []
    for i in range(1,len(sys.argv)):
        infon.append(sys.argv[i])
    action(infon)