Rajan Sharma commited on
Commit
1cc2098
·
verified ·
1 Parent(s): ff957d1

Update response_formatter.py

Browse files
Files changed (1) hide show
  1. response_formatter.py +102 -0
response_formatter.py CHANGED
@@ -117,6 +117,9 @@ class ResponseFormatter:
117
  """Format facility distribution analysis results"""
118
  response = ""
119
 
 
 
 
120
  if "geographic_distribution" in dist_results:
121
  response += "### Geographic Distribution\n\n"
122
  response += "| Region | Facility Count |\n"
@@ -142,6 +145,22 @@ class ResponseFormatter:
142
  diversity = dist_results["facility_diversity"]
143
  response += f"**Facility Diversity Index**: {diversity:.2f} (higher values indicate more diversity)\n\n"
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  return response if response else "No facility distribution data available"
146
 
147
  @staticmethod
@@ -183,6 +202,89 @@ class ResponseFormatter:
183
  growth = capacity_results["capacity_growth_rate"]
184
  response += f"**Overall Growth Rate**: {growth:.1f}%\n\n"
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  return response if response else "No capacity data available"
187
 
188
  @staticmethod
 
117
  """Format facility distribution analysis results"""
118
  response = ""
119
 
120
+ if "total_facilities" in dist_results:
121
+ response += f"**Total Facilities**: {dist_results['total_facilities']:,}\n\n"
122
+
123
  if "geographic_distribution" in dist_results:
124
  response += "### Geographic Distribution\n\n"
125
  response += "| Region | Facility Count |\n"
 
145
  diversity = dist_results["facility_diversity"]
146
  response += f"**Facility Diversity Index**: {diversity:.2f} (higher values indicate more diversity)\n\n"
147
 
148
+ if "top_cities" in dist_results and "city_breakdown" in dist_results:
149
+ response += "### Top Cities by Facility Count\n\n"
150
+ response += "| City | Hospitals | Nursing/Residential | Ambulatory | Total |\n"
151
+ response += "|------|-----------|-------------------|------------|-------|\n"
152
+
153
+ for city in dist_results["top_cities"]:
154
+ if city in dist_results["city_breakdown"]:
155
+ breakdown = dist_results["city_breakdown"][city]
156
+ hospitals = breakdown.get("Hospitals", 0)
157
+ nursing = breakdown.get("Nursing and residential care facilities", 0)
158
+ ambulatory = breakdown.get("Ambulatory health care services", 0)
159
+ total = hospitals + nursing + ambulatory
160
+ response += f"| {city} | {hospitals} | {nursing} | {ambulatory} | {total} |\n"
161
+
162
+ response += "\n"
163
+
164
  return response if response else "No facility distribution data available"
165
 
166
  @staticmethod
 
202
  growth = capacity_results["capacity_growth_rate"]
203
  response += f"**Overall Growth Rate**: {growth:.1f}%\n\n"
204
 
205
+ if "zone_summary" in capacity_results:
206
+ response += "### Bed Capacity by Zone\n\n"
207
+ response += "| Zone | Current Beds | Previous Beds | Absolute Change | Percentage Change |\n"
208
+ response += "|------|--------------|---------------|-----------------|-------------------|\n"
209
+
210
+ for zone_data in capacity_results["zone_summary"]:
211
+ # Extract zone name - try different possible keys
212
+ zone_name = "Unknown"
213
+ for key in ["zone", "Zone", "ZONE", "region", "Region", "REGION"]:
214
+ if key in zone_data:
215
+ zone_name = zone_data[key]
216
+ break
217
+
218
+ # Extract bed counts
219
+ current_beds = zone_data.get("beds_current", zone_data.get("current", "N/A"))
220
+ prev_beds = zone_data.get("beds_prev", zone_data.get("previous", "N/A"))
221
+ abs_change = zone_data.get("bed_change", "N/A")
222
+ pct_change = zone_data.get("percent_change", "N/A")
223
+
224
+ response += f"| {zone_name} | {current_beds} | {prev_beds} | {abs_change} | {pct_change:.1f}% |\n"
225
+
226
+ response += "\n"
227
+
228
+ if "max_absolute_decrease" in capacity_results and isinstance(capacity_results["max_absolute_decrease"], dict):
229
+ response += "### Zone with Largest Absolute Decrease\n\n"
230
+ max_abs = capacity_results["max_absolute_decrease"]
231
+
232
+ # Extract zone name
233
+ zone_name = "Unknown"
234
+ for key in ["zone", "Zone", "ZONE", "region", "Region", "REGION"]:
235
+ if key in max_abs:
236
+ zone_name = max_abs[key]
237
+ break
238
+
239
+ # Extract values
240
+ abs_change = max_abs.get("bed_change", "N/A")
241
+ pct_change = max_abs.get("percent_change", "N/A")
242
+
243
+ response += f"**Zone**: {zone_name}\n"
244
+ response += f"**Absolute Decrease**: {abs_change} beds\n"
245
+ response += f"**Percentage Decrease**: {pct_change:.1f}%\n\n"
246
+
247
+ if "max_percentage_decrease" in capacity_results and isinstance(capacity_results["max_percentage_decrease"], dict):
248
+ response += "### Zone with Largest Percentage Decrease\n\n"
249
+ max_pct = capacity_results["max_percentage_decrease"]
250
+
251
+ # Extract zone name
252
+ zone_name = "Unknown"
253
+ for key in ["zone", "Zone", "ZONE", "region", "Region", "REGION"]:
254
+ if key in max_pct:
255
+ zone_name = max_pct[key]
256
+ break
257
+
258
+ # Extract values
259
+ abs_change = max_pct.get("bed_change", "N/A")
260
+ pct_change = max_pct.get("percent_change", "N/A")
261
+
262
+ response += f"**Zone**: {zone_name}\n"
263
+ response += f"**Absolute Decrease**: {abs_change} beds\n"
264
+ response += f"**Percentage Decrease**: {pct_change:.1f}%\n\n"
265
+
266
+ if "facilities_with_largest_declines" in capacity_results:
267
+ response += "### Facilities with Largest Bed Declines\n\n"
268
+ response += "| Facility | Zone | Teaching Status | Beds Lost |\n"
269
+ response += "|----------|------|----------------|-----------|\n"
270
+
271
+ for facility in capacity_results["facilities_with_largest_declines"]:
272
+ name = facility.get("facility_name", "N/A")
273
+
274
+ # Extract zone name
275
+ zone_name = "Unknown"
276
+ for key in ["zone", "Zone", "ZONE", "region", "Region", "REGION"]:
277
+ if key in facility:
278
+ zone_name = facility[key]
279
+ break
280
+
281
+ teaching = facility.get("teaching_status", "N/A")
282
+ change = facility.get("bed_change", "N/A")
283
+
284
+ response += f"| {name} | {zone_name} | {teaching} | {change} |\n"
285
+
286
+ response += "\n"
287
+
288
  return response if response else "No capacity data available"
289
 
290
  @staticmethod