Spaces:
Sleeping
Sleeping
Create book_appointment.py
Browse files- book_appointment.py +73 -0
book_appointment.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import csv
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Hard-coded file path for appointment data
|
| 6 |
+
appointment_file_path = "appointments.csv"
|
| 7 |
+
patient_file_path = "patients.csv"
|
| 8 |
+
|
| 9 |
+
# Function to get patient details by ID
|
| 10 |
+
def get_patient_details(patient_id):
|
| 11 |
+
with open(patient_file_path, mode='r') as file:
|
| 12 |
+
reader = csv.DictReader(file)
|
| 13 |
+
for row in reader:
|
| 14 |
+
if row["Patient ID"] == patient_id:
|
| 15 |
+
return row["Name"]
|
| 16 |
+
return ""
|
| 17 |
+
|
| 18 |
+
# Function to get doctor names based on selected speciality
|
| 19 |
+
def get_doctors_by_speciality(speciality):
|
| 20 |
+
doctors = {
|
| 21 |
+
"ORTHOPEDICS": ["DR. UDAY KUMAR", "DR. SINDHU", "DR. MURALI"],
|
| 22 |
+
"CARDIOLOGY": ["DR. RAVI", "DR. RAMU", "DR. KRISHNA"],
|
| 23 |
+
"GENERAL MEDICINES": ["DR. SURESH"],
|
| 24 |
+
"NEPHROLOGY": ["DR. GIRISH", "DR. NAVESH"],
|
| 25 |
+
"NEUROLOGY": ["DR. DURGESH"]
|
| 26 |
+
}
|
| 27 |
+
return doctors.get(speciality, [])
|
| 28 |
+
|
| 29 |
+
# Function to book an appointment
|
| 30 |
+
def book_appointment_ui(patient_id, speciality, doctor_name, appointment_date, appointment_time):
|
| 31 |
+
patient_name = get_patient_details(patient_id)
|
| 32 |
+
if patient_name:
|
| 33 |
+
with open(appointment_file_path, mode='a', newline='') as file:
|
| 34 |
+
writer = csv.writer(file)
|
| 35 |
+
writer.writerow([patient_id, patient_name, speciality, doctor_name, appointment_date, appointment_time])
|
| 36 |
+
return f"Appointment for {patient_name} with {doctor_name} on {appointment_date} at {appointment_time} booked successfully!"
|
| 37 |
+
else:
|
| 38 |
+
return "Patient ID not found."
|
| 39 |
+
|
| 40 |
+
# Gradio UI for Book Appointment
|
| 41 |
+
def book_appointment_interface(patient_id, speciality, doctor_name, appointment_date, appointment_time):
|
| 42 |
+
patient_name = get_patient_details(patient_id)
|
| 43 |
+
return book_appointment_ui(patient_id, speciality, doctor_name, appointment_date, appointment_time), patient_name
|
| 44 |
+
|
| 45 |
+
def update_doctor_dropdown(speciality):
|
| 46 |
+
return gr.update(choices=get_doctors_by_speciality(speciality))
|
| 47 |
+
|
| 48 |
+
app = gr.Blocks()
|
| 49 |
+
|
| 50 |
+
with app:
|
| 51 |
+
with gr.Tab("Book Appointment"):
|
| 52 |
+
patient_id = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID", lines=1)
|
| 53 |
+
patient_name = gr.Textbox(label="Patient Name", interactive=False, lines=1)
|
| 54 |
+
|
| 55 |
+
speciality = gr.Dropdown(label="Speciality", choices=["ORTHOPEDICS", "CARDIOLOGY", "GENERAL MEDICINES", "NEPHROLOGY", "NEUROLOGY"])
|
| 56 |
+
|
| 57 |
+
doctor_name = gr.Dropdown(label="Doctor Name", choices=[])
|
| 58 |
+
|
| 59 |
+
# Use HTML for date and time selection
|
| 60 |
+
appointment_date = gr.HTML("""
|
| 61 |
+
<input type="date" id="appointment_date" name="appointment_date">
|
| 62 |
+
""")
|
| 63 |
+
appointment_time = gr.HTML("""
|
| 64 |
+
<input type="time" id="appointment_time" name="appointment_time">
|
| 65 |
+
""")
|
| 66 |
+
|
| 67 |
+
speciality.change(update_doctor_dropdown, inputs=speciality, outputs=doctor_name)
|
| 68 |
+
patient_id.change(lambda pid: get_patient_details(pid), inputs=patient_id, outputs=patient_name)
|
| 69 |
+
|
| 70 |
+
appointment_output = gr.Textbox(label="Appointment Status", lines=1)
|
| 71 |
+
gr.Button("Book Appointment").click(book_appointment_interface, inputs=[patient_id, speciality, doctor_name, appointment_date, appointment_time], outputs=[appointment_output, patient_name])
|
| 72 |
+
|
| 73 |
+
app.launch()
|