Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,17 +17,30 @@ CSV_PATH = "hcc_mapping.csv"
|
|
| 17 |
SAMPLE_PDF = "sample_patient_chart.pdf" # Place a sample PDF in the same folder
|
| 18 |
|
| 19 |
|
| 20 |
-
|
| 21 |
-
def json_to_markdown(output_data: dict) -> str:
|
| 22 |
"""
|
| 23 |
-
Convert
|
|
|
|
|
|
|
|
|
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
| 31 |
md = f"""
|
| 32 |
<div style="border:2px solid #4CAF50; padding:15px; border-radius:10px; background:#f9fdf9;">
|
| 33 |
<h2 style="color:#2e7d32;">📋 Patient Report</h2>
|
|
@@ -38,6 +51,7 @@ def json_to_markdown(output_data: dict) -> str:
|
|
| 38 |
<br/>
|
| 39 |
"""
|
| 40 |
|
|
|
|
| 41 |
for idx, diag in enumerate(analyses, 1):
|
| 42 |
md += f"""
|
| 43 |
<div style="border:1px solid #ccc; padding:12px; border-radius:8px; margin-bottom:12px;">
|
|
|
|
| 17 |
SAMPLE_PDF = "sample_patient_chart.pdf" # Place a sample PDF in the same folder
|
| 18 |
|
| 19 |
|
| 20 |
+
def json_to_markdown(data) -> str:
|
|
|
|
| 21 |
"""
|
| 22 |
+
Convert JSON (dict or list) into a clean, styled Markdown/HTML string.
|
| 23 |
+
Handles both:
|
| 24 |
+
- Full dict with patient_id, hcc_code, model_version, final_analysis
|
| 25 |
+
- Just a list of diagnoses
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
+
# Case 1: full dict
|
| 29 |
+
if isinstance(data, dict) and "final_analysis" in data:
|
| 30 |
+
patient_id = data.get("patient_id", "Unknown Patient")
|
| 31 |
+
hcc_code = data.get("hcc_code", "N/A")
|
| 32 |
+
model_version = data.get("model_version", "N/A")
|
| 33 |
+
analyses = data.get("final_analysis", [])
|
| 34 |
+
# Case 2: list of diagnoses
|
| 35 |
+
elif isinstance(data, list):
|
| 36 |
+
patient_id = "N/A"
|
| 37 |
+
hcc_code = "N/A"
|
| 38 |
+
model_version = "N/A"
|
| 39 |
+
analyses = data
|
| 40 |
+
else:
|
| 41 |
+
return "<div style='color:red; font-weight:bold;'>⚠️ Invalid data format for report.</div>"
|
| 42 |
|
| 43 |
+
# Header
|
| 44 |
md = f"""
|
| 45 |
<div style="border:2px solid #4CAF50; padding:15px; border-radius:10px; background:#f9fdf9;">
|
| 46 |
<h2 style="color:#2e7d32;">📋 Patient Report</h2>
|
|
|
|
| 51 |
<br/>
|
| 52 |
"""
|
| 53 |
|
| 54 |
+
# Each diagnosis
|
| 55 |
for idx, diag in enumerate(analyses, 1):
|
| 56 |
md += f"""
|
| 57 |
<div style="border:1px solid #ccc; padding:12px; border-radius:8px; margin-bottom:12px;">
|