Spaces:
Sleeping
Sleeping
File size: 8,675 Bytes
2295b8f d19864a 2295b8f 425deb7 2295b8f 2da3bf0 1a70d1e 2da3bf0 2295b8f 2da3bf0 2f8aad9 2da3bf0 2f8aad9 2da3bf0 1a70d1e 2295b8f 0306539 425deb7 0306539 425deb7 f5394cc 2295b8f 1a70d1e 2295b8f 977854e 2295b8f ba65c13 2295b8f b6c1aa5 ecac41a b6c1aa5 f9eb1c7 b6c1aa5 f9eb1c7 6afa05d 2295b8f b6c1aa5 2295b8f 0306539 425deb7 2295b8f 425deb7 0306539 425deb7 2295b8f 7e940ad 93eb34b 1a70d1e cd00d82 4bb6dc7 cd00d82 1a70d1e cd00d82 b6c1aa5 cd00d82 b6c1aa5 93eb34b eb7a558 93eb34b eb7a558 93eb34b eb7a558 93eb34b eb7a558 b6c1aa5 cd00d82 1a70d1e cd00d82 1a70d1e cd00d82 1a70d1e eb7a558 1a70d1e cd00d82 1a70d1e cd00d82 1a70d1e cd00d82 1a70d1e eb7a558 cd00d82 1a70d1e cd00d82 eb7a558 cd00d82 1a70d1e ba65c13 cd00d82 ba65c13 cd00d82 ba65c13 1a70d1e cd00d82 ba65c13 cd00d82 1a70d1e cd00d82 1a70d1e cd00d82 4bbf5a1 cd00d82 85bc4be 7e940ad c9ee207 |
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
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
# Check if year or month has changed
if last_sequence["year"] != current_year or last_sequence["month"] != current_month:
# Reset sequence for new year/month
last_sequence["year"] = current_year
last_sequence["month"] = current_month
last_sequence["number"] = 1
else:
# Increment sequence number
last_sequence["number"] += 1
# Format patient ID
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, phone, address, pincode):
patients, last_sequence = load_data()
# Generate patient ID
patient_id = generate_patient_id(phone, last_sequence)
# Add patient details to data
patients[patient_id] = {
"name": name,
"father_name": father_name,
"age": age,
"phone": phone,
"address": address,
"pincode": pincode,
"tests": [],
"total_cost": 0
}
# Save data and updated sequence
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) # Update dropdown with available tests
def confirm_tests_interface(patient_id, selected_tests):
patients, last_sequence = load_data() # Load both patients and last_sequence
response = select_tests(patient_id, selected_tests, patients) # Update patients directly
save_data(patients, last_sequence) # Save both patients and last_sequence
return response
# Billing Tab
def billing_interface(patient_id):
patients, _ = load_data() # Load patients and ignore last_sequence
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("<h1 style='text-align: center;'>\t\t\tSathkrutha LIMS</h1>", elem_id="header")
with gr.Tab("Patient Registration"):
with gr.Row():
name = gr.Textbox(label="Patient Name", placeholder="Enter patient name", elem_id="name_field", lines=1)
father_name = gr.Textbox(label="Father/Husband Name", placeholder="Enter father or husband name", 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")
phone = gr.Number(label="Phone Number", value=None, elem_id="phone_field")
with gr.Row():
address = gr.Textbox(label="Address", placeholder="Enter address", lines=2)
pincode = gr.Number(label="Pincode", value=None, elem_id="pincode_field")
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)
app.css = """
/* Global styling */
body {
font-family: 'Arial', sans-serif;
background: url('./background.png') no-repeat center center fixed;
background-size: cover;
color: #f0f0f0;
}
/* Header Styling */
#header h1 {
color: #ff9800;
font-size: 2.5em;
font-weight: bold;
text-align: center;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
padding-bottom: 20px;
}
/* Container Styling */
.gradio-container {
max-width: 850px;
margin: 20px auto;
padding: 30px;
background: rgba(34, 34, 34, 0.85);
border-radius: 12px;
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.5);
color: #f0f0f0;
}
/* Tab Styling with Rounded Rectangle */
.gradio-container .gr-tab {
color: #00ff40;
padding: 10px 20px;
font-weight: bold;
cursor: pointer;
position: relative;
transition: color 0.3s ease, background-color 0.3s ease;
border-radius: 20px; /* Rounded corners for tabs */
}
.gradio-container .gr-tab:hover {
color: #ffffff;
background-color: #0000ff; /* Background color for hover effect */
}
.gradio-container .gr-tab-active {
color: #ffffff;
background-color: #ff9800;
border-radius: 12px; /* Rounded rectangle for active tab */
}
.gradio-container .gr-tab + .gr-tab {
margin-left: 10px; /* Adds space between tabs */
}
/* Input Field Styling */
#name_field, #father_name_field, #age_field, #phone_field, #pincode_field, textarea {
width: 100%;
background-color: #2e2e2e;
color: #f0f0f0;
border: 1px solid #555;
border-radius: 8px;
padding: 12px;
font-size: 1em;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
margin-top: 10px;
}
#name_field:focus, #father_name_field:focus, #age_field:focus, #phone_field:focus, #pincode_field:focus, textarea:focus {
border-color: #ff9800;
box-shadow: 0 0 10px rgba(255, 152, 0, 0.4);
outline: none;
}
/* Button Styling */
.gr-button {
background-color: #0000ff;
color: #00ff00;
border: none;
border-radius: 8px;
padding: 12px 25px;
cursor: pointer;
font-size: 1em;
font-weight: bold;
transition: background-color 0.3s ease, transform 0.2s ease;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
margin-top: 15px;
}
.gr-button:hover {
background-color: #00ff00;
transform: translateY(-2px);
}
.gr-button:active {
background-color: #00ff00;
transform: translateY(0px);
}
/* Advanced styling for Test Categories and Available Tests checkboxes */
.gr-checkbox-group label {
display: inline-flex;
align-items: center;
padding: 10px 15px;
margin: 5px;
font-size: 0.9em;
font-weight: bold;
color: #f0f0f0;
background-color: #333;
border: 1px solid #555;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
}
.gr-checkbox-group label:hover {
background-color: #444;
border-color: #ff9800;
color: #ff9800;
}
.gr-checkbox-group input[type="checkbox"]:checked + label {
background-color: #ff9800;
border-color: #ff9800;
color: #ffffff;
}
.gr-checkbox-group input[type="checkbox"] {
display: none;
}
/* Billing Output Styling */
#billing_output {
background-color: rgba(176, 201, 30, 0.1);
padding: 15px;
border-radius: 8px;
color: #272dd9;
border: 1px solid #b0c91e;
font-size: 1em;
margin-top: 10px;
}
/* Responsive Design */
@media (max-width: 768px) {
#header h1 {
font-size: 2em;
}
.gradio-container {
padding: 20px;
}
.gr-button {
padding: 10px 20px;
font-size: 0.9em;
}
}
"""
app.launch()
|