From 5004b4021678aea04b1c54745b197f51e2fb1390 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Tue, 11 Jun 2024 13:10:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ie=E7=9A=84=E5=A3=B0=E6=98=8E?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E5=8F=8D=E5=A4=8D=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_review/__init__.py | 23 +++++++++++ photo_review/photo_review.py | 79 ++++++++++++------------------------ 2 files changed, 49 insertions(+), 53 deletions(-) diff --git a/photo_review/__init__.py b/photo_review/__init__.py index e69de29..1f3b3e0 100644 --- a/photo_review/__init__.py +++ b/photo_review/__init__.py @@ -0,0 +1,23 @@ +from paddlenlp import Taskflow + +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.photo_review import IE_BATCH_SIZE + +# 基本医保结算单 +settlement_list_schema = \ + PATIENT_NAME + ADMISSION_DATE + DISCHARGE_DATE + MEDICAL_EXPENSES + PERSONAL_CASH_PAYMENT \ + + PERSONAL_ACCOUNT_PAYMENT + PERSONAL_FUNDED_AMOUNT + MEDICAL_INSURANCE_TYPE +settlement_ie = Taskflow("information_extraction", schema=settlement_list_schema, model="uie-x-base", + task_path="config/model/settlement_list_model", layout_analysis=True, batch_size=IE_BATCH_SIZE) + +# 出院记录 +discharge_record_schema = \ + HOSPITAL + DEPARTMENT + PATIENT_NAME + ADMISSION_DATE + DISCHARGE_DATE + DOCTOR +discharge_ie = Taskflow("information_extraction", schema=discharge_record_schema, model="uie-x-base", + task_path="config/model/discharge_record_model", layout_analysis=True, batch_size=IE_BATCH_SIZE) + +# 费用清单 +cost_list_schema = PATIENT_NAME + ADMISSION_DATE + DISCHARGE_DATE + MEDICAL_EXPENSES +cost_ie = Taskflow("information_extraction", schema=cost_list_schema, model="uie-x-base", + task_path="config/model/cost_list_model", layout_analysis=True, batch_size=IE_BATCH_SIZE) diff --git a/photo_review/photo_review.py b/photo_review/photo_review.py index a2710ba..955e6c9 100644 --- a/photo_review/photo_review.py +++ b/photo_review/photo_review.py @@ -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"])