from flask import Flask,render_template,request,redirect from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) db = SQLAlchemy(app) #设置数据库连接 app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@127.0.0.1:3306/information_of_city' class city_count(db.Model): #表模型 city= db.Column(db.Integer) area = db.Column(db.Integer,primary_key=True,autoincrement=True) patient_count = db.Column(db.Integer) suspected = db.Column(db.Integer) no_cases = db.Column(db.Integer) mild_cases = db.Column(db.Integer) severe_cases = db.Column(db.Integer) class treatment_count(db.Model): #表模型 name= db.Column(db.String(255)) patients = db.Column(db.Integer) remaining_position = db.Column(db.Integer) total_position = db.Column(db.Integer,primary_key=True,autoincrement=True) total_worker = db.Column(db.Integer) class treatment_point(db.Model): #表模型 treatment_point_id= db.Column(db.Integer,primary_key=True,autoincrement=True) name = db.Column(db.String(255)) total_position = db.Column(db.Integer) area_id = db.Column(db.Integer) city_id = db.Column(db.Integer) class patient(db.Model): #表模型 patient_id= db.Column(db.Integer,primary_key=True,autoincrement=True) name = db.Column(db.String(255)) treatment_point_id = db.Column(db.Integer) phone = db.Column(db.Integer) area_id = db.Column(db.Integer) city_id = db.Column(db.Integer) class medical_worker(db.Model): #表模型 worker_id= db.Column(db.Integer,primary_key=True,autoincrement=True) name = db.Column(db.String(255)) treatment_point_id = db.Column(db.Integer) phone = db.Column(db.Integer) class report(db.Model): #表模型 patient_id = db.Column(db.Integer,primary_key=True,autoincrement=True) update_time = db.Column(db.String(255)) situation = db.Column(db.String(255)) @app.route("/index7/") def selectAll7(): RE = report.query.order_by(report.patient_id).all() return render_template("index7.html",R_E = RE) @app.route('/insert2',methods=['GET','POST']) def insert2(): #进行添加操作 patient_id = request.form['patient_id'] update_time = request.form['update_time'] situation = request.form['situation'] Report = report(patient_id=patient_id,update_time=update_time,situation =situation) db.session.add(Report) db.session.commit() #添加完成重定向至主页 return redirect('/index7/') @app.route("/insert2_page") def insert2_page(): #跳转至添加信息页面 return render_template("insert2.html") #删除数据 @app.route("/delete2",methods=['GET']) def delete2(): #操作数据库得到目标数据,before_number表示删除之前的数量,after_name表示删除之后的数量 patient_id = request.args.get("patient_id") Report = report.query.filter_by(patient_id=patient_id).first() db.session.delete(Report) db.session.commit() return redirect('/') #修改操作 @app.route("/alter2",methods=['GET','POST']) def alter2(): # 可以通过请求方式来改变处理该请求的具体操作 # 比如用户访问/alter页面 如果通过GET请求则返回修改页面 如果通过POST请求则使用修改操作 if request.method == 'GET': patient_id = request.args.get('patient_id') update_time = request.args.get('update_time') situation = request.args.get('situation') Report = report(patient_id=patient_id, update_time=update_time, situation=situation) return render_template("alter2.html",Report = Report) else: #接收参数,修改数据 patient_id = request.form['patient_id'] update_time = request.form['update_time'] situation = request.form['situation'] Report = report.query.filter_by(patient_id=patient_id).first() Report.patient_id =patient_id Report.update_time = update_time Report.situation = situation db.session.commit() return redirect('/index7') @app.route("/index6/") def selectAll6(): MW = medical_worker.query.order_by(medical_worker.worker_id).all() return render_template("index6.html",M_W = MW) @app.route('/insert3',methods=['GET','POST']) def insert3(): #进行添加操作 worker_id = request.form['worker_id'] name = request.form['name'] treatment_point_id = request.form['treatment_point_id'] phone = request.form['phone'] Med = medical_worker(worker_id=worker_id,name=name,treatment_point_id =treatment_point_id,phone=phone) db.session.add(Med) db.session.commit() #添加完成重定向至主页 return redirect('/index6/') @app.route("/insert3_page") def insert3_page(): #跳转至添加信息页面 return render_template("insert3.html") #删除数据 @app.route("/delete3",methods=['GET']) def delete3(): #操作数据库得到目标数据,before_number表示删除之前的数量,after_name表示删除之后的数量 worker_id = request.args.get("worker_id") Med = medical_worker.query.filter_by(worker_id=worker_id).first() db.session.delete(Med) db.session.commit() return redirect('/') #修改操作 @app.route("/alter3",methods=['GET','POST']) def alter3(): # 可以通过请求方式来改变处理该请求的具体操作 # 比如用户访问/alter页面 如果通过GET请求则返回修改页面 如果通过POST请求则使用修改操作 if request.method == 'GET': worker_id = request.args.get('worker_id') name = request.args.get('name') treatment_point_id = request.args.get('treatment_point_id') phone = request.args.get('phone') Med = medical_worker(worker_id=worker_id, name=name, treatment_point_id=treatment_point_id,phone=phone) return render_template("alter3.html",Med = Med) else: #接收参数,修改数据 worker_id = request.form['worker_id'] name = request.form['name'] treatment_point_id = request.form['treatment_point_id'] phone = request.form['phone'] Med = medical_worker.query.filter_by(worker_id=worker_id).first() Med.worker_id =worker_id Med.name = name Med.treatment_point_id = treatment_point_id Med.phone = phone db.session.commit() return redirect('/index6') @app.route("/index5/") def selectAll5(): PA = patient.query.order_by(patient.patient_id).all() return render_template("index5.html",P_A = PA) #添加数据 @app.route('/insert',methods=['GET','POST']) def insert(): #进行添加操作 patient_id = request.form['patient_id'] name = request.form['name'] treatment_point_id = request.form['treatment_point_id'] phone = request.form['phone'] area_id = request.form['area_id'] city_id = request.form['city_id'] Patient = patient(patient_id=patient_id,name=name,treatment_point_id=treatment_point_id,phone=phone,area_id=area_id,city_id=city_id) db.session.add(Patient) db.session.commit() #添加完成重定向至主页 return redirect('/index5') @app.route("/insert_page") def insert_page(): #跳转至添加信息页面 return render_template("insert.html") #删除数据 @app.route("/delete",methods=['GET']) def delete(): #操作数据库得到目标数据,before_number表示删除之前的数量,after_name表示删除之后的数量 patient_id = request.args.get("patient_id") Patient = patient.query.filter_by(patient_id=patient_id).first() db.session.delete(Patient) db.session.commit() return redirect('/index5') #修改操作 @app.route("/alter",methods=['GET','POST']) def alter(): # 可以通过请求方式来改变处理该请求的具体操作 # 比如用户访问/alter页面 如果通过GET请求则返回修改页面 如果通过POST请求则使用修改操作 if request.method == 'GET': patient_id = request.args.get('patient_id') name = request.args.get('name') treatment_point_id = request.args.get('treatment_point_id') phone = request.args.get('phone') area_id = request.args.get('area_id ') city_id = request.args.get('city_id') Patient = patient(patient_id=patient_id, name=name, treatment_point_id=treatment_point_id, phone=phone, area_id=area_id, city_id=city_id) return render_template("alter.html",Patient = Patient) else: #接收参数,修改数据 patient_id = request.form['patient_id'] name = request.form['name'] treatment_point_id = request.form['treatment_point_id'] phone = request.form['phone'] area_id = request.form['area_id '] city_id = request.form['city_id'] Patient = patient.query.filter_by(patient_id=patient_id).first() Patient.patient_id =patient_id Patient.name = name Patient.treatment_point_id = treatment_point_id Patient.phone = phone Patient.area_id = area_id Patient.city_id = city_id db.session.commit() return redirect('/index5/') @app.route("/index4/") def selectAll4(): TP = treatment_point.query.order_by(treatment_point.treatment_point_id).all() return render_template("index4.html",T_P = TP) @app.route("/index45/") def selectAll45(): TP = treatment_point.query.order_by(treatment_point.treatment_point_id).all() return render_template("index45.html",T_P = TP) #添加数据 @app.route('/insert45',methods=['GET','POST']) def insert4(): #进行添加操作 treatment_point_id = request.form['treatment_point_id'] name = request.form['name'] total_position = request.form['total_position'] area_id = request.form['area_id'] city_id = request.form['city_id'] Tp = treatment_point(treatment_point_id=treatment_point_id,name=name,total_position =total_position,area_id =area_id ,city_id=city_id) db.session.add(Tp) db.session.commit() #添加完成重定向至主页 return redirect('/index45/') @app.route("/insert4_page") def insert4_page(): #跳转至添加信息页面 return render_template("insert4.html") #删除数据 @app.route("/delete4",methods=['GET']) def delete4(): #操作数据库得到目标数据,before_number表示删除之前的数量,after_name表示删除之后的数量 treatment_point_id = request.args.get("treatment_point_id") Tp = treatment_point.query.filter_by(treatment_point_id=treatment_point_id).first() db.session.delete(Tp) db.session.commit() return redirect('/') #修改操作 @app.route("/alter4",methods=['GET','POST']) def alter4(): # 可以通过请求方式来改变处理该请求的具体操作 # 比如用户访问/alter页面 如果通过GET请求则返回修改页面 如果通过POST请求则使用修改操作 if request.method == 'GET': treatment_point_id = request.args.get('treatment_point_id') name = request.args.get('name') total_position = request.args.get('total_position') area_id = request.args.get('area_id ') city_id = request.args.get('city_id') Tp = treatment_point(treatment_point_id=treatment_point_id, name=name, total_position=total_position, area_id=area_id, city_id=city_id) return render_template("alter4.html",Tp = Tp) else: #接收参数,修改数据 treatment_point_id = request.form['treatment_point_id'] name = request.form['name'] total_position = request.form['total_position'] area_id = request.form['area_id '] city_id = request.form['city_id'] Tp = treatment_point.query.filter_by(treatment_point_id=treatment_point_id).first() Tp.treatment_point_id =treatment_point_id Tp.name = name Tp.total_position = total_position Tp.area_id = area_id Tp.city_id = city_id db.session.commit() return redirect('/index45') @app.route("/index3/") def selectAll3(): TP = treatment_count.query.order_by(treatment_count.total_position).all() return render_template("index3.html",T_P= TP) @app.route("/index2/") def selectAll2(): cityPost = city_count.query.order_by(city_count.area).all() return render_template("index2.html",city_Post = cityPost) @app.route("/login") def login_page(): return render_template("登录.html") @app.route("/tourist") def login_tourist(): return render_template("游客导航界面.html") @app.route("/doctor")\ def login_doctor(): return render_template("医务工作者导航界面.html") @app.route("/master") def login_master(): return render_template("决策者导航界面.html") @app.route('/') def index(): return login_page() if __name__ == "__main__": app.run()