-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatient.py
96 lines (87 loc) · 3.49 KB
/
patient.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
import mysql.connector
def add_patient():
cnx = mysql.connector.connect(user='Rich', password='1234', host='127.0.0.1', database='hospital_db')
cursor = cnx.cursor()
query = ("INSERT INTO patient (pat_no,first_name,last_name,appointment_date,discharged,assigned_doctor_id) VALUES (%s,%s,%s,%s,%s,%s)")
while True:
try:
id = int(input('\nEnter patient ID: '))
break
except ValueError:
print("Please input integer only...")
continue
first_name = input('Enter patient first name: ')
last_name = input('Enter patient last name: ')
appoint_date = input('Enter patient appointment date (use YYYY-MM-DD format): ')
discharged = input('Enter Y or N for discharged: ')
while True:
try:
doctor_id = int(input('Enter doctor ID: '))
break
except ValueError:
print("Please input integer only...")
continue
data = (id, first_name, last_name, appoint_date, discharged, doctor_id)
cursor.execute(query, data)
cnx.commit()
print('\nPatient added successfully!')
cnx.close()
def view_all_patients():
cnx = mysql.connector.connect(user='Rich', password='1234', host='127.0.0.1', database='hospital_db')
cursor = cnx.cursor()
cursor.execute("SELECT * FROM patient")
query = cursor.fetchall()
print('\nPatient ID\tFirst Name\tLast Name\tAppointment Date\tDischarged\tDoctor ID')
for (pat_no, first_name, last_name, appointment_date, discharged, assigned_doctor_id) in query:
print("{:<15} {:<15} {:<15} {:<23} {:<15} {:<15}".format(
pat_no, first_name, last_name, str(appointment_date), discharged, assigned_doctor_id))
cnx.close()
def update_patient():
cnx = mysql.connector.connect(user='Rich', password='1234', host='127.0.0.1', database='hospital_db')
cursor = cnx.cursor()
while True:
try:
id = int(input('\nEnter patient ID: '))
break
except ValueError:
print("Please input integer only...")
continue
first_name = input('Enter patient first name: ')
last_name = input('Enter patient last name: ')
appointment_date = input('Enter patient appointment date (use YYYY-MM-DD format): ')
discharged = input('Enter Y or N for discharged: ')
while True:
try:
doctor_id = int(input('Enter doctor ID: '))
break
except ValueError:
print("Please input integer only...")
continue
query = ("UPDATE patient SET first_name = %s, last_name = %s, appointment_date = %s, discharged = %s, assigned_doctor_id = %s WHERE pat_no = %s")
data = (first_name, last_name, appointment_date, discharged, doctor_id, id)
cursor.execute(query, data)
cnx.commit()
if cursor.rowcount == 0:
print('ID not found!')
else:
print('\nPatient updated successfully!')
cnx.close()
def delete_patient():
cnx = mysql.connector.connect(user='Rich', password='1234', host='127.0.0.1', database='hospital_db')
cursor = cnx.cursor()
while True:
try:
id = int(input('\nEnter patient ID: '))
break
except ValueError:
print("Please input integer only...")
continue
query = ("DELETE FROM patient WHERE pat_no = %s")
data = (id,)
cursor.execute(query, data)
cnx.commit()
if cursor.rowcount == 0:
print('ID not found!')
else:
print('\nPatient deleted successfully!')
cnx.close()