日常更新

from NUC
This commit is contained in:
liubiren 2025-12-10 21:56:38 +08:00
parent da52d06fa8
commit 6a286e7c69
2 changed files with 87 additions and 81 deletions

View File

@ -22,7 +22,7 @@ from dateutil.parser import parse
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from zen import ZenDecision, ZenEngine from zen import ZenDecision, ZenEngine
from utils.client import Authenticator, HTTPClient, CacheClient from utils.client import Authenticator, HTTPClient
# from utils.ocr import fuzzy_match # from utils.ocr import fuzzy_match
@ -905,15 +905,6 @@ def common_extraction(**kwargs) -> dict | None:
return extraction return extraction
# 初始化规则引擎
def decision(rules_path: Path) -> ZenDecision:
def loader(path):
with open(path, "r", encoding="utf-8") as file:
return file.read()
return ZenEngine({"loader": loader}).get_decision(rules_path.as_posix())
def disease_diagnosis(**kwargs) -> str | None: def disease_diagnosis(**kwargs) -> str | None:
"""疾病推定""" """疾病推定"""
@ -980,14 +971,26 @@ if __name__ == "__main__":
# 实例请求客户端 # 实例请求客户端
http_client = HTTPClient(timeout=300, cache_enabled=True) # 使用缓存 http_client = HTTPClient(timeout=300, cache_enabled=True) # 使用缓存
# 初始化影像件识别规则引擎
recognize_decision = decision(Path("rules/影像件是否需要数据提取.json"))
# 初始化工作目录地址对象 # 初始化工作目录地址对象
directory_path = Path("directory") directory_path = Path("directory")
# 若不存在则创建 # 若不存在则创建
directory_path.mkdir(parents=True, exist_ok=True) directory_path.mkdir(parents=True, exist_ok=True)
def rule_engine(rule_path: Path) -> ZenDecision:
"""
本地打开并读取规则文件并实例化规则引擎
:param rule_path: 规则文件路径对象
"""
def loader(path):
with open(path, "r", encoding="utf-8") as file:
return file.read()
return ZenEngine({"loader": loader}).get_decision(rule_path.as_posix())
# 影像件识别使能
recognition_enable = rule_engine(Path("rules/影像件识别使能.json"))
# 初始化JINJA2环境 # 初始化JINJA2环境
environment = Environment(loader=FileSystemLoader(".")) environment = Environment(loader=FileSystemLoader("."))
# 添加DATE过滤器 # 添加DATE过滤器
@ -1041,7 +1044,7 @@ if __name__ == "__main__":
return image_guid return image_guid
# noinspection PyShadowingNames # noinspection PyShadowingNames
def images_classify( def image_classify(
image_guid: str, image_format: str, image_ndarray: numpy.ndarray image_guid: str, image_format: str, image_ndarray: numpy.ndarray
) -> Optional[Tuple[str, str, str]]: ) -> Optional[Tuple[str, str, str]]:
""" """
@ -1053,7 +1056,7 @@ if __name__ == "__main__":
""" """
# noinspection PyShadowingNames # noinspection PyShadowingNames
def images_compress( def image_compress(
image_format, image_ndarray, image_size_specified=2 image_format, image_ndarray, image_size_specified=2
) -> Optional[str]: ) -> Optional[str]:
""" """
@ -1109,7 +1112,7 @@ if __name__ == "__main__":
return None return None
# 影像件压缩 # 影像件压缩
image_base64 = images_compress( image_base64 = image_compress(
image_format, image_ndarray, image_size_specified=2 image_format, image_ndarray, image_size_specified=2
) # 深圳快瞳要求为2兆字节 ) # 深圳快瞳要求为2兆字节
# TODO: 若影像件压缩发生异常则流转至人工处理 # TODO: 若影像件压缩发生异常则流转至人工处理
@ -1136,7 +1139,6 @@ if __name__ == "__main__":
raise RuntimeError("请求深圳快瞳影像件分类接口发生异常") raise RuntimeError("请求深圳快瞳影像件分类接口发生异常")
# 解析影像件类型 # 解析影像件类型
# TODO: 后续完成居民户口簿、中国港澳台地区及境外护照和医疗费用清单
# noinspection PyTypeChecker # noinspection PyTypeChecker
match (response["data"]["flag"], response["data"]["type"]): match (response["data"]["flag"], response["data"]["type"]):
case (14, _): case (14, _):
@ -1183,13 +1185,15 @@ if __name__ == "__main__":
}[image_orientation], }[image_orientation],
) )
# 旋正后影像件再次压缩 # 旋正后影像件再次压缩
image_base64 = images_compress( image_base64 = image_compress(
image_format, image_ndarray, image_size_specified=2 image_format, image_ndarray, image_size_specified=2
) )
# TODO: 若旋正后影像件再次压缩发生异常则流转至人工处理 # TODO: 若旋正后影像件再次压缩发生异常则流转至人工处理
if image_base64 is None: if image_base64 is None:
raise RuntimeError("旋正后影像件再次压缩发生异常") raise RuntimeError("旋正后影像件再次压缩发生异常")
global image
return image_base64, image_type, image_orientation return image_base64, image_type, image_orientation
# 遍历工作目录中赔案目录并创建赔案档案(模拟自动化域就待自动化任务创建理赔档案) # 遍历工作目录中赔案目录并创建赔案档案(模拟自动化域就待自动化任务创建理赔档案)
@ -1198,7 +1202,9 @@ if __name__ == "__main__":
# 报案渠道包括:保司定义,例如中银项目包括总行和各地分行驻场报案和普康宝自助报案等 # 报案渠道包括:保司定义,例如中银项目包括总行和各地分行驻场报案和普康宝自助报案等
dossier = { dossier = {
"报案层": { "报案层": {
"保险分公司": "中银保险有限公司广东分公司", # 设定:保险分公司为中银保险有限公司广东分公司 "保险分公司": (
insurance_branch := "中银保险有限公司广东分公司"
), # 设定:保险分公司为中银保险有限公司广东分公司
"赔案号": (case_number := case_path.stem), # 设定:赔案目录名称为赔案号 "赔案号": (case_number := case_path.stem), # 设定:赔案目录名称为赔案号
}, },
"影像件层": [], "影像件层": [],
@ -1234,8 +1240,8 @@ if __name__ == "__main__":
image_guid := image_serialize(image_format, image_ndarray) image_guid := image_serialize(image_format, image_ndarray)
) )
# 影像件分类并旋正(较初审自动化无使能检查) # 影像件分类并旋正(较初审自动化无使能检查)
image_base64, image_type, image_orientation = images_classify( image_base64, image_type, image_orientation = image_classify(
image_guid, image_format, image_ndarray image_guid, image_format, image_ndarray
) )
image["影像件类型"] = image_type image["影像件类型"] = image_type
@ -1243,22 +1249,22 @@ if __name__ == "__main__":
# 将影像件数据添加至影像件层 # 将影像件数据添加至影像件层
dossier["影像件层"].append(image) dossier["影像件层"].append(image)
# 影像件识别 print(dossier)
exit()
# 影像件识别使能检查,若影像件不识别则跳过
if not recognition_enable.evaluate(
{
"insurance_branch": insurance_branch,
"image_type": image_type,
}
)["result"]["recognition_enable"]:
continue
print(dossier)
exit()
""" """
# 根据保险总公司和影像件类型评估影像件是否需要数据提取,若无需数据提取则跳过该影像件(例如,中银保险有限公司理赔申请书包含户名、开户银行和银行账号,无需识别银行卡)
if not recognize_decision.evaluate(
{
"insurer": (insurer := dossier["赔案层"]["保险总公司"]),
"image_type": image_type,
}
)["result"]["extract"]:
dossier["影像件层"][-1]["已识别"] = "否,无需识别"
continue
# 根据影像件类型匹配影像件数据提取 # 根据影像件类型匹配影像件数据提取
# noinspection PyUnreachableCode # noinspection PyUnreachableCode

View File

@ -9,8 +9,8 @@
"id": "a56fc802-839b-4310-999e-054fcfdac452", "id": "a56fc802-839b-4310-999e-054fcfdac452",
"name": "request", "name": "request",
"position": { "position": {
"x": 125, "x": 110,
"y": 265 "y": 114
} }
}, },
{ {
@ -21,8 +21,8 @@
"id": "47992630-e8f6-4475-8307-437dc2b93acd", "id": "47992630-e8f6-4475-8307-437dc2b93acd",
"name": "response", "name": "response",
"position": { "position": {
"x": 845, "x": 750,
"y": 235 "y": 114
} }
}, },
{ {
@ -30,93 +30,93 @@
"content": { "content": {
"hitPolicy": "first", "hitPolicy": "first",
"rules": [ "rules": [
{
"_id": "8e5bf894-22b5-429c-ab9d-1ed541cc562b",
"_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民户口簿\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
},
{ {
"_id": "14b4347e-2d98-4e7f-80c6-2c1f70db7f38", "_id": "14b4347e-2d98-4e7f-80c6-2c1f70db7f38",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民身份证(正背面)\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民身份证(国徽、头像面)\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "f01654f5-fa1a-480b-bfbe-a6dc13120aa9", "_id": "f01654f5-fa1a-480b-bfbe-a6dc13120aa9",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民身份证(面)\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民身份证(国徽面)\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "25cf23fb-c150-4f2a-b896-8ca25f6107e0", "_id": "25cf23fb-c150-4f2a-b896-8ca25f6107e0",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民身份证(背面)\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"居民身份证(头像面)\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
},
{
"_id": "87984822-cd34-4819-b83f-78741b5b0b6a",
"_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"中国港澳台地区及境外护照\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "8f414db5-1f47-4814-9c81-7e036f0da92a", "_id": "8f414db5-1f47-4814-9c81-7e036f0da92a",
"_description": "", "_description": "中银保险有限公司广东分公司就银行卡不识别",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"银行卡\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"银行卡\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
},
{
"_id": "c373959c-1b1b-4149-8062-22fb3f0b4eb0",
"_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"增值税发票(电子)\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\""
}, },
{ {
"_id": "f64b5e4c-74e3-41ae-96d3-eec72fa512dd", "_id": "f64b5e4c-74e3-41ae-96d3-eec72fa512dd",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"增值税发票\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"增值税发票\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
},
{
"_id": "ffdfd273-2c0a-4d49-86f0-a4f20572d522",
"_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"医疗费用清单\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "6120b722-abd9-4f17-a97b-45eaa854961f", "_id": "6120b722-abd9-4f17-a97b-45eaa854961f",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"门诊收费票据(电子)\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"门诊收费票据\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "3048396c-b175-44ee-9bcf-8e83aea55280", "_id": "3048396c-b175-44ee-9bcf-8e83aea55280",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"门诊收费票据\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\""
},
{
"_id": "11df6fc8-22c4-49fc-a54d-0c529daaba17",
"_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"住院收费票据(电子)\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\""
},
{
"_id": "d5983617-093f-460f-a3e2-33054c644dab",
"_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"住院收费票据\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"住院收费票据\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "9ff5abf3-516e-4b13-a353-b47b4ee29107", "_id": "9ff5abf3-516e-4b13-a353-b47b4ee29107",
"_description": "", "_description": "",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"理赔申请书\"", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"理赔申请书\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "true",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "f0d20445-48f1-4980-8d3d-0173fc906293", "_id": "f0d20445-48f1-4980-8d3d-0173fc906293",
"_description": "中银保险有限公司其它影像件类型不需要数据抽取", "_description": "中银保险有限公司就其它影像件类型不识别",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "\"其它\"",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司\"" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "\"中银保险有限公司广东分公司\""
}, },
{ {
"_id": "9ed5dfc9-85c9-4617-9e54-dfdb8c0c2049", "_id": "9ed5dfc9-85c9-4617-9e54-dfdb8c0c2049",
"_description": "其它保险总公司、影像件类型不需要数据抽取", "_description": "其它保险分公司所有影像件类型不识别",
"88d06a40-06ea-472b-9f8f-f4daf6468c52": "", "88d06a40-06ea-472b-9f8f-f4daf6468c52": "",
"a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false", "a2fc744f-930d-43e0-b5cf-824a5928c7f1": "false",
"edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": "" "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b": ""
@ -126,7 +126,7 @@
{ {
"id": "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b", "id": "edfeddf0-41bd-4cb7-8cb2-a3c4afa7fc3b",
"name": "保险总公司", "name": "保险总公司",
"field": "insurer" "field": "insurance_branch"
}, },
{ {
"id": "88d06a40-06ea-472b-9f8f-f4daf6468c52", "id": "88d06a40-06ea-472b-9f8f-f4daf6468c52",
@ -138,7 +138,7 @@
{ {
"id": "a2fc744f-930d-43e0-b5cf-824a5928c7f1", "id": "a2fc744f-930d-43e0-b5cf-824a5928c7f1",
"name": "是否识别", "name": "是否识别",
"field": "extract" "field": "recognition_enable"
} }
], ],
"passThrough": true, "passThrough": true,
@ -149,8 +149,8 @@
"id": "a1146fe1-b0dd-4efd-b0b7-11e000bc569f", "id": "a1146fe1-b0dd-4efd-b0b7-11e000bc569f",
"name": "decisionTable", "name": "decisionTable",
"position": { "position": {
"x": 495, "x": 430,
"y": 170 "y": 114
} }
} }
], ],