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, "phone": phone, "address": address, "tests": [], "total_cost": 0 } save_data(patients, last_sequence) return f"Patient Registered. Patient ID: {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;600;700&display=swap'); /* General Page Style */ body { font-family: 'Poppins', Arial, sans-serif; background: linear-gradient(135deg, #4a90e2, #003c7c); color: #ffffff; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; } /* Header Styling */ #header { color: #7fffd4; text-align: center; font-weight: 700; font-size: 2.5em; margin-bottom: 25px; text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3); letter-spacing: 1px; transition: color 0.3s ease; } #header:hover { color: #32cd32; transform: scale(1.05); } /* Container Style */ .gradio-container { max-width: 850px; margin: 30px auto; padding: 40px; background: rgba(0, 0, 50, 0.95); border-radius: 15px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5); color: #e0f7fa; } /* Form Field Styles */ input, select, textarea { max-width: 700px; border: 1px solid #7fffd4; border-radius: 8px; padding: 10px 12px; background: rgba(245, 245, 245, 0.95); color: #2d2d2d; font-size: 15px; margin-bottom: 20px; transition: all 0.3s ease; box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.15); } /* Button Style */ .gr-button { color: #ffffff; background: linear-gradient(135deg, #1de9b6, #007aff); border: none; border-radius: 12px; padding: 12px 30px; cursor: pointer; font-weight: 600; font-size: 16px; transition: 0.3s ease; box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3); } .gr-button:hover { background: linear-gradient(135deg, #005cbf, #00bfa5); transform: scale(1.05); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4); } /* Tab Styling */ .nav-tabs { display: flex; justify-content: space-around; background-color: #001848; border-bottom: 1px solid #ffffff; padding: 12px; gap: 20px; } .nav-tabs .nav-item { font-size: 1.2em; color: #7fffd4; padding: 10px 18px; cursor: pointer; font-weight: 500; border: 2px solid transparent; border-radius: 8px; transition: color 0.3s, border-color 0.3s; } .nav-tabs .nav-item:hover { color: #00ffcc; background-color: rgba(0, 255, 204, 0.1); } .nav-tabs .nav-item.active { color: #ff8c00; border-bottom: 3px solid #ff8c00; font-weight: 700; background-color: rgba(255, 140, 0, 0.1); padding: 8px 16px; } /* Label Styling */ label { font-size: 1em; font-weight: 600; color: #7fffd4; margin-bottom: 5px; } /* Output Text Styling */ #test_output, #billing_output { color: #ffffff !important; background-color: rgba(0, 0, 50, 0.8) !important; padding: 10px; border-radius: 5px; font-weight: bold; text-align: left; } /* Responsive Design for Mobile Devices */ @media (max-width: 768px) { .gradio-container { padding: 20px; } #header { font-size: 2em; } input, textarea, select, .gr-button { font-size: 1em; padding: 10px; } } """ # Gradio Interface with gr.Blocks(css=custom_css) as app: gr.Markdown("