File size: 3,893 Bytes
2295b8f
 
 
425deb7
2295b8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0306539
425deb7
0306539
425deb7
 
2295b8f
425deb7
2295b8f
 
 
 
 
 
 
 
 
 
 
 
 
 
b6c1aa5
 
 
 
 
 
 
 
 
2295b8f
 
b6c1aa5
2295b8f
 
 
 
0306539
 
 
 
425deb7
2295b8f
 
425deb7
0306539
425deb7
2295b8f
 
 
 
 
 
 
b6c1aa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2295b8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr
import json
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:
            return json.load(file)
    except FileNotFoundError:
        return {}

# Save data
def save_data(data):
    with open("data.json", "w") as file:
        json.dump(data, file)

# Patient Registration Tab
def registration_interface(name, father_name, age, phone, address, pincode):
    patient_id = register_patient(name, father_name, age, phone, address, pincode)
    data = load_data()
    data[patient_id] = {"name": name, "father_name": father_name, "age": age, "phone": phone, "address": address, "pincode": pincode, "tests": [], "total_cost": 0}
    save_data(data)
    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)  # Update dropdown with available tests

def confirm_tests_interface(patient_id, selected_tests):
    data = load_data()
    response = select_tests(patient_id, selected_tests, data)
    save_data(data)
    return response

# Billing Tab
def billing_interface(patient_id):
    data = load_data()
    billing_info = fetch_billing(patient_id, data)
    return billing_info

# Gradio Interface
with gr.Blocks() as app:
    gr.Markdown("# Sathkrutha LIMS - Patient Management and Billing App")

    with gr.Tab("Patient Registration"):
        with gr.Row():
            name = gr.Textbox(label="Patient Name", placeholder="Enter patient name", max_chars=50, elem_id="name_field", lines=1)
            father_name = gr.Textbox(label="Father/Husband Name", placeholder="Enter father or husband name", max_chars=50, elem_id="father_name_field", lines=1)
        with gr.Row():
            age = gr.Number(label="Age", value=None, minimum=0, maximum=99, elem_id="age_field", precision=0)
            phone = gr.Number(label="Phone Number", value=None, elem_id="phone_field", precision=0)
        with gr.Row():
            address = gr.Textbox(label="Address", placeholder="Enter address", lines=2)
            pincode = gr.Number(label="Pincode", value=None, elem_id="pincode_field", precision=0)
        register_button = gr.Button("Register Patient")
        registration_output = gr.Textbox(label="Registration Output")

        register_button.click(registration_interface, [name, father_name, age, phone, address, pincode], registration_output)

    with gr.Tab("Tests"):
        patient_id_test = gr.Textbox(label="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 Tests")
        test_output = gr.Textbox(label="Test Selection Output")

        categories.change(test_interface, inputs=categories, outputs=available_tests)  # Update available tests based on selected categories
        confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output)

    with gr.Tab("Billing"):
        patient_id_bill = gr.Textbox(label="Patient ID")
        fetch_button = gr.Button("Fetch Billing")
        billing_output = gr.Textbox(label="Billing Information")
        fetch_button.click(billing_interface, [patient_id_bill], billing_output)

# Custom CSS to adjust field sizes
app.css = """
#name_field, #father_name_field {
    max-width: 200px;
}

#age_field {
    max-width: 80px;
}

#phone_field {
    max-width: 150px;
}

#pincode_field {
    max-width: 100px;
}
"""

app.launch()