Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
236 lines (210 loc) · 7.38 KB
/
Copy pathmain.py
File metadata and controls
236 lines (210 loc) · 7.38 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import pymysql
from app import app
from config import mysql
from flask import jsonify, request
@app.route('/Manu')
def get_Manu():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute("SELECT * FROM manufacturer")
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/shotGiver')
def get_shotGiver():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute("select DISTINCT ID, FirstName, LastName from Volunteer")
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/shotGiven')
def get_shotGiven():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute(
"Select Distinct VolunteerID, FirstName, LastName, Count(PatientID) as Shots_Adminstered from Dose inner join Volunteer on Dose.VolunteerID = Volunteer.ID group by VolunteerID")
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/doseByManu')
def get_doseByManu():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute(
"Select Distinct ManufacturerID, MName, Count(PatientID) as Dose_Adminstered from Dose inner join Manufacturer on Dose.ManufacturerID = Manufacturer.ID group by ManufacturerID")
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/PatientByLotID')
def get_PatientByLotID():
try:
_json = request.json
_lotID = _json['lotID']
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
sqlQuery = f"Select ID, FirstName, LastName from Patient Inner Join Dose on Patient.ID= Dose.PatientID where Dose.LotID='{_lotID}'"
print(sqlQuery)
cursor.execute(sqlQuery)
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/PatientWithFirstDose')
def get_PatientWithFirstDose():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute(
"Select ID, FirstName, LastName, DateReceived from Patient Inner Join Dose on Patient.ID= Dose.PatientID where DoseNumber=1")
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/AgeAtVaccination')
def get_AgeAtVaccination():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute(
"Select ID, FirstName, LastName, Floor(DATEDIFF(Dose.DateReceived, DOB ) / 365.25) as age from Patient Inner Join Dose on Patient.ID= Dose.PatientID where DoseNumber=1")
row = cursor.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/AvgAgeOfVolunteers')
def get_AvgAgeOfVolunteers():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute("SELECT AVG(AGE) as AverageAge from Volunteer")
row = cursor.fetchone()
value = str(row)
resp = jsonify(value)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/INSERT')
def Insert():
try:
_json = request.json
_table = _json['table']
_columns = _json['columns']
_values = _json['values']
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
sqlQuery = f"INSERT INTO {_table}({_columns}) VALUES({_values})"
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
query = (sqlQuery)
cursor.execute(query)
conn.commit()
resp = jsonify(query)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/SELECT')
def Select():
try:
_json = request.json
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
_query = _json['query']
sqlQuery = f"{_query}"
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
query = (sqlQuery)
cursor.execute(query)
row = cursor.fetchall()
value = str(row)
resp = jsonify(value)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/DELETE')
def Delete():
try:
_json = request.json
_table = _json['table']
_where = _json['where']
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
sqlQuery = f"DELETE From {_table} where {_where}"
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
query = (sqlQuery)
cursor.execute(query)
conn.commit()
resp = jsonify(query)
resp.status_code = 200
return resp
except Exception as e:
print(e)
@app.route('/AdminQuery')
def Query():
try:
_json = request.json
_query = _json['query']
app.config['MYSQL_DATABASE_USER'] = _json['UserName']
app.config['MYSQL_DATABASE_PASSWORD'] = _json['Password']
sqlQuery = f"{_query}"
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
query = (sqlQuery)
cursor.execute(query)
conn.commit()
resp = jsonify(query)
resp.status_code = 200
return resp
except Exception as e:
print(e)
if __name__ == "__main__":
app.run(debug=True)