```
feat(CaptureService): 改进报告解析逻辑并添加多语言键支持 - 修改应用描述从"个人健康影像档案"到"个人健康随记" - 添加对多种JSON键名的支持,包括中文键名(如"指标"、"项目"、"结果"等) - 实现指标状态智能推断功能,可根据数值和参考范围自动判断高低状态 - 支持多种状态标识符,包括箭头符号(↑↓)和中英文状态词 - 增加对不同参考范围格式的解析支持(如"< 3.40"、"208 - 428"等) - 添加相关单元测试验证中文键名和状态推断功能 ```
This commit is contained in:
@@ -100,6 +100,42 @@ struct CaptureServiceJSONTests {
|
||||
#expect(parsed.indicators.first?.status == .normal)
|
||||
}
|
||||
|
||||
@Test func parsesRegionJSONWithChineseKeysAndArrowStatus() throws {
|
||||
let raw = """
|
||||
{"指标":[{"项目":"尿酸","结果":"486","单位":"μmol/L","参考范围":"208 - 428","异常":"↑"}]}
|
||||
"""
|
||||
let indicators = try CaptureService.parseIndicatorsJSON(raw)
|
||||
#expect(indicators.count == 1)
|
||||
#expect(indicators.first?.name == "尿酸")
|
||||
#expect(indicators.first?.value == "486")
|
||||
#expect(indicators.first?.unit == "μmol/L")
|
||||
#expect(indicators.first?.range == "208 - 428")
|
||||
#expect(indicators.first?.status == .high)
|
||||
}
|
||||
|
||||
@Test func parsesReportJSONWithChineseIndicatorArrayKey() throws {
|
||||
let raw = """
|
||||
{"title":"t","type":"lab","report_date":"2026-05-01","指标":[{"项目":"尿酸","结果":"486","单位":"μmol/L","参考范围":"208 - 428","异常":"偏高"}]}
|
||||
"""
|
||||
let parsed = try CaptureService.parseReportJSON(raw)
|
||||
#expect(parsed.indicators.count == 1)
|
||||
#expect(parsed.indicators.first?.name == "尿酸")
|
||||
#expect(parsed.indicators.first?.status == .high)
|
||||
}
|
||||
|
||||
@Test func infersStatusFromValueAndReferenceRangeWhenStatusMissing() throws {
|
||||
let raw = """
|
||||
{"indicators":[
|
||||
{"name":"低密度脂蛋白","value":"3.84","unit":"mmol/L","range":"< 3.40"},
|
||||
{"name":"白细胞","value":"2.8","unit":"10^9/L","range":"3.5 - 9.5"}
|
||||
]}
|
||||
"""
|
||||
let indicators = try CaptureService.parseIndicatorsJSON(raw)
|
||||
#expect(indicators.count == 2)
|
||||
#expect(indicators[0].status == .high)
|
||||
#expect(indicators[1].status == .low)
|
||||
}
|
||||
|
||||
@Test func badReportDateFallsBackToNow() throws {
|
||||
let raw = """
|
||||
{"title":"t","type":"lab","report_date":"昨天","institution":"","page_count":1,"summary":"","indicators":[]}
|
||||
|
||||
Reference in New Issue
Block a user