Spaces:
Sleeping
Sleeping
neerajkalyank
commited on
Commit
•
b8d540d
1
Parent(s):
7af2ecd
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,29 +51,8 @@ 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) # Update dropdown with available tests
|
69 |
-
|
70 |
-
def confirm_tests_interface(patient_id, selected_tests):
|
71 |
-
patients, last_sequence = load_data() # Load both patients and last_sequence
|
72 |
-
response = select_tests(patient_id, selected_tests, patients) # Update patients directly
|
73 |
-
save_data(patients, last_sequence) # Save both patients and last_sequence
|
74 |
-
return response
|
75 |
-
|
76 |
-
# Billing Tab
|
77 |
-
def billing_interface(patient_id):
|
78 |
-
patients, _ = load_data() # Load patients and ignore last_sequence
|
79 |
-
if patient_id in patients:
|
80 |
-
billing_info = fetch_billing(patient_id, patients)
|
81 |
-
return billing_info
|
82 |
-
else:
|
83 |
-
return "Invalid Patient ID. Please check the ID."
|
84 |
|
85 |
# Gradio Interface
|
86 |
with gr.Blocks() as app:
|
@@ -98,27 +70,13 @@ with gr.Blocks() as app:
|
|
98 |
pincode = gr.Number(label="Pincode", value=None, elem_id="pincode_field")
|
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 |
-
|
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) # Update available tests based on selected categories
|
115 |
-
confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output)
|
116 |
-
|
117 |
-
with gr.Tab("Billing"):
|
118 |
-
patient_id_bill = gr.Textbox(label="Patient ID")
|
119 |
-
fetch_button = gr.Button("Fetch Billing")
|
120 |
-
billing_output = gr.Textbox(label="Billing Information")
|
121 |
-
fetch_button.click(billing_interface, [patient_id_bill], billing_output)
|
122 |
|
123 |
# Custom CSS styling
|
124 |
app.css = """
|
|
|
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}", patient_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# Gradio Interface
|
58 |
with gr.Blocks() as app:
|
|
|
70 |
pincode = gr.Number(label="Pincode", value=None, elem_id="pincode_field")
|
71 |
register_button = gr.Button("Register Patient")
|
72 |
registration_output = gr.Textbox(label="Registration Output")
|
73 |
+
copy_button = gr.Button("Copy Patient ID")
|
74 |
+
hidden_patient_id = gr.Textbox(visible=False) # Hidden field to store the patient ID
|
75 |
|
76 |
+
register_button.click(registration_interface, [name, father_name, age, phone, address, pincode], [registration_output, hidden_patient_id])
|
77 |
+
|
78 |
+
# Add JavaScript to copy the patient ID
|
79 |
+
copy_button.click(None, [], None, _js="(x) => navigator.clipboard.writeText(x)", inputs=[hidden_patient_id])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Custom CSS styling
|
82 |
app.css = """
|