Spaces:
Running
Running
neerajkalyank
commited on
Commit
β’
8d88ff2
1
Parent(s):
4cea6bb
Update app.py
Browse files
app.py
CHANGED
@@ -25,28 +25,21 @@ def generate_patient_id(phone, last_sequence):
|
|
25 |
current_year = today.year
|
26 |
current_month = today.month
|
27 |
|
28 |
-
# Check if year or month has changed
|
29 |
if last_sequence["year"] != current_year or last_sequence["month"] != current_month:
|
30 |
-
# Reset sequence for new year/month
|
31 |
last_sequence["year"] = current_year
|
32 |
last_sequence["month"] = current_month
|
33 |
last_sequence["number"] = 1
|
34 |
else:
|
35 |
-
# Increment sequence number
|
36 |
last_sequence["number"] += 1
|
37 |
|
38 |
-
# Format patient ID
|
39 |
patient_id = f"{current_year}{current_month:02d}{last_sequence['number']:05d}"
|
40 |
return patient_id
|
41 |
|
42 |
# Patient Registration Tab
|
43 |
def registration_interface(name, father_name, age, phone, address, pincode):
|
44 |
patients, last_sequence = load_data()
|
45 |
-
|
46 |
-
# Generate patient ID
|
47 |
patient_id = generate_patient_id(phone, last_sequence)
|
48 |
|
49 |
-
# Add patient details to data
|
50 |
patients[patient_id] = {
|
51 |
"name": name,
|
52 |
"father_name": father_name,
|
@@ -58,24 +51,23 @@ def registration_interface(name, father_name, age, phone, address, pincode):
|
|
58 |
"total_cost": 0
|
59 |
}
|
60 |
|
61 |
-
# Save data and updated sequence
|
62 |
save_data(patients, last_sequence)
|
63 |
return f"Patient Registered. Patient ID: {patient_id}"
|
64 |
|
65 |
# Tests Selection Tab
|
66 |
def test_interface(categories):
|
67 |
available_tests = get_tests_by_category(categories)
|
68 |
-
return gr.update(choices=available_tests)
|
69 |
|
70 |
def confirm_tests_interface(patient_id, selected_tests):
|
71 |
-
patients, last_sequence = load_data()
|
72 |
-
response = select_tests(patient_id, selected_tests, patients)
|
73 |
-
save_data(patients, last_sequence)
|
74 |
return response
|
75 |
|
76 |
# Billing Tab
|
77 |
def billing_interface(patient_id):
|
78 |
-
patients, _ = load_data()
|
79 |
if patient_id in patients:
|
80 |
billing_info = fetch_billing(patient_id, patients)
|
81 |
return billing_info
|
@@ -87,37 +79,40 @@ with gr.Blocks() as app:
|
|
87 |
gr.Markdown("<h1 style='text-align: center;'>π©π»βπ¬π
’π
π
£π
π
π
‘π
€π
£π
π
π
π
π
π
’π¬</h1>", elem_id="header")
|
88 |
|
89 |
with gr.Tab("Patient Registration"):
|
|
|
90 |
with gr.Row():
|
91 |
-
name = gr.Textbox(label="Patient Name", placeholder="Enter patient name", elem_id="name_field"
|
92 |
-
father_name = gr.Textbox(label="Father/Husband Name", placeholder="Enter father
|
93 |
with gr.Row():
|
94 |
-
age = gr.Number(label="Age", value=None, minimum=
|
95 |
-
phone = gr.
|
96 |
with gr.Row():
|
97 |
-
address = gr.Textbox(label="Address", placeholder="Enter address", lines=2)
|
98 |
-
pincode = gr.
|
99 |
-
register_button = gr.Button("Register Patient")
|
100 |
-
registration_output = gr.Textbox(label="Registration Output")
|
101 |
|
|
|
|
|
102 |
register_button.click(registration_interface, [name, father_name, age, phone, address, pincode], registration_output)
|
103 |
|
104 |
with gr.Tab("Tests"):
|
105 |
-
|
|
|
106 |
categories = gr.CheckboxGroup(
|
107 |
["Haematology", "Clinical Pathology", "Biochemistry", "Microbiology", "Specific Diseases", "Serology", "Radiology", "Other Diagnostic Tests"],
|
108 |
label="Select Test Categories"
|
109 |
)
|
110 |
available_tests = gr.CheckboxGroup(label="Available Tests")
|
111 |
-
confirm_button = gr.Button("Confirm Tests")
|
112 |
-
test_output = gr.Textbox(label="Test Selection Output")
|
113 |
|
114 |
-
categories.change(test_interface, inputs=categories, outputs=available_tests)
|
115 |
confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output)
|
116 |
|
117 |
with gr.Tab("Billing"):
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
121 |
fetch_button.click(billing_interface, [patient_id_bill], billing_output)
|
122 |
|
123 |
# Custom CSS styling
|
|
|
25 |
current_year = today.year
|
26 |
current_month = today.month
|
27 |
|
|
|
28 |
if last_sequence["year"] != current_year or last_sequence["month"] != current_month:
|
|
|
29 |
last_sequence["year"] = current_year
|
30 |
last_sequence["month"] = current_month
|
31 |
last_sequence["number"] = 1
|
32 |
else:
|
|
|
33 |
last_sequence["number"] += 1
|
34 |
|
|
|
35 |
patient_id = f"{current_year}{current_month:02d}{last_sequence['number']:05d}"
|
36 |
return patient_id
|
37 |
|
38 |
# Patient Registration Tab
|
39 |
def registration_interface(name, father_name, age, phone, address, pincode):
|
40 |
patients, last_sequence = load_data()
|
|
|
|
|
41 |
patient_id = generate_patient_id(phone, last_sequence)
|
42 |
|
|
|
43 |
patients[patient_id] = {
|
44 |
"name": name,
|
45 |
"father_name": father_name,
|
|
|
51 |
"total_cost": 0
|
52 |
}
|
53 |
|
|
|
54 |
save_data(patients, last_sequence)
|
55 |
return f"Patient Registered. Patient ID: {patient_id}"
|
56 |
|
57 |
# Tests Selection Tab
|
58 |
def test_interface(categories):
|
59 |
available_tests = get_tests_by_category(categories)
|
60 |
+
return gr.update(choices=available_tests)
|
61 |
|
62 |
def confirm_tests_interface(patient_id, selected_tests):
|
63 |
+
patients, last_sequence = load_data()
|
64 |
+
response = select_tests(patient_id, selected_tests, patients)
|
65 |
+
save_data(patients, last_sequence)
|
66 |
return response
|
67 |
|
68 |
# Billing Tab
|
69 |
def billing_interface(patient_id):
|
70 |
+
patients, _ = load_data()
|
71 |
if patient_id in patients:
|
72 |
billing_info = fetch_billing(patient_id, patients)
|
73 |
return billing_info
|
|
|
79 |
gr.Markdown("<h1 style='text-align: center;'>π©π»βπ¬π
’π
π
£π
π
π
‘π
€π
£π
π
π
π
π
π
’π¬</h1>", elem_id="header")
|
80 |
|
81 |
with gr.Tab("Patient Registration"):
|
82 |
+
gr.Markdown("<h2>Register a New Patient</h2>")
|
83 |
with gr.Row():
|
84 |
+
name = gr.Textbox(label="Patient Name", placeholder="Enter patient's full name", elem_id="name_field")
|
85 |
+
father_name = gr.Textbox(label="Father/Husband's Name", placeholder="Enter father/husband's full name", elem_id="father_name_field")
|
86 |
with gr.Row():
|
87 |
+
age = gr.Number(label="Age", value=None, minimum=1, maximum=120, elem_id="age_field")
|
88 |
+
phone = gr.Textbox(label="Phone Number", placeholder="Enter a valid 10-digit phone number", elem_id="phone_field")
|
89 |
with gr.Row():
|
90 |
+
address = gr.Textbox(label="Address", placeholder="Enter full address", lines=2, elem_id="address_field")
|
91 |
+
pincode = gr.Textbox(label="Pincode", placeholder="Enter area pincode", elem_id="pincode_field")
|
|
|
|
|
92 |
|
93 |
+
register_button = gr.Button("Register Patient", elem_id="register_button")
|
94 |
+
registration_output = gr.Textbox(label="Registration Output", elem_id="registration_output", interactive=False)
|
95 |
register_button.click(registration_interface, [name, father_name, age, phone, address, pincode], registration_output)
|
96 |
|
97 |
with gr.Tab("Tests"):
|
98 |
+
gr.Markdown("<h2>Select Tests for the Patient</h2>")
|
99 |
+
patient_id_test = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID")
|
100 |
categories = gr.CheckboxGroup(
|
101 |
["Haematology", "Clinical Pathology", "Biochemistry", "Microbiology", "Specific Diseases", "Serology", "Radiology", "Other Diagnostic Tests"],
|
102 |
label="Select Test Categories"
|
103 |
)
|
104 |
available_tests = gr.CheckboxGroup(label="Available Tests")
|
105 |
+
confirm_button = gr.Button("Confirm Selected Tests")
|
106 |
+
test_output = gr.Textbox(label="Test Selection Output", elem_id="test_output", interactive=False)
|
107 |
|
108 |
+
categories.change(test_interface, inputs=categories, outputs=available_tests)
|
109 |
confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output)
|
110 |
|
111 |
with gr.Tab("Billing"):
|
112 |
+
gr.Markdown("<h2>Billing Information</h2>")
|
113 |
+
patient_id_bill = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID for Billing")
|
114 |
+
fetch_button = gr.Button("Fetch Billing Details")
|
115 |
+
billing_output = gr.Textbox(label="Billing Information", interactive=False, elem_id="billing_output")
|
116 |
fetch_button.click(billing_interface, [patient_id_bill], billing_output)
|
117 |
|
118 |
# Custom CSS styling
|