Plan du Programme
- Gestion des Patients
- Suivi des Médicaments
- Planification des Rendez-vous
- Notifications et Rappels
Voici le code Python pour l’assistant de soins en gérontologie :
import datetime
import time
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
class Patient:
def __init__(self, id, name, age, medical_conditions, medications):
self.id = id
self.name = name
self.age = age
self.medical_conditions = medical_conditions
self.medications = medications
self.appointments = []
def add_appointment(self, appointment):
self.appointments.append(appointment)
class Medication:
def __init__(self, name, dosage, frequency):
self.name = name
self.dosage = dosage
self.frequency = frequency
class Appointment:
def __init__(self, date, time, description):
self.date = date
self.time = time
self.description = description
class GeriatricCareAssistant:
def __init__(self):
self.patients = []
def add_patient(self, patient):
self.patients.append(patient)
def get_patient(self, id):
for patient in self.patients:
if patient.id == id:
return patient
return None
def schedule_appointment(self, patient_id, date, time, description):
patient = self.get_patient(patient_id)
if patient:
appointment = Appointment(date, time, description)
patient.add_appointment(appointment)
print(f"Appointment scheduled for {patient.name} on {date} at {time}.")
else:
print("Patient not found.")
def check_medications(self):
current_time = datetime.datetime.now().time()
for patient in self.patients:
for medication in patient.medications:
if current_time >= medication.frequency:
self.send_notification(patient, medication)
def send_notification(self, patient, medication):
email = "youremail@example.com"
password = "yourpassword"
recipient = "recipient@example.com"
subject = "Medication Reminder"
body = f"Dear {patient.name}, it's time to take your medication: {medication.name} - {medication.dosage}."
msg = MIMEMultipart()
msg['From'] = email
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
try:
server = smtplib.SMTP('smtp.example.com', 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, recipient, text)
server.quit()
print(f"Notification sent to {patient.name}.")
except Exception as e:
print(f"Failed to send email: {str(e)}")
def show_patient_info(self, patient_id):
patient = self.get_patient(patient_id)
if patient:
print(f"Name: {patient.name}")
print(f"Age: {patient.age}")
print("Medical Conditions: ", ", ".join(patient.medical_conditions))
print("Medications:")
for med in patient.medications:
print(f" {med.name} - {med.dosage} - {med.frequency}")
print("Appointments:")
for app in patient.appointments:
print(f" {app.date} at {app.time} - {app.description}")
else:
print("Patient not found.")
def main():
assistant = GeriatricCareAssistant()
# Adding sample data
med1 = Medication("Aspirin", "100mg", datetime.time(8, 0))
med2 = Medication("Metformin", "500mg", datetime.time(18, 0))
patient1 = Patient(1, "John Doe", 75, ["Diabetes"], [med1, med2])
assistant.add_patient(patient1)
assistant.schedule_appointment(1, "2024-07-20", "10:00", "Routine Checkup")
while True:
assistant.check_medications()
time.sleep(60) # Check every minute
if __name__ == "__main__":
main()
Explications :
- Gestion des Patients : La classe
Patientpermet de stocker les informations sur les patients, y compris leurs conditions médicales, médicaments et rendez-vous. - Suivi des Médicaments : La classe
Medicationcontient les détails sur les médicaments, tels que le nom, le dosage et la fréquence de prise. La méthodecheck_medicationsdans la classeGeriatricCareAssistantvérifie si c’est l’heure de prendre des médicaments et envoie des notifications par email. - Planification des Rendez-vous : La classe
Appointmentpermet de créer des rendez-vous pour les patients. La méthodeschedule_appointmentpermet de planifier ces rendez-vous. - Notifications et Rappels : La méthode
send_notificationutilise le modulesmtplibpour envoyer des notifications par email aux patients pour les rappeler de prendre leurs médicaments.
Ce code constitue une base pour un assistant de soins en gérontologie. Des améliorations peuvent être apportées, telles que l’interface utilisateur graphique, l’intégration de bases de données, et des fonctionnalités supplémentaires pour répondre aux besoins spécifiques des soignants et des patients.