-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
184 lines (137 loc) · 5.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from flask import Flask, render_template,request,redirect,url_for,flash
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.secret_key = "Nivetha"
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://postgres:1234@localhost:5432/postgres"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']= True
db = SQLAlchemy(app)
# migrate = Migrate(app, db)
db.init_app(app)
class patient(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(100))
phone = db.Column(db.String(100))
disease = db.Column(db.String(100))
status = db.Column(db.String(100))
def __init__(self,name,phone,disease,status):
self.name = name
self.phone = phone
self.disease = disease
self.status = status
@app.before_first_request
def create_all():
db.create_all()
@app.route('/')
def Index():
all_data = patient.query.all()
all_dat = doctor.query.all()
all_da = employee.query.all()
data = {'patients':all_data,'doctor':all_dat,'employees':all_da}
return render_template('index.html',**data)
@app.route('/insert', methods = ['POST'])
def insert():
if request.method == 'POST':
name = request.form['name']
phone = request.form['phone']
disease = request.form['disease']
status = request.form['status']
my_data = patient(name,phone,disease,status)
db.session.add(my_data)
db.session.commit()
flash("Patient Inserted Successfully!!")
return redirect(url_for('Index'))
@app.route('/update', methods = ['GET','POST'])
def update():
if request.method == 'POST':
my_data = patient.query.get(request.form.get('id'))
my_data.name = request.form['name']
my_data.phone = request.form['phone']
my_data.disease = request.form['disease']
my_data.status = request.form['status']
db.session.commit()
flash("Patient Updated Successfully")
return redirect(url_for('Index'))
@app.route('/delete/<id>/', methods = ['GET', 'POST'])
def delete(id):
my_data = patient.query.get(id)
db.session.delete(my_data)
db.session.commit()
flash("Patient Deleted Successfully")
return redirect(url_for('Index'))
class doctor(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(100))
phone = db.Column(db.String(100))
specialist = db.Column(db.String(100))
def __init__(self,name,phone,specialist):
self.name = name
self.phone = phone
self.specialist = specialist
@app.route('/insert1', methods = ['POST'])
def insert1():
if request.method == 'POST':
name = request.form['name']
phone = request.form['phone']
specialist = request.form['specialist']
my_data = doctor(name,phone,specialist)
db.session.add(my_data)
db.session.commit()
flash("Doctor Inserted Successfully!!")
return redirect(url_for('Index'))
@app.route('/update1', methods = ['GET','POST'])
def update1():
if request.method == 'POST':
my_data = doctor.query.get(request.form.get('id'))
my_data.name = request.form['name']
my_data.phone = request.form['phone']
my_data.specialist = request.form['specialist']
db.session.commit()
flash("Doctor Updated Successfully")
return redirect(url_for('Index'))
@app.route('/delete1/<id>/', methods = ['GET', 'POST'])
def delete1(id):
my_data = doctor.query.get(id)
db.session.delete(my_data)
db.session.commit()
flash("Doctor Deleted Successfully")
return redirect(url_for('Index'))
class employee(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(100))
phone = db.Column(db.String(100))
designation = db.Column(db.String(100))
def __init__(self,name,phone,designation):
self.name = name
self.phone = phone
self.designation = designation
@app.route('/insert2', methods = ['POST'])
def insert2():
if request.method == 'POST':
name = request.form['name']
phone = request.form['phone']
designation = request.form['designation']
my_data = employee(name,phone,designation)
db.session.add(my_data)
db.session.commit()
flash("Employee Inserted Successfully!!")
return redirect(url_for('Index'))
@app.route('/update2', methods = ['GET','POST'])
def update2():
if request.method == 'POST':
my_data = employee.query.get(request.form.get('id'))
my_data.name = request.form['name']
my_data.phone = request.form['phone']
my_data.designation = request.form['designation']
db.session.commit()
flash("Employee Updated Successfully")
return redirect(url_for('Index'))
@app.route('/delete2/<id>/', methods = ['GET', 'POST'])
def delete2(id):
my_data = employee.query.get(id)
db.session.delete(my_data)
db.session.commit()
flash("Employee Deleted Successfully")
return redirect(url_for('Index'))
if __name__ == "__main__":
app.run(debug=True)