-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhospitalrecordtracker.py
More file actions
93 lines (88 loc) · 2.52 KB
/
hospitalrecordtracker.py
File metadata and controls
93 lines (88 loc) · 2.52 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
import csv
c='y'
while c=='y':
print('1.add patients record\n',' 2.display patients records\n','3.update patients record\n','4.search in patients records\n','5. exit')
ch=int(input('enter your choice:'))
if ch==1:
add()
elif ch==2:
displayrecord()
elif ch==3:
updaterecord()
elif ch==4:
search()
else:
break
def add():
f=open('hospital.csv','w',newline='')
w=csv.writer(f)
w.writerow('id','name','age','gender','contact','department','category')
r=[]
while true:
i=int(input('enter id:'))
n=input('enter name:')
a=int(input('enter age'))
g=input('enter gender:')
c=int(input('enter contact number:'))
de=input('enter department;')
ca=input('are you doctor,patient or worker?')
s=[i,n,a,g,c,de,ca]
r.append(s)
ch=input('continue?')
if ch=='n':
break
for i in r:
w.writerow(i)
def displayrecord():
f=open('hospital.csv','r',newline='')
r=csv.reader(f)
for i in r:
print(i)
def updaterecord():
n=intput("enter id of patient you want to update record of: ")
rows=[]
f1=open('hospital.csv','w',newline='')
f2=open('hospital.csv','r')
r=csv.reader(f2)
rows=list(r)
w=csv.writer(f1)
print('''1. Update id
2. Update name
3. Update age
4. Update gender
5. Update contact
6. Update department
7. Exit''')
c = input('Enter choice: ')
for row in rows:
if row[0] == n:
if c == '1':
s = input('Enter updated id: ')
row[0] = s
elif c == '2':
s = input('Enter updated name: ')
row[1] = s
elif c == '3':
s = input('Enter updated age: ')
row[2] = s
elif c == '4':
s = input('Enter update gender: ')
row[3] = s
elif c == '5':
s = input('Enter updated contact: ')
row[4] = s
elif c == '6':
s = input('Enter updated department: ')
row[5] = s
else:
break
f1=open('hospital.csv', 'w', newline='')
w.writerows(rows)
def search():
f=open('hospital.csv','r')
n=input('enter some detail whose record is to be searched')
r=csv.reader(f)
for i in r:
if n in i:
print('found:',i)
f.close()