Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import csv | |
| import os | |
| # Hard-coded file path for consultation data | |
| consultation_file_path = "consultations.csv" | |
| patient_file_path = "patients.csv" | |
| # Function to get patient details by ID | |
| def get_patient_details(patient_id): | |
| with open(patient_file_path, mode='r') as file: | |
| reader = csv.DictReader(file) | |
| for row in reader: | |
| if row["Patient ID"] == patient_id: | |
| return row["Name"] | |
| return "" | |
| # Function for consultation | |
| def consultation_ui(patient_id, height, weight, diastolic_bp, systolic_bp, temperature, complaints, drug_name, frequency, number, test_name, department, lab_tests, revisit_date, revisit_time): | |
| patient_name = get_patient_details(patient_id) | |
| if patient_name: | |
| prescription = f"{drug_name} - {frequency} - {number}" | |
| lab_investigations = f"TEST Name: {test_name}, Department: {department}, Additional Tests: {lab_tests}" | |
| with open(consultation_file_path, mode='a', newline='') as file: | |
| writer = csv.writer(file) | |
| writer.writerow([patient_id, patient_name, height, weight, diastolic_bp, systolic_bp, temperature, complaints, prescription, lab_investigations, revisit_date, revisit_time]) | |
| return f"Consultation for {patient_name} recorded successfully!" | |
| else: | |
| return "Patient ID not found." | |
| # Gradio UI for Consultation | |
| def consultation_interface(patient_id, height, weight, diastolic_bp, systolic_bp, temperature, complaints, drug_name, frequency, number, test_name, department, lab_tests, revisit_date, revisit_time): | |
| patient_name = get_patient_details(patient_id) | |
| return consultation_ui(patient_id, height, weight, diastolic_bp, systolic_bp, temperature, complaints, drug_name, frequency, number, test_name, department, lab_tests, revisit_date, revisit_time), patient_name | |
| app = gr.Blocks() | |
| with app: | |
| with gr.Tab("Consultation"): | |
| patient_id = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID", lines=1) | |
| patient_name = gr.Textbox(label="Patient Name", interactive=False, lines=1) | |
| height = gr.Textbox(label="Height (cm)", placeholder="Enter height in cm", lines=1) | |
| weight = gr.Textbox(label="Weight (kg)", placeholder="Enter weight in kg", lines=1) | |
| diastolic_bp = gr.Textbox(label="Diastolic BP (mm Hg)", placeholder="Enter diastolic BP", lines=1) | |
| systolic_bp = gr.Textbox(label="Systolic BP (mm Hg)", placeholder="Enter systolic BP", lines=1) | |
| temperature = gr.Textbox(label="Temperature (°C)", placeholder="Enter temperature", lines=1) | |
| complaints = gr.Textbox(label="Chief Complaints", placeholder="Enter complaints", lines=3) | |
| # Prescription with sub-fields for Drug Name, Frequency, Number | |
| drug_name = gr.Textbox(label="Drug Name", placeholder="Enter drug name", lines=1) | |
| frequency = gr.Dropdown(label="Frequency", choices=["every other day", "q.a.m.", "q.d.", "q.d.s.", "q.p.m.", "q.h.", "q.h.s.", "q.1 h", "q.i.d.", "q4PM", "q.o.d.", "qqh"]) | |
| number = gr.Textbox(label="Number", placeholder="Enter number", lines=1) | |
| test_name = gr.Textbox(label="Test Name", placeholder="Enter test name", lines=1) | |
| department = gr.Textbox(label="Department", placeholder="Enter department", lines=1) | |
| lab_tests = gr.Textbox(label="Lab Tests", placeholder="Enter additional tests", lines=3) | |
| revisit_date = gr.HTML(""" | |
| <input type="date" id="revisit_date" name="revisit_date"> | |
| """) | |
| revisit_time = gr.HTML(""" | |
| <input type="time" id="revisit_time" name="revisit_time"> | |
| """) | |
| patient_id.change(lambda pid: get_patient_details(pid), inputs=patient_id, outputs=patient_name) | |
| consultation_output = gr.Textbox(label="Consultation Status", lines=1) | |
| gr.Button("Submit Consultation").click(consultation_interface, inputs=[patient_id, height, weight, diastolic_bp, systolic_bp, temperature, complaints, drug_name, frequency, number, test_name, department, lab_tests, revisit_date, revisit_time], outputs=[consultation_output, patient_name]) | |
| app.launch() | |