Spaces:
Sleeping
Sleeping
File size: 10,500 Bytes
2295b8f d19864a bdde5b9 2295b8f 2da3bf0 424b0ea 2da3bf0 1a70d1e 2da3bf0 2295b8f 6bde547 2da3bf0 2f8aad9 e55bd6f 2f8aad9 2da3bf0 1a70d1e e55bd6f 977854e fe8c4f6 bdde5b9 8d88ff2 fe8c4f6 8d88ff2 bdde5b9 fe8c4f6 8d88ff2 fe8c4f6 bdde5b9 fe8c4f6 9ccbc67 a096730 a9010bc 97272d5 1a70d1e a9010bc 2a98323 27514ec 21badeb 1a70d1e 7af2ecd afde41b 2a98323 afde41b 2a98323 e55bd6f afde41b 2a98323 e55bd6f 21badeb 9ccbc67 2a98323 21badeb 2a98323 afde41b 2a98323 507ce13 2a98323 b6c1aa5 b7d9de6 2a98323 b7d9de6 afde41b 2a98323 afde41b 2a98323 abbb0da afde41b 2a98323 507ce13 afde41b 507ce13 27514ec afde41b 2a98323 abbb0da 2a98323 920c9eb 507ce13 2a98323 afde41b 2a98323 afde41b 2a98323 afde41b abbb0da e55bd6f c619372 e55bd6f 507ce13 c619372 507ce13 c619372 e55bd6f 507ce13 c619372 e55bd6f c619372 507ce13 e55bd6f 507ce13 c619372 e55bd6f c619372 e55bd6f 507ce13 c619372 e55bd6f c619372 e55bd6f 507ce13 e55bd6f 507ce13 e55bd6f 507ce13 e55bd6f 27514ec e55bd6f 21badeb 97272d5 21badeb 2a98323 507ce13 756506f 97272d5 2a98323 1a70d1e 97272d5 2a98323 97272d5 95f776f 2a98323 cd00d82 27514ec 0697b43 2a98323 507ce13 1ad4f59 2a98323 507ce13 15e7bff 2a98323 1ad4f59 920c9eb a096730 abbb0da a096730 abbb0da a096730 abbb0da a096730 abbb0da a096730 e55bd6f a096730 eabbeae |
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
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": 0, "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
if last_sequence["year"] != current_year or last_sequence["month"] != current_month:
last_sequence["year"] = current_year
last_sequence["month"] = current_month
last_sequence["number"] = 1
else:
last_sequence["number"] += 1
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, gender, phone, address):
patients, last_sequence = load_data()
patient_id = generate_patient_id(phone, last_sequence)
patients[patient_id] = {
"name": name,
"father_name": father_name,
"age": age,
"gender": gender, # Updated field for gender
"phone": phone,
"address": address,
"tests": [],
"total_cost": 0
}
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)
def confirm_tests_interface(patient_id, selected_tests):
patients, last_sequence = load_data()
response = select_tests(patient_id, selected_tests, patients)
save_data(patients, last_sequence)
return response
# Billing Tab
def billing_interface(patient_id):
patients, _ = load_data()
if patient_id in patients:
billing_info = fetch_billing(patient_id, patients)
return billing_info
else:
return "Invalid Patient ID. Please check the ID."
# Custom CSS styling
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');
/* General Page Style */
body {
font-family: 'Poppins', Arial, sans-serif;
background: linear-gradient(135deg, #f0f7f4, #e8f0fe); /* Calm medical background */
color: #333333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
/* Main Container */
.gradio-container {
max-width: 900px;
margin: 30px auto;
padding: 40px;
background: #ffffff;
border: 1px solid #d1e2e8;
border-radius: 12px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
color: #333333;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.gradio-container:hover {
transform: scale(1.01);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.15);
}
/* Header Styling */
#header {
color: #00695c; /* Deep teal for medical tone */
text-align: center;
font-weight: 700;
font-size: 2.8em;
margin-bottom: 25px;
text-shadow: 1px 1px 6px rgba(0, 0, 0, 0.2);
letter-spacing: 1px;
transition: color 0.3s ease, transform 0.3s ease;
}
#header:hover {
color: #004d40;
transform: scale(1.05);
}
/* Heading Colors */
h1 {
color: #00695c; /* Dark teal for main headings */
text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.15);
}
h2, h3, h4, h5, h6 {
color: #00796b; /* Softer blue-green for subheadings */
text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1);
}
/* Section Title Styling */
.section-title {
font-size: 1.5em;
color: #00796b;
margin-bottom: 20px;
border-bottom: 2px solid #80cbc4;
padding-bottom: 8px;
}
/* Form Field Styles */
input, select, textarea {
width: 100%;
border: 1px solid #b0bec5;
border-radius: 8px;
padding: 12px 14px;
background: #fafafa;
color: #333333;
font-size: 16px;
margin-bottom: 20px;
transition: all 0.3s ease;
box-shadow: inset 0px 1px 3px rgba(0, 0, 0, 0.05);
}
input:focus, select:focus, textarea:focus {
border-color: #26a69a;
background: #f0f7f4;
box-shadow: 0px 3px 6px rgba(38, 166, 154, 0.15);
}
/* Button Styles */
button {
font-size: 1em;
font-weight: 600;
padding: 12px 24px;
border-radius: 8px;
border: none;
background-color: #00796b;
color: #ffffff;
cursor: pointer;
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
transition: background-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}
button:hover {
background-color: #004d40;
box-shadow: 0px 6px 14px rgba(0, 0, 0, 0.15);
transform: translateY(-2px);
}
/* Radio Button Group Styling */
.gr-radio-group label {
display: flex;
align-items: center;
justify-content: center;
padding: 10px 20px;
border: 1px solid #00838f;
border-radius: 8px;
transition: all 0.3s ease;
cursor: pointer;
color: #004d40;
background: #e0f7fa;
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.1);
margin-right: 10px;
}
.gr-radio-group label:hover {
background: #b2ebf2;
color: #004d40;
}
/* Radio Button Styling */
.gr-radio-group input[type="radio"] {
appearance: none;
width: 18px;
height: 18px;
border: 2px solid #004d40;
border-radius: 50%;
margin-right: 8px;
transition: all 0.3s ease;
position: relative;
}
.gr-radio-group input[type="radio"]:checked {
background-color: #26a69a;
border-color: #26a69a;
}
.gr-radio-group input[type="radio"]:checked::after {
content: "✓";
color: #ffffff;
font-size: 12px;
position: absolute;
top: 1px;
left: 1px;
width: 16px;
height: 16px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
background-color: #26a69a;
}
/* Adjust label for responsive alignment */
.gr-radio-group span {
font-size: 1em;
font-weight: 600;
color: #333333;
}
/* Tab Styling */
.nav-tabs {
display: flex;
justify-content: space-around;
background-color: #ffffff;
border-bottom: 1px solid #e0e0e0;
padding: 12px;
gap: 20px;
border-radius: 8px;
}
.nav-tabs .nav-item {
font-size: 1.2em;
color: #333333;
padding: 10px 18px;
cursor: pointer;
font-weight: 500;
border: 2px solid transparent;
border-radius: 8px;
transition: color 0.3s, background-color 0.3s;
}
.nav-tabs .nav-item:hover {
color: #26a69a;
background-color: rgba(38, 166, 154, 0.1);
}
.nav-tabs .nav-item.active {
color: #00796b;
border-bottom: 3px solid #00796b;
font-weight: 700;
background-color: rgba(38, 166, 154, 0.1);
padding: 8px 16px;
}
/* Output Text Styling */
#registration_output, #test_output, #billing_output {
color: #333333;
background-color: rgba(240, 255, 255, 0.9);
padding: 15px;
border-radius: 7px;
font-weight: bold;
text-align: left;
border: 1px solid #d1e2e8;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.05);
transition: background-color 0.3s ease;
}
#registration_output:hover, #test_output:hover, #billing_output:hover {
background-color: rgba(230, 245, 245, 0.95);
}
"""
# Gradio Interface
with gr.Blocks(css=custom_css) as app:
gr.Markdown("<h1 style='text-align: center;'>👩🏻🔬丂卂ㄒ卄Ҝ尺ㄩㄒ卄卂 ㄥ丨爪丂🔬</h1>", elem_id="header")
with gr.Tab("Patient Registration"):
gr.Markdown("<h2>Register a New Patient</h2>")
with gr.Row():
name = gr.Textbox(label="Patient Name", placeholder="Enter patient's full name", elem_id="name_field")
father_name = gr.Textbox(label="Father/Husband's Name", placeholder="Enter father/husband's full name", elem_id="father_name_field")
with gr.Row():
age = gr.Number(label="Age", value=None, minimum=0, maximum=120, elem_id="age_field")
gender = gr.Radio(
choices=["Male", "Female", "Other"],
label="Gender",
elem_id="gender_field"
)
with gr.Row():
phone = gr.Textbox(label="Phone Number", placeholder="Enter a valid 10-digit phone number", elem_id="phone_field")
address = gr.Textbox(label="Address", placeholder="Enter full address", lines=2, elem_id="address_field")
register_button = gr.Button("Register Patient", elem_id="register_button")
registration_output = gr.Markdown(label="Registration Output", elem_id="registration_output")
register_button.click(registration_interface, [name, father_name, age, gender, phone, address], registration_output)
with gr.Tab("Tests"):
gr.Markdown("<h2>Select Tests for the Patient</h2>")
patient_id_test = gr.Textbox(label="Patient ID", placeholder="Enter 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 Selected Tests")
# Use Markdown for Test Selection Output to allow for auto-expanding content
test_output = gr.Markdown(label="Test Selection Output", elem_id="test_output")
categories.change(test_interface, inputs=categories, outputs=available_tests)
confirm_button.click(confirm_tests_interface, [patient_id_test, available_tests], test_output)
with gr.Tab("Billing"):
gr.Markdown("<h2>Billing Information</h2>")
patient_id_bill = gr.Textbox(label="Patient ID", placeholder="Enter Patient ID for Billing")
fetch_button = gr.Button("Fetch Billing Details")
# Use Markdown for Billing Output to allow for auto-expanding content
billing_output = gr.Markdown(label="Billing Information", elem_id="billing_output")
fetch_button.click(billing_interface, [patient_id_bill], billing_output)
app.launch()
|