import gradio as gr import json from datetime import datetime from patient_registration import register_patient from test_selection import select_tests, get_tests_by_category from billing import fetch_billing # Load data def load_data(): try: with open("data.json", "r") as file: data = json.load(file) return data.get("patients", {}), data.get("last_sequence", {"year": None, "month": None, "number": 0}) except FileNotFoundError: return {}, {"year": None, "month": 0, "number": 0} # Save data def save_data(patients, last_sequence): with open("data.json", "w") as file: json.dump({"patients": patients, "last_sequence": last_sequence}, file) # Generate patient ID def generate_patient_id(phone, last_sequence): today = datetime.now() current_year = today.year current_month = today.month if last_sequence["year"] != current_year or last_sequence["month"] != current_month: last_sequence["year"] = current_year last_sequence["month"] = current_month last_sequence["number"] = 1 else: last_sequence["number"] += 1 patient_id = f"{current_year}{current_month:02d}{last_sequence['number']:05d}" return patient_id # Patient Registration Tab def registration_interface(name, father_name, age, gender, phone, address): patients, last_sequence = load_data() patient_id = generate_patient_id(phone, last_sequence) patients[patient_id] = { "name": name, "father_name": father_name, "age": age, "gender": gender, # Updated field for gender "phone": phone, "address": address, "tests": [], "total_cost": 0 } save_data(patients, last_sequence) return f"Patient Registered. Patient ID: {patient_id}" # Tests Selection Tab def test_interface(categories): available_tests = get_tests_by_category(categories) return gr.update(choices=available_tests) def confirm_tests_interface(patient_id, selected_tests): patients, last_sequence = load_data() response = select_tests(patient_id, selected_tests, patients) save_data(patients, last_sequence) return response # Billing Tab def billing_interface(patient_id): patients, _ = load_data() if patient_id in patients: billing_info = fetch_billing(patient_id, patients) return billing_info else: return "Invalid Patient ID. Please check the ID." # Custom CSS styling custom_css = """ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap'); /* General Page Style */ body { font-family: 'Poppins', Arial, sans-serif; background: #f0f7f9; color: #333; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; } /* Main Container */ .gradio-container { max-width: 900px; width: 100%; margin: 0 auto; padding: 30px; background-color: #ffffff; border-radius: 8px; border: 1px solid #d0e7f1; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08); } /* Header Styling */ #header { color: #005b8c; text-align: center; font-weight: 600; font-size: 1.8em; margin-bottom: 20px; } /* Headings */ h1, h2, h3 { color: #005b8c; font-weight: 500; margin: 10px 0; } /* Form Field Styles */ input, select, textarea { width: 100%; border: 1px solid #aac9d4; border-radius: 6px; padding: 8px 10px; font-size: 14px; color: #333; background: #f7fcff; margin-bottom: 15px; transition: border-color 0.3s ease; } input:focus, select:focus, textarea:focus { border-color: #41a0c4; background: #eaf6f9; outline: none; } /* Button Styles */ button { padding: 10px 20px; font-size: 0.9em; font-weight: 500; border: none; border-radius: 6px; color: #ffffff; background-color: #007ba7; cursor: pointer; transition: background-color 0.2s ease; } button:hover { background-color: #005f80; } /* Container for All Checkbox Groups */ .checkbox-container { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; } /* Individual Checkbox Group */ .checkbox-group { display: inline-flex; align-items: center; padding: 8px 10px; border: 1px solid #d0e7f1; border-radius: 6px; background-color: #f7fcff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); min-width: 150px; justify-content: center; } /* Styling for Checkbox */ .checkbox-group input[type="checkbox"] { margin-right: 8px; transform: scale(1.2); /* Larger checkbox */ accent-color: #007ba7; } /* Styling for Checkbox Label */ .checkbox-group label { font-size: 0.95em; color: #333333; white-space: nowrap; display: inline-block; } /* Radio Button Group */ .gr-radio-group label { display: inline-flex; align-items: center; padding: 6px 12px; border: 1px solid #b0d3dc; border-radius: 6px; color: #333; background: #f7fcff; margin-right: 8px; transition: background-color 0.2s, color 0.2s, border-color 0.2s; cursor: pointer; } .gr-radio-group label:hover { background-color: #eaf6f9; border-color: #41a0c4; } .gr-radio-group input[type="radio"] { appearance: none; width: 14px; height: 14px; margin-right: 6px; border: 2px solid #007ba7; border-radius: 50%; transition: background-color 0.2s, border-color 0.2s; } .gr-radio-group input[type="radio"]:checked { background-color: #007ba7; border-color: #007ba7; } /* Tabs */ .nav-tabs { display: flex; justify-content: space-around; background-color: #ffffff; padding: 10px; border-bottom: 1px solid #e0f2f4; border-radius: 6px; margin-bottom: 15px; } .nav-tabs .nav-item { font-size: 0.9em; font-weight: 500; color: #333; padding: 8px 15px; border-radius: 6px; cursor: pointer; transition: color 0.2s, background-color 0.2s; } .nav-tabs .nav-item:hover, .nav-tabs .nav-item.active { color: #007ba7; background-color: #eaf6f9; } /* Output Text Styling */ #registration_output, #test_output, #billing_output { color: #333; background-color: #f0fbff; padding: 12px; border-radius: 6px; font-weight: 500; text-align: left; border: 1px solid #d0e7f1; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); transition: background-color 0.2s ease, border-color 0.2s ease; } #registration_output:hover, #test_output:hover, #billing_output:hover { background-color: #e8f7fb; border-color: #41a0c4; } """ # Gradio Interface with gr.Blocks(css=custom_css) as app: gr.Markdown("

๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ”ฌไธ‚ๅ‚ใ„’ๅ„าœๅฐบใ„ฉใ„’ๅ„ๅ‚ ใ„ฅไธจ็ˆชไธ‚๐Ÿ”ฌ

", elem_id="header") with gr.Tab("Patient Registration"): gr.Markdown("

Register a New Patient

") with gr.Row(): name = gr.Textbox(label="Patient Name", placeholder="Enter patient's full name", elem_id="name_field") father_name = gr.Textbox(label="Father/Husband's Name", placeholder="Enter father/husband's full name", elem_id="father_name_field") with gr.Row(): age = gr.Number(label="Age", value=None, minimum=0, maximum=120, elem_id="age_field") gender = gr.Radio( choices=["Male", "Female", "Other"], label="Gender", elem_id="gender_field" ) with gr.Row(): phone = gr.Textbox(label="Phone Number", placeholder="Enter a valid 10-digit phone number", elem_id="phone_field") address = gr.Textbox(label="Address", placeholder="Enter full address", lines=2, elem_id="address_field") register_button = gr.Button("Register Patient", elem_id="register_button") registration_output = gr.Markdown(label="Registration Output", elem_id="registration_output") register_button.click(registration_interface, [name, father_name, age, gender, phone, address], registration_output) with gr.Tab("Tests"): gr.Markdown("

Select Tests for the Patient

") patient_id_test = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID") categories = gr.CheckboxGroup( ["Haematology", "Clinical Pathology", "Biochemistry", "Microbiology", "Specific Diseases", "Serology", "Radiology", "Other Diagnostic Tests"], label="Select Test Categories" ) available_tests = gr.CheckboxGroup(label="Available Tests") confirm_button = gr.Button("Confirm Selected Tests") # Use Markdown for Test Selection Output to allow for auto-expanding content test_output = gr.Markdown(label="Test Selection Output", elem_id="test_output") categories.change(test_interface, inputs=categories, outputs=available_tests) confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output) with gr.Tab("Billing"): gr.Markdown("

Billing Information

") patient_id_bill = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID for Billing") fetch_button = gr.Button("Fetch Billing Details") # Use Markdown for Billing Output to allow for auto-expanding content billing_output = gr.Markdown(label="Billing Information", elem_id="billing_output") fetch_button.click(billing_interface, [patient_id_bill], billing_output) app.launch()