-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathfetchAccessMap.py
More file actions
45 lines (33 loc) · 1.19 KB
/
fetchAccessMap.py
File metadata and controls
45 lines (33 loc) · 1.19 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
from mysql import connector
def fetchAccessMap(userEmail,
dbConnection,
patientOrDoctor # "doctor" or "patient"
):
cursor = dbConnection.cursor()
if patientOrDoctor == "doctor":
query = ("SELECT u.FirstName, u.LastName, u.Email FROM users u"
"JOIN accessMap AM"
"ON AM.patient = u.Email"
"WHERE AM.doctor = %(EmailVal)s"
)
else:
query = ("SELECT u.FirstName, u.LastName, u.Email FROM users u"
"JOIN accessMap AM "
"ON AM.doctor = u.Email"
"WHERE AM.patient = %(EmailVal)s"
)
queryData = {
'emailVal': userEmail
} # user primary key
try:
cursor.execute(query, queryData) # execute the changes
except:
return 2 #errorval
returnList = []
for (FirstName, LastName, Email) in cursor:
# iterate through a set of tuples
# the tuples are the rows
returnList.append((FirstName, LastName, Email))
cursor.close() # close cursor
dbConnection.close() # close connection
return returnList #return the map