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": None, "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." # Gradio Interface with gr.Blocks() 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.CheckboxGroup( 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.Textbox(label="Registration Output", elem_id="registration_output", interactive=False) 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") test_output = gr.Textbox(label="Test Selection Output", elem_id="test_output", interactive=False) 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") billing_output = gr.Textbox(label="Billing Information", interactive=False, elem_id="billing_output") fetch_button.click(billing_interface, [patient_id_bill], billing_output) # Custom CSS styling app.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) !important; color: #ffffff !important; margin: 0 !important; padding: 0 !important; display: flex !important; justify-content: center !important; align-items: center !important; min-height: 100vh !important; } /* Header */ #header { color: #7fffd4 !important; /* Light Aqua for better contrast */ text-align: center !important; font-weight: 700 !important; font-size: 2.5em !important; margin-bottom: 25px !important; text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3) !important; letter-spacing: 1px !important; transition: color 0.3s ease !important; } #header:hover { color: #32cd32 !important; /* Lime Green on hover */ transform: scale(1.05) !important; } /* Container Style */ .gradio-container { max-width: 850px !important; margin: 30px auto !important; padding: 40px !important; background: rgba(0, 0, 50, 0.95) !important; border-radius: 15px !important; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5) !important; color: #e0f7fa !important; } /* Form Field Styles */ input, select, textarea { max-width: 700px !important; border: 1px solid #7fffd4 !important; border-radius: 8px !important; padding: 10px 12px !important; background: rgba(245, 245, 245, 0.95) !important; color: #2d2d2d !important; font-size: 15px !important; margin-bottom: 20px !important; transition: all 0.3s ease !important; box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.15) !important; } /* Text Area Styling */ textarea { width: 100% !important; height: 50px !important; /* Set initial height */ resize: none !important; /* Disable resizing */ padding: 10px !important; border-radius: 8px !important; border: 1px solid #7fffd4 !important; background: rgba(245, 245, 245, 0.95) !important; color: #2d2d2d !important; font-size: 15px !important; transition: all 0.3s ease !important; box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.15) !important; } /* Form Field Hover and Focus */ input:focus, textarea:focus, select:focus { border-color: #00ffcc !important; /* Light Cyan border on focus */ box-shadow: 0 0 10px rgba(0, 255, 204, 0.6) !important; transform: scale(1.02) !important; } /* Button Style */ .gr-button { color: #ffffff !important; background: linear-gradient(135deg, #1de9b6, #007aff) !important; border: none !important; border-radius: 12px !important; padding: 12px 30px !important; cursor: pointer !important; font-weight: 600 !important; font-size: 16px !important; transition: 0.3s ease !important; box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3) !important; } .gr-button:hover { background: linear-gradient(135deg, #005cbf, #00bfa5) !important; transform: scale(1.05) !important; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4) !important; } /* Success & Error Messages */ #registration_output, #test_output, #billing_output { padding: 10px !important; border-radius: 5px !important; font-weight: bold !important; text-align: center !important; } #registration_output { background-color: #e6f4ea !important; color: #1b5e20 !important; } #test_output { background-color: #e3f2fd !important; color: #0d47a1 !important; } #billing_output { background-color: #ffebee !important; color: #b71c1c !important; } /* Tab Container Styling */ .nav-tabs { display: flex !important; justify-content: space-around !important; background-color: #3a3a3a !important; border-bottom: 1px solid #fff !important; padding: 8px !important; } .nav-tabs .nav-item { font-size: 1.1em !important; color: #7fffd4 !important; /* Light Aqua for inactive tabs */ padding: 10px 18px !important; cursor: pointer !important; font-weight: 500 !important; border: 2px solid transparent !important; border-radius: 8px !important; transition: color 0.3s, border-color 0.3s !important; } .nav-tabs .nav-item:hover { color: #00ffcc !important; /* Bright cyan on hover */ } .nav-tabs .nav-item.active { color: #00FF00 !important; /* Bright Green for active tab */ border: 2px solid #00FF00 !important; font-weight: 700 !important; background-color: rgba(0, 255, 0, 0.1) !important; padding: 8px 16px !important; } /* Field Labels */ label { font-size: 1em !important; font-weight: 600 !important; color: #7fffd4 !important; /* Light Aqua for label text */ margin-bottom: 5px !important; } /* Checkbox Group Styling */ #gender_field { display: flex !important; flex-direction: row !important; gap: 15px !important; align-items: center !important; margin-top: -10px !important; /* Adjust as needed for alignment */ } /* Styling for Gender Checkboxes */ #gender_field input[type="checkbox"] { margin-right: 5px !important; } /* Row Styling for Field Alignment */ .gradio-container .gr-row { display: flex !important; gap: 20px !important; align-items: center !important; } /* Responsive Design for Mobile Devices */ @media (max-width: 768px) { .gradio-container { padding: 20px !important; } #header { font-size: 2em !important; } input, textarea, select, .gr-button { font-size: 1em !important; padding: 10px !important; } #gender_field { flex-direction: column !important; align-items: flex-start !important; } } """ app.launch()