File size: 6,399 Bytes
4217e5f
 
 
 
 
 
 
 
 
b4add28
4217e5f
 
 
 
 
 
b4add28
 
4217e5f
 
 
 
 
 
 
 
b4add28
 
4217e5f
 
 
 
d0eadd2
4217e5f
 
b4add28
 
4217e5f
 
 
 
 
 
 
 
b4add28
 
 
 
 
 
 
 
 
 
8067507
b4add28
 
8067507
 
665bf0c
 
d0eadd2
b4add28
 
 
 
d0eadd2
 
 
 
b4add28
665bf0c
b4add28
 
4217e5f
 
 
 
33fa193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
665bf0c
33fa193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
665bf0c
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
142
143
144
145
146
147
148
149
150
151
152
153
154
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()