-
Notifications
You must be signed in to change notification settings - Fork 0
/
Patient.py
121 lines (100 loc) · 3.94 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
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
from Person import *
import os
import pandas as pd
class Patient(Person):
"""
'Patient' is another subclass of 'Person' and includes attributes like 'patient_id' and a reference to the assigned 'doctor'.
"""
__patient_counter = 1
__doctor_patient_db = "doctor_patient.csv"
__doctors_db = "doctors.csv"
__patients_db = "patients.csv"
def count_rows_csv(file_path):
try:
with open(file_path, 'rb') as file:
line_count = sum(1 for line in file)
return line_count
except Exception as e:
return 1
if __patient_counter == 1 and os.path.isfile("patients.csv"):
__patient_counter = count_rows_csv("patients.csv")
def __init__(self, name, age, gender, phone):
super().__init__(name, age, gender, phone)
self.patient_id = f"PID_{Patient.__patient_counter:03d}"
Patient.__patient_counter += 1
self.doctor = None
@classmethod
def empty_patient_constructor(cls):
cls.name = ""
cls.age = ""
cls.gender = ""
cls.phone = ""
return cls(cls.name,
cls.age,
cls.gender,
cls.phone,
)
def check_doctor_db(self, doctor_name, doctor_phone):
"""
Return True If Doctor Already EXist, and False if Not
"""
if os.path.isfile(Patient.__doctors_db):
df = pd.read_csv(Patient.__doctors_db)
doctor_phone = f"'{doctor_phone}'" # Same Stored Format
filt = (df["Name"] == doctor_name) & (
df["Phone"] == doctor_phone)
if sum(filt) == 1:
return True
else:
return False
else:
return False
def check_patient_db(self, patient_id, patient_name):
"""
Return True If Patient Already EXist, and False if Not
"""
if os.path.isfile(Patient.__patients_db):
df = pd.read_csv(Patient.__patients_db)
filt = (df["Name"] == patient_name) & (
df["Patient_ID"] == patient_id)
if sum(filt) == 1:
return True
else:
return False
else:
return False
def assign_doctor_to_pateint(slef, doctor_name, doctor_phone, patient_id, patient_name):
if slef.check_doctor_db(doctor_name, doctor_phone) and slef.check_patient_db(patient_id, patient_name):
doctor_phone = f"'{doctor_phone}'"
row_to_check = pd.Series({"Doctor": doctor_name,
"Doctor_Phone": doctor_phone,
"Patient": patient_name,
"Patient_ID": patient_id})
if os.path.isfile(Patient.__doctor_patient_db):
# Read Doctors_Nurse DB
df = pd.read_csv(Patient.__doctor_patient_db)
# To Check if The Nurse Already In The Doctor's Team
# => True if There is No Duplicates
if df[df.eq(row_to_check).all(axis=1)].empty:
df_to_append = pd.DataFrame([row_to_check])
pd.concat([df, df_to_append]).drop_duplicates().to_csv(
Patient.__doctor_patient_db, index=False)
else:
return -1
else:
df = pd.DataFrame([row_to_check])
df.to_csv(Patient.__doctor_patient_db, index=False)
else:
return False
def assign_doctor(self, doctor):
self.doctor = doctor
print(f"{self.name} assigned to Dr. {doctor.name}")
def display_info(self):
super().display_info()
print(f"Patient ID: {self.patient_id}")
if self.doctor:
print(f"Assigned Doctor: {self.doctor.name}")
else:
print("No assigned doctor.")
def get_patient_id(self):
return self.patient_id