moazx commited on
Commit
f73f660
·
1 Parent(s): 70b9c9d

Update the HBV responses

Browse files
Files changed (1) hide show
  1. core/hbv_assessment.py +23 -4
core/hbv_assessment.py CHANGED
@@ -76,7 +76,7 @@ def normalize_recommendations(text: str) -> str:
76
  Normalize the recommendations string for concise, consistent formatting.
77
  - Remove extra blank lines
78
  - Trim trailing/leading whitespace on each line
79
- - Ensure single "\n" between lines
80
  - Optionally cap length to avoid overly long outputs
81
  """
82
  if not text:
@@ -86,7 +86,25 @@ def normalize_recommendations(text: str) -> str:
86
  # Split, strip, and drop empty lines
87
  lines = [ln.strip() for ln in text.split('\n')]
88
  lines = [ln for ln in lines if ln]
89
- normalized = '\n'.join(lines)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # Soft cap length (keep whole content if already short)
91
  max_len = 1800
92
  if len(normalized) > max_len:
@@ -275,6 +293,7 @@ IMPORTANT JSON FORMATTING:
275
  - Return ONLY valid JSON without markdown code blocks
276
  - You MUST use "\\n" to indicate line breaks inside the "recommendations" string and format the content as clear bullet lists prefixed with "- ".
277
  - Do NOT include literal newline characters. Use \\n for every new bullet or line.
 
278
 
279
  STRUCTURE AND CONTENT OF "recommendations" (CONCISE & ORGANIZED):
280
  - Use ONLY these sections in this exact order, each as a header followed by 1-3 concise bullets:
@@ -307,10 +326,10 @@ PAGE-TO-TOPIC MAPPING GUIDANCE (for correct citations):
307
  - Page 9: Special populations (HBV-HCV, HBV-HDV, HBV-HIV, immunocompromised).
308
  - Page 10: Pregnancy-related recommendations (late pregnancy prophylaxis, breastfeeding, switching).
309
 
310
- EXAMPLE OUTPUT (ELIGIBLE PATIENT):
311
  Eligibility and Rationale:\n- Eligible: HBV DNA > 2,000 IU/mL, ALT > ULN, moderate fibrosis (Grade A) [SASLT 2021, Page 6]\nTreatment Recommendations:\n- Start monotherapy with ETV, TDF, or TAF (Grade A) [SASLT 2021, Page 8]\nMonitoring and Follow-up:\n- Monitor treatment response per SASLT protocol [SASLT 2021, Page 7]\nSpecial Considerations:\n- HBV-HIV coinfection: use TDF- or TAF-based ART (Grade A) [SASLT 2021, Page 9]\nReferences:\n- Pages 6, 7, 8, 9: Treatment criteria, drugs, monitoring, HIV coinfection
312
 
313
- EXAMPLE OUTPUT (NOT ELIGIBLE PATIENT):
314
  Eligibility and Rationale:\n- Not eligible: HBV DNA < 2,000 IU/mL, ALT ≤ ULN, no significant fibrosis [SASLT 2021, Page 6]\nTreatment Recommendations:\n- Treatment not indicated at this time [SASLT 2021, Page 6]\nMonitoring and Follow-up:\n- Monitor every 6-12 months (HBeAg-negative, HBV DNA < 2,000 IU/mL) (Grade B) [SASLT 2021, Page 7]\nReferences:\n- Pages 6, 7: Treatment criteria, monitoring protocols
315
 
316
  CRITICAL REQUIREMENTS:
 
76
  Normalize the recommendations string for concise, consistent formatting.
77
  - Remove extra blank lines
78
  - Trim trailing/leading whitespace on each line
79
+ - Add single blank line before section headers for readability
80
  - Optionally cap length to avoid overly long outputs
81
  """
82
  if not text:
 
86
  # Split, strip, and drop empty lines
87
  lines = [ln.strip() for ln in text.split('\n')]
88
  lines = [ln for ln in lines if ln]
89
+
90
+ # Add spacing before section headers (lines ending with ':')
91
+ # but not before the first line
92
+ formatted_lines = []
93
+ section_headers = [
94
+ 'Eligibility and Rationale:',
95
+ 'Treatment Recommendations:',
96
+ 'Monitoring and Follow-up:',
97
+ 'Special Considerations:',
98
+ 'References:'
99
+ ]
100
+
101
+ for i, line in enumerate(lines):
102
+ # Add blank line before section headers (except first line)
103
+ if i > 0 and any(line.startswith(header) for header in section_headers):
104
+ formatted_lines.append('') # Add blank line
105
+ formatted_lines.append(line)
106
+
107
+ normalized = '\n'.join(formatted_lines)
108
  # Soft cap length (keep whole content if already short)
109
  max_len = 1800
110
  if len(normalized) > max_len:
 
293
  - Return ONLY valid JSON without markdown code blocks
294
  - You MUST use "\\n" to indicate line breaks inside the "recommendations" string and format the content as clear bullet lists prefixed with "- ".
295
  - Do NOT include literal newline characters. Use \\n for every new bullet or line.
296
+ - Use SINGLE \\n between lines. Do NOT use \\n\\n (double newlines) anywhere.
297
 
298
  STRUCTURE AND CONTENT OF "recommendations" (CONCISE & ORGANIZED):
299
  - Use ONLY these sections in this exact order, each as a header followed by 1-3 concise bullets:
 
326
  - Page 9: Special populations (HBV-HCV, HBV-HDV, HBV-HIV, immunocompromised).
327
  - Page 10: Pregnancy-related recommendations (late pregnancy prophylaxis, breastfeeding, switching).
328
 
329
+ EXAMPLE OUTPUT (ELIGIBLE PATIENT) - Use SINGLE \\n only:
330
  Eligibility and Rationale:\n- Eligible: HBV DNA > 2,000 IU/mL, ALT > ULN, moderate fibrosis (Grade A) [SASLT 2021, Page 6]\nTreatment Recommendations:\n- Start monotherapy with ETV, TDF, or TAF (Grade A) [SASLT 2021, Page 8]\nMonitoring and Follow-up:\n- Monitor treatment response per SASLT protocol [SASLT 2021, Page 7]\nSpecial Considerations:\n- HBV-HIV coinfection: use TDF- or TAF-based ART (Grade A) [SASLT 2021, Page 9]\nReferences:\n- Pages 6, 7, 8, 9: Treatment criteria, drugs, monitoring, HIV coinfection
331
 
332
+ EXAMPLE OUTPUT (NOT ELIGIBLE PATIENT) - Use SINGLE \\n only:
333
  Eligibility and Rationale:\n- Not eligible: HBV DNA < 2,000 IU/mL, ALT ≤ ULN, no significant fibrosis [SASLT 2021, Page 6]\nTreatment Recommendations:\n- Treatment not indicated at this time [SASLT 2021, Page 6]\nMonitoring and Follow-up:\n- Monitor every 6-12 months (HBeAg-negative, HBV DNA < 2,000 IU/mL) (Grade B) [SASLT 2021, Page 7]\nReferences:\n- Pages 6, 7: Treatment criteria, monitoring protocols
334
 
335
  CRITICAL REQUIREMENTS: