Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -134,7 +134,7 @@ def is_healthcare_scenario(text: str, uploaded_files_paths) -> bool:
|
|
| 134 |
has_healthcare_keywords = any(keyword in t for keyword in HEALTHCARE_SETTINGS["healthcare_keywords"])
|
| 135 |
|
| 136 |
# Check for healthcare facility types
|
| 137 |
-
has_facility_types =
|
| 138 |
any(ftype in t for ftype in ["hospital", "medical center", "health centre"]) or
|
| 139 |
any(ftype in t for ftype in ["nursing", "residential", "care facility", "long-term care"]) or
|
| 140 |
any(ftype in t for ftype in ["ambulatory", "clinic", "surgery center", "outpatient"])
|
|
@@ -196,6 +196,10 @@ def process_healthcare_data(uploaded_files_paths, data_registry):
|
|
| 196 |
def analyze_facility_distribution(facilities_df):
|
| 197 |
"""Analyze healthcare facility distribution dynamically."""
|
| 198 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
# Find province column
|
| 200 |
province_col = find_column(facilities_df, ['province', 'state', 'territory'])
|
| 201 |
if province_col:
|
|
@@ -245,6 +249,10 @@ def analyze_facility_distribution(facilities_df):
|
|
| 245 |
def analyze_bed_capacity(beds_df):
|
| 246 |
"""Analyze bed capacity dynamically."""
|
| 247 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
# Find required columns
|
| 249 |
current_col = find_column(beds_df, ['current', '2023', '2024', 'beds_current', 'staffed_beds', 'capacity'])
|
| 250 |
prev_col = find_column(beds_df, ['prev', 'previous', '2022', 'beds_prev', 'previous_beds'])
|
|
@@ -322,6 +330,10 @@ def analyze_bed_capacity(beds_df):
|
|
| 322 |
def assess_long_term_capacity(facilities_df, beds_df, zone_name):
|
| 323 |
"""Assess long-term care capacity dynamically."""
|
| 324 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
# Find relevant columns
|
| 326 |
zone_col = find_column(facilities_df, ['zone', 'region', 'area', 'district'])
|
| 327 |
city_col = find_column(facilities_df, ['city', 'municipality', 'town'])
|
|
@@ -444,13 +456,13 @@ def format_healthcare_analysis_response(scenario_text, results, recommendations,
|
|
| 444 |
response += "## 1. Data Preparation\n\n"
|
| 445 |
response += f"Total healthcare facilities: {fd.get('total_facilities', 'N/A')}\n\n"
|
| 446 |
|
| 447 |
-
if 'type_distribution' in fd:
|
| 448 |
response += "### Facility Type Distribution\n\n"
|
| 449 |
for ftype, count in fd['type_distribution'].items():
|
| 450 |
response += f"- {ftype}: {count}\n"
|
| 451 |
response += "\n"
|
| 452 |
|
| 453 |
-
if 'city_breakdown' in fd:
|
| 454 |
response += "### Top Cities by Facility Count\n\n"
|
| 455 |
response += "| City | Hospitals | Nursing/Residential | Ambulatory | Total |\n"
|
| 456 |
response += "|------|-----------|-------------------|------------|-------|\n"
|
|
@@ -529,7 +541,7 @@ def format_healthcare_analysis_response(scenario_text, results, recommendations,
|
|
| 529 |
response += f"In {zone} Zone, the major city is {city} with a nursing/residential to hospital ratio of {ratio:.2f}.\n\n"
|
| 530 |
response += f"Long-term care capacity appears **{assessment}** in {city}.\n\n"
|
| 531 |
|
| 532 |
-
if 'facility_counts' in ltc:
|
| 533 |
response += "### Facility Counts\n\n"
|
| 534 |
for ftype, count in ltc['facility_counts'].items():
|
| 535 |
response += f"- {ftype}: {count}\n"
|
|
|
|
| 134 |
has_healthcare_keywords = any(keyword in t for keyword in HEALTHCARE_SETTINGS["healthcare_keywords"])
|
| 135 |
|
| 136 |
# Check for healthcare facility types
|
| 137 |
+
has_facility_types = (
|
| 138 |
any(ftype in t for ftype in ["hospital", "medical center", "health centre"]) or
|
| 139 |
any(ftype in t for ftype in ["nursing", "residential", "care facility", "long-term care"]) or
|
| 140 |
any(ftype in t for ftype in ["ambulatory", "clinic", "surgery center", "outpatient"])
|
|
|
|
| 196 |
def analyze_facility_distribution(facilities_df):
|
| 197 |
"""Analyze healthcare facility distribution dynamically."""
|
| 198 |
try:
|
| 199 |
+
# Validate input
|
| 200 |
+
if facilities_df is None or facilities_df.empty:
|
| 201 |
+
return {"error": "No facility data provided"}
|
| 202 |
+
|
| 203 |
# Find province column
|
| 204 |
province_col = find_column(facilities_df, ['province', 'state', 'territory'])
|
| 205 |
if province_col:
|
|
|
|
| 249 |
def analyze_bed_capacity(beds_df):
|
| 250 |
"""Analyze bed capacity dynamically."""
|
| 251 |
try:
|
| 252 |
+
# Validate input
|
| 253 |
+
if beds_df is None or beds_df.empty:
|
| 254 |
+
return {"error": "No bed data provided"}
|
| 255 |
+
|
| 256 |
# Find required columns
|
| 257 |
current_col = find_column(beds_df, ['current', '2023', '2024', 'beds_current', 'staffed_beds', 'capacity'])
|
| 258 |
prev_col = find_column(beds_df, ['prev', 'previous', '2022', 'beds_prev', 'previous_beds'])
|
|
|
|
| 330 |
def assess_long_term_capacity(facilities_df, beds_df, zone_name):
|
| 331 |
"""Assess long-term care capacity dynamically."""
|
| 332 |
try:
|
| 333 |
+
# Validate inputs
|
| 334 |
+
if facilities_df is None or facilities_df.empty:
|
| 335 |
+
return {"error": "No facility data provided"}
|
| 336 |
+
|
| 337 |
# Find relevant columns
|
| 338 |
zone_col = find_column(facilities_df, ['zone', 'region', 'area', 'district'])
|
| 339 |
city_col = find_column(facilities_df, ['city', 'municipality', 'town'])
|
|
|
|
| 456 |
response += "## 1. Data Preparation\n\n"
|
| 457 |
response += f"Total healthcare facilities: {fd.get('total_facilities', 'N/A')}\n\n"
|
| 458 |
|
| 459 |
+
if 'type_distribution' in fd and isinstance(fd['type_distribution'], dict):
|
| 460 |
response += "### Facility Type Distribution\n\n"
|
| 461 |
for ftype, count in fd['type_distribution'].items():
|
| 462 |
response += f"- {ftype}: {count}\n"
|
| 463 |
response += "\n"
|
| 464 |
|
| 465 |
+
if 'city_breakdown' in fd and isinstance(fd['city_breakdown'], dict):
|
| 466 |
response += "### Top Cities by Facility Count\n\n"
|
| 467 |
response += "| City | Hospitals | Nursing/Residential | Ambulatory | Total |\n"
|
| 468 |
response += "|------|-----------|-------------------|------------|-------|\n"
|
|
|
|
| 541 |
response += f"In {zone} Zone, the major city is {city} with a nursing/residential to hospital ratio of {ratio:.2f}.\n\n"
|
| 542 |
response += f"Long-term care capacity appears **{assessment}** in {city}.\n\n"
|
| 543 |
|
| 544 |
+
if 'facility_counts' in ltc and isinstance(ltc['facility_counts'], dict):
|
| 545 |
response += "### Facility Counts\n\n"
|
| 546 |
for ftype, count in ltc['facility_counts'].items():
|
| 547 |
response += f"- {ftype}: {count}\n"
|