-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.py
More file actions
141 lines (100 loc) · 4.6 KB
/
user.py
File metadata and controls
141 lines (100 loc) · 4.6 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
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
from datetime import date
from enum import Enum
class MentalHealthIssue(Enum):
DEPRESSION = "Depression"
ANXIETY = "Anxiety"
BIPOLAR = "Bipolar Disorder"
SCHIZOPHRENIA = "Schizophrenia"
PTSD = "Post-Traumatic Stress Disorder"
OCD = "Obsessive-Compulsive Disorder"
class Appointment:
_counter = 0
def __init__(self, date, time, psychiatrist, patient):
self.date = date
self.time = time
self.psychiatrist = psychiatrist
self.patient = patient
self._id = Appointment._counter
Appointment._counter += 1
def __str__(self):
return f"Appointment #{self._id} with Dr. {self.psychiatrist.last_name} at {self.time} on {self.date}"
@staticmethod
def get_appointment_count():
return Appointment._counter
class User:
def __init__(self, first_name, last_name, username, email, password, birth_date, id):
self.first_name = first_name
self.last_name = last_name
self.username = username
self.email = email
self.__password = password
self.birth_date = birth_date
self.id = id
self.appointments = []
def login(self, username, password):
return username == self.username and password == self.__password
def __str__(self):
return f"{self.first_name} {self.last_name}"
def add_appointment(self, appointment):
self.appointments.append(appointment)
def get_age(self):
today = date.today()
return today.year - self.birth_date.year - (
(today.month, today.day) < (self.birth_date.month, self.birth_date.day)
)
class Psychiatrist(User):
def __init__(self, first_name, last_name, username, email, password, birth_date, specialization, id):
super().__init__(first_name, last_name, username, email, password, birth_date, id)
self.specialization = specialization
self._patients = set()
def __str__(self):
return f"Dr. {self.last_name} - {self.specialization}"
def add_patient(self, patient):
self._patients.add(patient)
def get_patient_count(self):
return len(self._patients)
class Patient(User):
def __init__(self, first_name, last_name, username, email, password, birth_date, id):
super().__init__(first_name, last_name, username, email, password, birth_date, id)
self.diagnoses = []
self._medical_history = ""
def add_diagnosis(self, issue: MentalHealthIssue):
if issue not in self.diagnoses:
self.diagnoses.append(issue)
def remove_diagnosis(self, issue: MentalHealthIssue):
if issue in self.diagnoses:
self.diagnoses.remove(issue)
def update_medical_history(self, new_info):
self._medical_history += f"\n{date.today()}: {new_info}"
def __str__(self):
return f"{super().__str__()}"
if __name__ == "__main__":
psychiatrist = Psychiatrist("John", "Doe", "johndoe", "john@clinic.com", "password123",
date(1975, 5, 15), "Clinical Psychiatrist", 1)
patient = Patient("Jane", "Smith", "janesmith", "jane@email.com", "pass456",
date(1990, 8, 20), 2)
print(psychiatrist)
print(patient)
print("\nLogin attempts:")
psychiatrist_login_success = psychiatrist.login("johndoe", "password123")
print(f"Psychiatrist login success: {psychiatrist_login_success}")
patient_login_success = patient.login("janesmith", "pass456")
print(f"Patient login success: {patient_login_success}")
patient_login_fail = patient.login("janesmith", "wrongpassword")
print(f"Patient login success with wrong password: {patient_login_fail}")
patient.add_diagnosis(MentalHealthIssue.ANXIETY)
patient.add_diagnosis(MentalHealthIssue.DEPRESSION)
psychiatrist.add_patient(patient)
users = [psychiatrist, patient]
for user in users:
print(f"{user} - Age: {user.get_age()}")
appointment = Appointment(date(2024, 10, 5), "14:00", psychiatrist, patient)
psychiatrist.add_appointment(appointment)
patient.add_appointment(appointment)
print(f"\nCreated appointment: {appointment}")
print(f"Total appointments: {Appointment.get_appointment_count()}")
print(f"\nPatient's diagnoses: {', '.join([issue.value for issue in patient.diagnoses])}")
patient.remove_diagnosis(MentalHealthIssue.ANXIETY)
print(f"Updated patient's diagnoses: {', '.join([issue.value for issue in patient.diagnoses])}")
patient.update_medical_history("Initial consultation completed. Prescribed antidepressants.")
print(f"\nPsychiatrist's patient count: {psychiatrist.get_patient_count()}")