|
@@ -135,6 +135,30 @@ def extract_text(file_path):
|
|
|
return lines
|
|
return lines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _normalize_report_date(raw):
|
|
|
|
|
+ """将常见中文/数字日期字符串归一为 YYYY-MM-DD;无法识别返回空串。"""
|
|
|
|
|
+ raw = (raw or '').strip()
|
|
|
|
|
+ m = re.search(r'(\d{4})\s*[-/年.]\s*(\d{1,2})\s*[-/月.]\s*(\d{1,2})', raw)
|
|
|
|
|
+ if m:
|
|
|
|
|
+ return f"{m.group(1)}-{int(m.group(2)):02d}-{int(m.group(3)):02d}"
|
|
|
|
|
+ return ''
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _extract_report_date(text):
|
|
|
|
|
+ """从报告文本提取报告日期/采样日期/检测日期等,归一为 YYYY-MM-DD。
|
|
|
|
|
+
|
|
|
|
|
+ 命中失败返回空串(保持 overview.report_date=null,不造假值)。
|
|
|
|
|
+ """
|
|
|
|
|
+ for kw in ('报告出具日期', '采样日期', '检测日期', '报告日期',
|
|
|
|
|
+ '采样时间', '检测时间', '报告时间'):
|
|
|
|
|
+ m = re.search(rf'{kw}\s*[::]?\s*(\d{{4}}\s*[-/年.]\s*\d{{1,2}}\s*[-/月.]\s*\d{{1,2}})', text)
|
|
|
|
|
+ if m:
|
|
|
|
|
+ d = _normalize_report_date(m.group(1))
|
|
|
|
|
+ if d:
|
|
|
|
|
+ return d
|
|
|
|
|
+ return ''
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def parse_overview(lines):
|
|
def parse_overview(lines):
|
|
|
"""提取报告概述"""
|
|
"""提取报告概述"""
|
|
|
text = '\n'.join(lines)
|
|
text = '\n'.join(lines)
|
|
@@ -155,6 +179,10 @@ def parse_overview(lines):
|
|
|
if m: r['gut_age'] = m.group(1)
|
|
if m: r['gut_age'] = m.group(1)
|
|
|
m = re.search(r'肠型[::\s]*(\S+)', text)
|
|
m = re.search(r'肠型[::\s]*(\S+)', text)
|
|
|
if m: r['gut_type'] = m.group(1)
|
|
if m: r['gut_type'] = m.group(1)
|
|
|
|
|
+ # V-02 fix: 补 report_date 提取(报告/采样/检测日期常见形态);无则保持 null
|
|
|
|
|
+ report_date = _extract_report_date(text)
|
|
|
|
|
+ if report_date:
|
|
|
|
|
+ r['report_date'] = report_date
|
|
|
return r
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1842,6 +1870,10 @@ def _parse_bj_overview(text):
|
|
|
if m: r['age'] = m.group(1)
|
|
if m: r['age'] = m.group(1)
|
|
|
m = re.search(r'性\s*别[::\s]*(\S+)', text)
|
|
m = re.search(r'性\s*别[::\s]*(\S+)', text)
|
|
|
if m: r['gender'] = 'male' if m.group(1) in ('男', 'M') else 'female'
|
|
if m: r['gender'] = 'male' if m.group(1) in ('男', 'M') else 'female'
|
|
|
|
|
+ # V-02 fix: 补 report_date 提取;无则保持 null(不造假值)
|
|
|
|
|
+ report_date = _extract_report_date(text)
|
|
|
|
|
+ if report_date:
|
|
|
|
|
+ r['report_date'] = report_date
|
|
|
# 肠型
|
|
# 肠型
|
|
|
gut_type = _parse_bj_gut_type(text)
|
|
gut_type = _parse_bj_gut_type(text)
|
|
|
if gut_type: r['gut_type'] = gut_type
|
|
if gut_type: r['gut_type'] = gut_type
|