-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHome.py
175 lines (165 loc) · 8.88 KB
/
Home.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
from flask import render_template,Blueprint,request,redirect,url_for,session,make_response
from phonenumbers.phonenumber import PhoneNumber
from functions import *
from phonenumbers import geocoder
from phonenumbers import carrier
import phonenumbers
from models.models import *
from config import *
import bcrypt
#open the connection
connection = open_connection("hospital.db")
cursor = get_cursor(connection)
Database_Setup(cursor)
activate_Fks(cursor)
HomePage=Blueprint("Home",__name__)
@HomePage.route('/',methods=["GET"])
@HomePage.route('/home',methods=["GET"])
def mainpage():
#count = Select_count_Department(cursor)
connection.commit()
DataDp = selectFromTable(cursor,'Department',Department_attributes,[Deparment.All.value],[])
Manager_Data = select_All_manager_name(cursor)
Donations = select_Donations(cursor)
count =count_donations(cursor)
if(len(count) ==0):
count = [("Blood",0),("Equipment",0),("Money",0)]
Admin = selectFromTable(cursor,'Employee',Employee_attributes,[Employee.All.value],[(Employee.Group_id.value,'A')])
if(len(Admin) == 0):
Admin = [(0,"","")]
return render_template('HomePage.html',Principle = Admin,Donations =count,Manager_Data =Manager_Data,data_of_department = DataDp,no_departments = count[0][0],Data=session) # pass your Data here like Departments & Donations & all other informations
################################################################################################################################################
@HomePage.route('/home',methods=["POST"])
def make_donation():
if (request.method == "POST"):
if("ID" not in session):
donationtype = request.form.get("donationtype")
bloodtype = request.form.get("bloodtype")
DonorFname = request.form.get("DonorFname")
DonorLname = request.form.get("DonorLname")
DonorEmail = request.form.get("DonorEmail")
Donorphone = request.form.get("Donorphone")
if(DonorFname == "" or DonorLname == "" or DonorEmail == "" or Donorphone == "" ):
return redirect("/error")
else:
donationtype = request.form.get("donationtype")
bloodtype = request.form.get("bloodtype")
if('Group_id' not in session):
patient_data = selectFromTable(cursor,"Patient",Patient_attributes,[Patient.All.value],[(Patient.Patient_ID.value,session["ID"])])
DonorFname = patient_data[0][1]
DonorLname = patient_data[0][2]
DonorEmail = patient_data[0][10]
Donorphone = patient_data[0][5]
else:
employee_data = selectFromTable(cursor,"Employee",Employee_attributes,[Employee.All.value],[(Employee.Employee_ID.value,session["ID"])])
DonorFname = employee_data[0][1]
DonorLname = employee_data[0][2]
DonorEmail = employee_data[0][10]
Donorphone = employee_data[0][5]
Columns = [Donor.All.value]
Values = [bloodtype,DonorFname,DonorLname,DonorEmail,Donorphone]
is_added = insert_general(cursor,"Doner",Donor_attributes,Columns,Values)
connection.commit()
Columns = [Donor.Donor_ID.value]
Values = [(Donor.Donor_Blood_Type.value,bloodtype),(Donor.Donor_Fname.value,DonorFname),
(Donor.Donor_Lname.value,DonorLname),(Donor.Donor_Email.value,DonorEmail),(Donor.Donor_phonenumber.value,Donorphone)]
donor_id = selectFromTable(cursor,"Doner",Donor_attributes,Columns,Values)
Columns = [Donation.All.value]
Values = [get_time_now_as_text(),donationtype,donor_id[0][0],"W"]
is_added = insert_general(cursor,"Donation" ,Donation_attributes,Columns,Values)
connection.commit()
return redirect("/home")
else:
return redirect("/error")
#############################################################################################################################
@HomePage.route('/Departments/<ID_Department>',methods=["GET"])
def Dapartments(ID_Department):
# no_rooms = select_rooms_number(cursor,ID_Department)
Manager_name = select_manager_name(cursor,ID_Department)
Doctors = selectFromTable(cursor,'Employee',Employee_attributes,[Employee.All.value],[(Employee.Group_id.value,'D'),(Employee.D_id.value,ID_Department)])
Data_Department = selectFromTable(cursor,'Department',Department_attributes,[Deparment.All.value],[(Deparment.Department_ID.value,ID_Department)])
return render_template('Departments.html',Data=session,Manager_name =Manager_name,Data_Department=Data_Department,Doctors =Doctors) # pass your Data here like Departments & Donations & all other informations
####################################################################################################
@HomePage.route('/Departments/<ID_Department>',methods=["POST"])
def Make_Appointment(ID_Department):
if (request.method == "POST"):
doctor_id = request.form.get("doctor_id")
appointment = request.form.get("appointment")
type = str(request.form.get("type")) + str(ID_Department)
is_added = insert_reservation(cursor, get_time_now_as_text(), appointment, 'W', type, doctor_id, session['ID'])
connection.commit()
if(is_added):
return redirect("/home")
else:
return redirect("/error")#"Error 404"
else:
return redirect("/error")
#################################################################################################################
#from the signup page
#TODO:(validations to the input data)
@HomePage.route("/signup/home",methods=["POST"])
def SignupHome():
if (request.method == "POST"):
# checks on the data from the user in signup
# take the variables
#////////////////////////////////////////////////////////////
password=request.form.get("password")
# Ahmed Alaa Edited here (Start)
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
password = hashed_password.decode('utf-8')
email=request.form.get("email")
Fname=request.form.get('Fname')
Lname=request.form.get('Lname')
AddressCountry=request.form.get('country')
AddressCity=request.form.get('city')
AddressStreet=request.form.get('street')
PhoneCountry="+"+str(codes[recode(AddressCountry)])
phoneNumber =request.form.get('Number')
#///////////////////////////////////////////////////////////////////
phone = phonenumbers.parse(PhoneCountry+phoneNumber)
if not(has_numbers(Fname)) and not(has_numbers(Lname)and(phonenumbers.is_valid_number(phone))):
Columns = [Patient.All.value]
Values =[Fname, Lname, 20 ,PhoneCountry, str(phoneNumber), AddressCountry, AddressCity, AddressStreet, "M", email, password,"None"]
is_added = insert_general(cursor,'Patient',Patient_attributes,Columns,Values)
if(is_added):
connection.commit()
result1= selectFromTable(cursor,"Patient",Patient_attributes,[Patient.Patient_ID.value],[(Patient.Email.value,email),(Patient.Password.value,password)])
session['ID'] =result1[0][0]
session["Email"] =email
return redirect("/home")
else:
return redirect('/error')
else:
return redirect('/signup')
else:
return redirect("/error")
###########################################################################################################################################
@HomePage.route("/login/home",methods=["POST"])
def LoginHome():
if(request.method=="POST"):
# from the login page
#TODO:query to ckeck if the email and the password is correct
#if the data is not correct the will direct to the login ag
password=request.form.get("password")
email=request.form.get("email")
result1= selectFromTable(cursor,"Patient",Patient_attributes,[Patient.All.value],[(Patient.Email.value,email)])
result2= selectFromTable(cursor,"Employee",Employee_attributes,[Employee.All.value],[(Employee.Email.value,email)])
if len(result1)!=0:
if bcrypt.checkpw(password.encode('utf-8'), result1[0][11].encode('utf-8')):
session['ID'] =result1[0][0]
session["Email"] =email
return redirect("/home")
else:
return redirect("/error")
elif len(result2)!=0:
if bcrypt.checkpw(password.encode('utf-8'), result2[0][11].encode('utf-8')):
session['ID'] =result2[0][0]
session['Group_id'] =result2[0][-1]
session["Email"] =email
return redirect("/home")
else :
return redirect("/error")
else:
return redirect("/login")
else:
return redirect("/error")