Spaces:
Running
Running
neerajkalyank
commited on
Commit
•
6c55cc0
1
Parent(s):
2e62ddb
Update app.py
Browse files
app.py
CHANGED
@@ -25,21 +25,28 @@ def generate_patient_id(phone, last_sequence):
|
|
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,9 +58,30 @@ def registration_interface(name, father_name, age, phone, address, pincode):
|
|
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:
|
59 |
gr.Markdown("<h1 style='text-align: center;'>Sathkrutha LIMS</h1>", elem_id="header")
|
@@ -70,21 +98,43 @@ 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 |
-
hidden_patient_id = gr.Textbox(visible=False) # Hidden field to store the patient ID
|
74 |
|
75 |
register_button.click(registration_interface, [name, father_name, age, phone, address, pincode], [registration_output, hidden_patient_id])
|
76 |
|
77 |
# Custom HTML for Copy ID Button
|
78 |
-
|
79 |
<button onclick="copyPatientID()" style="background-color: #3b74f2; color: white; padding: 10px; border-radius: 5px; border: none; cursor: pointer;">Copy Patient ID</button>
|
80 |
<script>
|
81 |
function copyPatientID() {
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
}
|
85 |
</script>
|
86 |
-
"""
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
# Custom CSS styling
|
90 |
app.css = """
|
|
|
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 |
"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}", 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:
|
87 |
gr.Markdown("<h1 style='text-align: center;'>Sathkrutha LIMS</h1>", elem_id="header")
|
|
|
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 |
+
hidden_patient_id = gr.Textbox(visible=False, elem_id="hidden_patient_id") # Hidden field to store the patient ID
|
102 |
|
103 |
register_button.click(registration_interface, [name, father_name, age, phone, address, pincode], [registration_output, hidden_patient_id])
|
104 |
|
105 |
# Custom HTML for Copy ID Button
|
106 |
+
gr.HTML("""
|
107 |
<button onclick="copyPatientID()" style="background-color: #3b74f2; color: white; padding: 10px; border-radius: 5px; border: none; cursor: pointer;">Copy Patient ID</button>
|
108 |
<script>
|
109 |
function copyPatientID() {
|
110 |
+
const patientID = document.querySelector('#hidden_patient_id input').value;
|
111 |
+
navigator.clipboard.writeText(patientID).then(() => {
|
112 |
+
alert('Patient ID copied to clipboard');
|
113 |
+
}).catch(err => {
|
114 |
+
alert('Failed to copy Patient ID');
|
115 |
+
});
|
116 |
}
|
117 |
</script>
|
118 |
+
""")
|
119 |
+
|
120 |
+
with gr.Tab("Tests"):
|
121 |
+
patient_id_test = gr.Textbox(label="Patient ID")
|
122 |
+
categories = gr.CheckboxGroup(
|
123 |
+
["Haematology", "Clinical Pathology", "Biochemistry", "Microbiology", "Specific Diseases", "Serology", "Radiology", "Other Diagnostic Tests"],
|
124 |
+
label="Select Test Categories"
|
125 |
+
)
|
126 |
+
available_tests = gr.CheckboxGroup(label="Available Tests")
|
127 |
+
confirm_button = gr.Button("Confirm Tests")
|
128 |
+
test_output = gr.Textbox(label="Test Selection Output")
|
129 |
+
|
130 |
+
categories.change(test_interface, inputs=categories, outputs=available_tests) # Update available tests based on selected categories
|
131 |
+
confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output)
|
132 |
+
|
133 |
+
with gr.Tab("Billing"):
|
134 |
+
patient_id_bill = gr.Textbox(label="Patient ID")
|
135 |
+
fetch_button = gr.Button("Fetch Billing")
|
136 |
+
billing_output = gr.Textbox(label="Billing Information")
|
137 |
+
fetch_button.click(billing_interface, [patient_id_bill], billing_output)
|
138 |
|
139 |
# Custom CSS styling
|
140 |
app.css = """
|