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;700&display=swap'); /* Reset and Base Styles */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Poppins', Arial, sans-serif; background: linear-gradient(135deg, #f3faff, #e0f4f9); color: #333; display: flex; justify-content: center; align-items: center; min-height: 100vh; } /* Main Container */ .gradio-container { max-width: 900px; width: 100%; margin: 30px auto; padding: 40px; background-color: #fff; border-radius: 12px; border: 1px solid #d0e7f1; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); transition: box-shadow 0.3s ease, transform 0.3s ease; } .gradio-container:hover { transform: scale(1.01); box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12); } /* Header */ #header { color: #005b8c; text-align: center; font-weight: 700; font-size: 2.4em; margin-bottom: 20px; letter-spacing: 0.5px; text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1); } /* Typography for Headings */ h1, h2, h3, h4, h5, h6 { color: #005b8c; font-weight: 600; } /* Form Field Styles */ input, select, textarea { width: 100%; border: 1px solid #aac9d4; border-radius: 8px; padding: 12px 14px; font-size: 15px; color: #333; background: #f7fcff; margin-bottom: 20px; transition: all 0.3s ease; box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05); } input:focus, select:focus, textarea:focus { border-color: #41a0c4; background: #eaf6f9; box-shadow: 0 4px 10px rgba(65, 160, 196, 0.15); outline: none; } /* Button Styles */ button { padding: 12px 24px; font-size: 1em; font-weight: 600; border: none; border-radius: 8px; color: #fff; background-color: #007ba7; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease; box-shadow: 0 4px 12px rgba(0, 123, 167, 0.2); } button:hover { background-color: #005f80; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 123, 167, 0.3); } button:active { transform: translateY(1px); } /* Toggle Switch */ .toggle-switch { position: relative; display: inline-block; width: 50px; height: 28px; } .toggle-switch input { opacity: 0; width: 0; height: 0; } .toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #c2d6dc; transition: 0.4s; border-radius: 34px; } .toggle-slider:before { position: absolute; content: ""; height: 22px; width: 22px; left: 3px; bottom: 3px; background-color: #fff; transition: 0.4s; border-radius: 50%; } input:checked + .toggle-slider { background-color: #007ba7; } input:checked + .toggle-slider:before { transform: translateX(22px); } /* Radio Button Group */ .gr-radio-group label { display: inline-flex; align-items: center; padding: 8px 16px; border: 1px solid #b0d3dc; border-radius: 8px; background: #f7fcff; margin-right: 10px; cursor: pointer; transition: background-color 0.3s, color 0.3s, border-color 0.3s; } .gr-radio-group label:hover { background-color: #eaf6f9; border-color: #41a0c4; color: #005b8c; } .gr-radio-group input[type="radio"] { appearance: none; width: 18px; height: 18px; margin-right: 8px; border: 2px solid #007ba7; border-radius: 50%; transition: background-color 0.3s, border-color 0.3s; } .gr-radio-group input[type="radio"]:checked { background-color: #007ba7; border-color: #007ba7; } /* Tabs */ .nav-tabs { display: flex; justify-content: space-around; background-color: #fff; padding: 12px; border-bottom: 2px solid #e0f2f4; border-radius: 8px; margin-bottom: 20px; } .nav-tabs .nav-item { font-size: 1.1em; font-weight: 500; color: #333; padding: 10px 20px; border: 2px solid transparent; border-radius: 6px; cursor: pointer; transition: color 0.3s, background-color 0.3s, border-color 0.3s; } .nav-tabs .nav-item:hover, .nav-tabs .nav-item.active { color: #007ba7; background-color: #eaf6f9; border-color: #007ba7; } /* Output Text Styling */ #registration_output, #test_output, #billing_output { color: #333; background-color: #f0fbff; padding: 15px; border-radius: 8px; font-weight: 600; text-align: left; border: 1px solid #d0e7f1; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05); transition: background-color 0.3s ease, border-color 0.3s ease; } #registration_output:hover, #test_output:hover, #billing_output:hover { background-color: #e8f7fb; border-color: #41a0c4; } /* Media Query for Mobile Responsiveness */ @media (max-width: 768px) { .gradio-container { padding: 20px; margin: 20px; } #header { font-size: 2em; } .nav-tabs .nav-item { font-size: 1em; padding: 8px 12px; } button { padding: 10px 20px; font-size: 0.9em; } } """ # Gradio Interface with gr.Blocks(css=custom_css) as app: gr.Markdown("