优化ie的声明,避免反复创建
This commit is contained in:
@@ -2,13 +2,13 @@ import json
|
||||
import logging
|
||||
from time import sleep
|
||||
|
||||
from paddlenlp import Taskflow
|
||||
from sqlalchemy import update
|
||||
|
||||
from config.keys import PATIENT_NAME, ADMISSION_DATE, DISCHARGE_DATE, MEDICAL_EXPENSES, PERSONAL_CASH_PAYMENT, \
|
||||
PERSONAL_ACCOUNT_PAYMENT, PERSONAL_FUNDED_AMOUNT, MEDICAL_INSURANCE_TYPE, HOSPITAL, DEPARTMENT, DOCTOR
|
||||
from config.mysql import MysqlSession
|
||||
from config.photo_review import PHHD_BATCH_SIZE, SLEEP_MINUTES, IE_BATCH_SIZE
|
||||
from config.photo_review import PHHD_BATCH_SIZE, SLEEP_MINUTES
|
||||
from photo_review import settlement_ie, discharge_ie, cost_ie
|
||||
from photo_review.entity.bd_yljg import BdYljg
|
||||
from photo_review.entity.bd_ylks import BdYlks
|
||||
from photo_review.entity.zx_ie_cost import ZxIeCost
|
||||
@@ -23,7 +23,7 @@ from photo_review.util.util import get_default_datetime
|
||||
|
||||
|
||||
# 关键信息提取
|
||||
def information_extraction(schema, phrecs, task_path):
|
||||
def information_extraction(ie, phrecs):
|
||||
result = {}
|
||||
docs = []
|
||||
doc_phrecs = []
|
||||
@@ -32,9 +32,6 @@ def information_extraction(schema, phrecs, task_path):
|
||||
if pic_path:
|
||||
docs.append({"doc": pic_path})
|
||||
doc_phrecs.append(phrec)
|
||||
|
||||
ie = Taskflow("information_extraction", schema=schema, model="uie-x-base", task_path=task_path,
|
||||
layout_analysis=True, batch_size=IE_BATCH_SIZE)
|
||||
ie_results = ie(docs)
|
||||
|
||||
now = get_default_datetime()
|
||||
@@ -123,40 +120,17 @@ def photo_review(pk_phhd):
|
||||
elif phrec.cRectype == "4":
|
||||
cost_list.append(phrec)
|
||||
|
||||
name_key = PATIENT_NAME
|
||||
admission_date_key = ADMISSION_DATE
|
||||
discharge_date_key = DISCHARGE_DATE
|
||||
medical_expenses_key = MEDICAL_EXPENSES
|
||||
personal_cash_payment_key = PERSONAL_CASH_PAYMENT
|
||||
personal_account_payment_key = PERSONAL_ACCOUNT_PAYMENT
|
||||
personal_funded_amount_key = PERSONAL_FUNDED_AMOUNT
|
||||
medical_insurance_type_key = MEDICAL_INSURANCE_TYPE
|
||||
hospital_key = HOSPITAL
|
||||
department_key = DEPARTMENT
|
||||
doctor_key = DOCTOR
|
||||
|
||||
# 基本医保结算单
|
||||
settlement_list_schema = \
|
||||
name_key + admission_date_key + discharge_date_key + medical_expenses_key + personal_cash_payment_key \
|
||||
+ personal_account_payment_key + personal_funded_amount_key + medical_insurance_type_key
|
||||
# 出院记录
|
||||
discharge_record_schema = \
|
||||
hospital_key + department_key + name_key + admission_date_key + discharge_date_key + doctor_key
|
||||
# 费用清单
|
||||
cost_list_schema = name_key + admission_date_key + discharge_date_key + medical_expenses_key
|
||||
|
||||
settlement_list_ie_result = information_extraction(settlement_list_schema, settlement_list,
|
||||
"config/model/settlement_list_model")
|
||||
settlement_list_ie_result = information_extraction(settlement_ie, settlement_list)
|
||||
settlement_data = {
|
||||
"pk_phhd": pk_phhd,
|
||||
"name": handle_name(get_best_value_in_keys(settlement_list_ie_result, name_key)),
|
||||
"admission_date_str": get_best_value_in_keys(settlement_list_ie_result, admission_date_key),
|
||||
"discharge_date_str": get_best_value_in_keys(settlement_list_ie_result, discharge_date_key),
|
||||
"medical_expenses_str": get_best_value_in_keys(settlement_list_ie_result, medical_expenses_key),
|
||||
"personal_cash_payment_str": get_best_value_in_keys(settlement_list_ie_result, personal_cash_payment_key),
|
||||
"personal_account_payment_str": get_best_value_in_keys(settlement_list_ie_result, personal_account_payment_key),
|
||||
"personal_funded_amount_str": get_best_value_in_keys(settlement_list_ie_result, personal_funded_amount_key),
|
||||
"medical_insurance_type": get_best_value_in_keys(settlement_list_ie_result, medical_insurance_type_key)
|
||||
"name": handle_name(get_best_value_in_keys(settlement_list_ie_result, PATIENT_NAME)),
|
||||
"admission_date_str": get_best_value_in_keys(settlement_list_ie_result, ADMISSION_DATE),
|
||||
"discharge_date_str": get_best_value_in_keys(settlement_list_ie_result, DISCHARGE_DATE),
|
||||
"medical_expenses_str": get_best_value_in_keys(settlement_list_ie_result, MEDICAL_EXPENSES),
|
||||
"personal_cash_payment_str": get_best_value_in_keys(settlement_list_ie_result, PERSONAL_CASH_PAYMENT),
|
||||
"personal_account_payment_str": get_best_value_in_keys(settlement_list_ie_result, PERSONAL_ACCOUNT_PAYMENT),
|
||||
"personal_funded_amount_str": get_best_value_in_keys(settlement_list_ie_result, PERSONAL_FUNDED_AMOUNT),
|
||||
"medical_insurance_type": get_best_value_in_keys(settlement_list_ie_result, MEDICAL_INSURANCE_TYPE)
|
||||
}
|
||||
settlement_data["admission_date"] = handle_date(settlement_data["admission_date_str"])
|
||||
settlement_data["admission_date"] = handle_date(settlement_data["admission_date_str"])
|
||||
@@ -167,20 +141,19 @@ def photo_review(pk_phhd):
|
||||
settlement_data["personal_funded_amount"] = handle_decimal(settlement_data["personal_funded_amount_str"])
|
||||
save_or_update_ie(ZxIeSettlement, pk_phhd, settlement_data)
|
||||
|
||||
discharge_record_ie_result = information_extraction(discharge_record_schema, discharge_record,
|
||||
"config/model/discharge_record_model")
|
||||
discharge_record_ie_result = information_extraction(discharge_ie, discharge_record)
|
||||
discharge_data = {
|
||||
"pk_phhd": pk_phhd,
|
||||
"hospital": get_best_value_in_keys(discharge_record_ie_result, hospital_key),
|
||||
"department": get_best_value_in_keys(discharge_record_ie_result, department_key),
|
||||
"name": handle_name(get_best_value_in_keys(discharge_record_ie_result, name_key)),
|
||||
"admission_date_str": get_best_value_in_keys(discharge_record_ie_result, admission_date_key),
|
||||
"discharge_date_str": get_best_value_in_keys(discharge_record_ie_result, discharge_date_key),
|
||||
"doctor": handle_name(get_best_value_in_keys(discharge_record_ie_result, doctor_key))
|
||||
"hospital": get_best_value_in_keys(discharge_record_ie_result, HOSPITAL),
|
||||
"department": get_best_value_in_keys(discharge_record_ie_result, DEPARTMENT),
|
||||
"name": handle_name(get_best_value_in_keys(discharge_record_ie_result, PATIENT_NAME)),
|
||||
"admission_date_str": get_best_value_in_keys(discharge_record_ie_result, ADMISSION_DATE),
|
||||
"discharge_date_str": get_best_value_in_keys(discharge_record_ie_result, DISCHARGE_DATE),
|
||||
"doctor": handle_name(get_best_value_in_keys(discharge_record_ie_result, DOCTOR))
|
||||
}
|
||||
discharge_data["admission_date"] = handle_date(discharge_data["admission_date_str"])
|
||||
discharge_data["discharge_date"] = handle_date(discharge_data["discharge_date_str"])
|
||||
hospital_value = get_values_of_keys(discharge_record_ie_result, hospital_key)
|
||||
hospital_value = get_values_of_keys(discharge_record_ie_result, HOSPITAL)
|
||||
if hospital_value:
|
||||
session = MysqlSession()
|
||||
yljg = session.query(BdYljg.pk_yljg, BdYljg.name) \
|
||||
@@ -189,7 +162,7 @@ def photo_review(pk_phhd):
|
||||
if yljg:
|
||||
discharge_data["pk_yljg"] = yljg.pk_yljg
|
||||
discharge_data["hospital"] = yljg.name
|
||||
department_value = get_values_of_keys(discharge_record_ie_result, department_key)
|
||||
department_value = get_values_of_keys(discharge_record_ie_result, DEPARTMENT)
|
||||
if department_value:
|
||||
department_values = []
|
||||
for dept in department_value:
|
||||
@@ -205,13 +178,13 @@ def photo_review(pk_phhd):
|
||||
discharge_data["department"] = ylks.name
|
||||
save_or_update_ie(ZxIeDischarge, pk_phhd, discharge_data)
|
||||
|
||||
cost_list_ie_result = information_extraction(cost_list_schema, cost_list, "config/model/cost_list_model")
|
||||
cost_list_ie_result = information_extraction(cost_ie, cost_list)
|
||||
cost_data = {
|
||||
"pk_phhd": pk_phhd,
|
||||
"name": handle_name(get_best_value_in_keys(cost_list_ie_result, name_key)),
|
||||
"admission_date_str": get_best_value_in_keys(cost_list_ie_result, admission_date_key),
|
||||
"discharge_date_str": get_best_value_in_keys(cost_list_ie_result, discharge_date_key),
|
||||
"medical_expenses_str": get_best_value_in_keys(cost_list_ie_result, medical_expenses_key)
|
||||
"name": handle_name(get_best_value_in_keys(cost_list_ie_result, PATIENT_NAME)),
|
||||
"admission_date_str": get_best_value_in_keys(cost_list_ie_result, ADMISSION_DATE),
|
||||
"discharge_date_str": get_best_value_in_keys(cost_list_ie_result, DISCHARGE_DATE),
|
||||
"medical_expenses_str": get_best_value_in_keys(cost_list_ie_result, MEDICAL_EXPENSES)
|
||||
}
|
||||
cost_data["admission_date"] = handle_date(cost_data["admission_date_str"])
|
||||
cost_data["discharge_date"] = handle_date(cost_data["discharge_date_str"])
|
||||
|
||||
Reference in New Issue
Block a user