Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import datetime | |
| import random | |
| # Load sample data from CSV files | |
| patients = pd.read_csv('patients.csv') | |
| consultations = pd.read_csv('consultations.csv') | |
| appointments = pd.read_csv('appointments.csv') | |
| reports = pd.read_csv('reports.csv') | |
| def generate_jitsi_link(doctor_name, appointment_date): | |
| meeting_id = f"{doctor_name}_{appointment_date.replace(' ', '_')}_{random.randint(1000, 9999)}" | |
| return f"https://meet.jit.si/{meeting_id}" | |
| def register_patient(name, age, contact): | |
| if not name or age <= 0 or not contact: | |
| return "Error: Please provide valid details." | |
| global patients | |
| new_id = patients['ID'].max() + 1 if not patients.empty else 1 | |
| new_patient = pd.DataFrame([[new_id, name, age, contact]], columns=['ID', 'Name', 'Age', 'Contact']) | |
| patients = pd.concat([patients, new_patient], ignore_index=True) | |
| patients.to_csv('patients.csv', index=False) | |
| return f"Patient {name} registered successfully with ID {new_id}" | |
| def view_consultations(patient_id): | |
| if patient_id <= 0: | |
| return "Error: Please provide a valid patient ID." | |
| records = consultations[consultations['PatientID'] == patient_id] | |
| if not records.empty: | |
| return records | |
| else: | |
| return pd.DataFrame(columns=['ID', 'PatientID', 'DoctorName', 'Date', 'Diagnosis', 'Prescription']) | |
| def book_appointment(patient_id, doctor_name, appointment_date): | |
| if patient_id <= 0 or not doctor_name or not appointment_date: | |
| return "Error: Please provide valid details." | |
| global appointments | |
| new_id = appointments['ID'].max() + 1 if not appointments.empty else 1 | |
| jitsi_link = generate_jitsi_link(doctor_name, appointment_date) | |
| new_appointment = pd.DataFrame([[new_id, patient_id, doctor_name, appointment_date, jitsi_link]], columns=['ID', 'PatientID', 'DoctorName', 'Date', 'JitsiLink']) | |
| appointments = pd.concat([appointments, new_appointment], ignore_index=True) | |
| appointments.to_csv('appointments.csv', index=False) | |
| return f"Appointment booked successfully with Dr. {doctor_name} on {appointment_date}. Join the meeting at: {jitsi_link}" | |
| def add_report(patient_id, report_date, report_link): | |
| if patient_id <= 0 or not report_date or not report_link: | |
| return "Error: Please provide valid details." | |
| global reports | |
| new_id = reports['ID'].max() + 1 if not reports.empty else 1 | |
| new_report = pd.DataFrame([[new_id, patient_id, report_date, report_link]], columns=['ID', 'PatientID', 'Date', 'ReportLink']) | |
| reports = pd.concat([reports, new_report], ignore_index=True) | |
| reports.to_csv('reports.csv', index=False) | |
| return f"Report added successfully for patient ID {patient_id}." | |
| def view_appointments_and_reports(patient_id): | |
| if patient_id <= 0: | |
| return "Error: Please provide a valid patient ID." | |
| upcoming_appointments = appointments[appointments['PatientID'] == patient_id] | |
| patient_reports = reports[reports['PatientID'] == patient_id] | |
| if not upcoming_appointments.empty: | |
| upcoming_appointments['JitsiLink'] = upcoming_appointments['JitsiLink'].apply(lambda x: f'<a href="{x}" target="_blank">{x}</a>') | |
| return upcoming_appointments, patient_reports | |
| def jitsi_iframe(appointment_id): | |
| if appointment_id <= 0: | |
| return "Error: Please provide a valid appointment ID." | |
| appointment = appointments.loc[appointments['ID'] == appointment_id] | |
| if appointment.empty: | |
| return "No meeting link found for this appointment." | |
| jitsi_link = appointment['JitsiLink'].values[0] | |
| if jitsi_link: | |
| return f'<iframe src="{jitsi_link}" style="width: 100%; height: 600px; border: 0;" allow="camera; microphone; fullscreen; display-capture"></iframe>' | |
| return "No meeting link found for this appointment." | |
| # Load images for UI | |
| register_image = "https://via.placeholder.com/800x400.png?text=Register+Image" | |
| consultation_image = "https://via.placeholder.com/800x400.png?text=Consultation+Image" | |
| appointment_image = "https://via.placeholder.com/800x400.png?text=Appointment+Image" | |
| report_image = "https://via.placeholder.com/800x400.png?text=Report+Image" | |
| # Define Gradio interfaces with images and styles | |
| register_interface = gr.Interface( | |
| fn=register_patient, | |
| inputs=[gr.Textbox(label="Name"), gr.Number(label="Age"), gr.Textbox(label="Contact")], | |
| outputs="text", | |
| title="Register Patient", | |
| description="Register new patients by filling out their details below.", | |
| article=register_image | |
| ) | |
| view_consultations_interface = gr.Interface( | |
| fn=view_consultations, | |
| inputs=gr.Number(label="Patient ID"), | |
| outputs="dataframe", | |
| title="View Previous Consultations", | |
| description="View previous consultations and prescriptions for a patient.", | |
| article=consultation_image | |
| ) | |
| book_appointment_interface = gr.Interface( | |
| fn=book_appointment, | |
| inputs=[gr.Number(label="Patient ID"), gr.Textbox(label="Doctor Name"), gr.Textbox(label="Appointment Date")], | |
| outputs="text", | |
| title="Book Appointment", | |
| description="Book an appointment with a doctor.", | |
| article=appointment_image | |
| ) | |
| add_report_interface = gr.Interface( | |
| fn=add_report, | |
| inputs=[gr.Number(label="Patient ID"), gr.Textbox(label="Report Date"), gr.Textbox(label="Report Link")], | |
| outputs="text", | |
| title="Add Report", | |
| description="Add a new report for a patient.", | |
| article=report_image | |
| ) | |
| view_appointments_reports_interface = gr.Interface( | |
| fn=view_appointments_and_reports, | |
| inputs=gr.Number(label="Patient ID"), | |
| outputs=[gr.HTML(label="Upcoming Appointments"), gr.Dataframe(label="Reports")], | |
| title="View Appointments and Reports", | |
| description="View upcoming appointments and reports for a patient.", | |
| article=report_image | |
| ) | |
| join_meeting_interface = gr.Interface( | |
| fn=jitsi_iframe, | |
| inputs=gr.Number(label="Appointment ID"), | |
| outputs="html", | |
| title="Join Meeting", | |
| description="Join the online meeting with your doctor." | |
| ) | |
| app = gr.TabbedInterface([ | |
| register_interface, | |
| view_consultations_interface, | |
| book_appointment_interface, | |
| add_report_interface, | |
| view_appointments_reports_interface, | |
| join_meeting_interface | |
| ], [ | |
| "Register Patient", | |
| "View Consultations", | |
| "Book Appointment", | |
| "Add Report", | |
| "View Appointments and Reports", | |
| "Join Meeting" | |
| ]) | |
| if __name__ == "__main__": | |
| app.launch() | |