|
|
@@ -1519,8 +1519,23 @@ def _parse_bj_core_bacteria(text):
|
|
|
return bacteria
|
|
|
|
|
|
|
|
|
+def _parse_related_bacteria_in_chunk(chunk):
|
|
|
+ """从文本片段提取关联菌列表(如:乳杆菌属(缺乏)、另枝菌属(超标))"""
|
|
|
+ bacteria = []
|
|
|
+ for bm in re.finditer(
|
|
|
+ r'([\u4e00-\u9fa5]{2,10}?(?:菌|属|科|杆菌|球菌|梭菌))[((]\s*(超标|缺乏|偏高|偏低|异常|正常)\s*[))]',
|
|
|
+ chunk):
|
|
|
+ bacteria.append({
|
|
|
+ 'bacteria': bm.group(1),
|
|
|
+ 'correlation': bm.group(2),
|
|
|
+ 'value': '',
|
|
|
+ 'status': '',
|
|
|
+ })
|
|
|
+ return bacteria
|
|
|
+
|
|
|
+
|
|
|
def _parse_bj_disease_risks(text):
|
|
|
- """提取疾病风险评估"""
|
|
|
+ """提取疾病风险评估(含关联菌 P0)"""
|
|
|
diseases = []
|
|
|
for keyword in DISEASE_KEYWORDS_BJ:
|
|
|
idx = text.find(keyword)
|
|
|
@@ -1529,11 +1544,38 @@ def _parse_bj_disease_risks(text):
|
|
|
val_m = re.search(r'(\d+\.\d+)', chunk)
|
|
|
level_m = re.search(r'(低风险|较低风险|中度风险|较高风险|高风险)', chunk)
|
|
|
if val_m:
|
|
|
- diseases.append({
|
|
|
+ entry = {
|
|
|
'疾病': keyword,
|
|
|
'风险指数': float(val_m.group(1)),
|
|
|
'风险等级': level_m.group(1) if level_m else '',
|
|
|
- })
|
|
|
+ }
|
|
|
+ bacteria = _parse_related_bacteria_in_chunk(chunk)
|
|
|
+ if bacteria:
|
|
|
+ entry['related_bacteria'] = bacteria
|
|
|
+ diseases.append(entry)
|
|
|
+
|
|
|
+ # 补充:从「疾病肠菌评估(异常项)」章节提取关联菌,按疾病名匹配补挂
|
|
|
+ ab_idx = text.find('疾病肠菌评估')
|
|
|
+ if ab_idx != -1:
|
|
|
+ ab_sec = text[ab_idx:ab_idx + 1800]
|
|
|
+ for entry in diseases:
|
|
|
+ if entry.get('related_bacteria'):
|
|
|
+ continue
|
|
|
+ kw_idx = ab_sec.find(entry['疾病'])
|
|
|
+ if kw_idx == -1:
|
|
|
+ continue
|
|
|
+ # 截断到下一个疾病关键字,避免跨疾病串扰
|
|
|
+ end = len(ab_sec)
|
|
|
+ for other in DISEASE_KEYWORDS_BJ:
|
|
|
+ if other == entry['疾病']:
|
|
|
+ continue
|
|
|
+ oi = ab_sec.find(other, kw_idx + len(entry['疾病']))
|
|
|
+ if oi != -1 and oi < end:
|
|
|
+ end = oi
|
|
|
+ chunk = ab_sec[kw_idx:end]
|
|
|
+ bacteria = _parse_related_bacteria_in_chunk(chunk)
|
|
|
+ if bacteria:
|
|
|
+ entry['related_bacteria'] = bacteria
|
|
|
return diseases
|
|
|
|
|
|
|
|
|
@@ -1931,6 +1973,11 @@ def _parse_beijing_report(file_path: str) -> dict:
|
|
|
if pathogens:
|
|
|
result['胃肠道感染病原体'] = pathogens
|
|
|
|
|
|
+ # 肠道菌群状态 → overview.gutStatusLevel(P1)
|
|
|
+ status = result.get('肠道微生物健康指数', {}).get('肠道菌群状态')
|
|
|
+ if status:
|
|
|
+ result['overview']['gutStatusLevel'] = status
|
|
|
+
|
|
|
# 营养物质 → 标准字段映射
|
|
|
metabolism = result.get('营养物质及营养素代谢评估', {})
|
|
|
if metabolism.get('主要营养物质代谢'):
|