-
Notifications
You must be signed in to change notification settings - Fork 0
/
FirebaseRealtimeDB.py
84 lines (64 loc) · 2.07 KB
/
FirebaseRealtimeDB.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
import pyrebase
'''
Medical Information Format
info = { "name" : "Jonas",
"age" : "15",
"weight" : "145",
"height" : "5'10",
"blood type" : "A",
"dlid" : "122441",
"medical conditions" : "None",
"allergies" : "Sound",
"medication" : "None"
}
'''
config = {
'apiKey': "AIzaSyBLCdqXHMYP-Hm0maNclOpiWK-UsiQ-Eto",
'authDomain' : "medify-37830.firebaseapp.com",
'databaseURL': "https://medify-37830-default-rtdb.firebaseio.com",
'projectId' : "medify-37830",
'storageBucket' : "medify-37830.appspot.com",
'messagingSenderId' : "882712357939",
'appId' : "1:882712357939:web:f924a4b3f753079639c746",
'measurementId' : "G-5H0GB0Z7WQ"
}
firebase = pyrebase.initialize_app(config)
database = firebase.database()
auth = firebase.auth()
def login(email, password):
id_token = None
try:
id_token = auth.sign_in_with_email_and_password(email, password)["idToken"]
except:
print("Invalid credentials")
return id_token is not None
def create_acct(email, password):
auth.create_user_with_email_and_password(email, password)
def verify_emt(ems_id):
emt_list = database.child("emts").get().val()
return ems_id in emt_list
def update_patient_info(info):
patients = database.child("patients").get().val()
if info["dlid"] in patients:
for key in info:
patients[info["dlid"]][key] = info[key]
database.child("patients").set(patients)
else:
patients[info["dlid"]] = info
database.child("patients").set(patients)
def get_patient_info(dlid):
patient_info = None
try:
patient_info = database.child("patients").child(dlid).get().val()
except:
print("User not found!!!")
return patient_info
'''
def update_patient_info(info):
patients = database.child("patients").get().val()
if info["dlid"] in patients:
for key in info:
database.child("patients").child(info["dlid"]).update({key: info[key]})
else:
database.child("patients").set({info["dlid"] : info})
'''