From 14a0cbeb0bbd1b27eff2818dd9951bcdbae152db Mon Sep 17 00:00:00 2001 From: well Date: Sat, 2 Nov 2024 13:18:16 +0800 Subject: [PATCH 01/62] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B2=20?= =?UTF-8?q?upload=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/forms100.py | 241 ++++++++++++++++++++++++++++++++++++- 1 file changed, 240 insertions(+), 1 deletion(-) diff --git a/api/parse_file/forms100.py b/api/parse_file/forms100.py index 4f8af6461d..8453e193cf 100644 --- a/api/parse_file/forms100.py +++ b/api/parse_file/forms100.py @@ -1,11 +1,17 @@ import base64 +import datetime import json import requests +from django.http import HttpRequest from openpyxl.reader.excel import load_workbook -from contracts.models import PriceName, PriceCoast +from api.models import Application +from api.patients.views import patients_search_card +from clients.models import Card, Individual, HarmfulFactor, PatientHarmfullFactor, CardBase +from contracts.models import PriceName, PriceCoast, Company, CompanyDepartment, MedicalExamination from directory.models import Researches +from integration_framework.views import check_enp from laboratory.settings import RMIS_MIDDLE_SERVER_ADDRESS, RMIS_MIDDLE_SERVER_TOKEN @@ -137,3 +143,236 @@ def form_02(request_data): result = response.json() return {"ok": True, "result": [], "message": f"{result}"} + + +def get_background_token(): + application = Application.objects.filter(active=True, is_background_worker=True).first() + if application: + bearer_token = f"Bearer {application.key}" + else: + new_application = Application(name="background_worker", is_background_worker=True) + new_application.save() + bearer_token = f"Bearer {new_application.key}" + return bearer_token + + +def search_by_fio(request_obj, family, name, patronymic, birthday): + patient_card = None + params_tfoms = { + "enp": "", + "family": family, + "name": name, + "bd": birthday, + "check_mode": "l2-enp-full", + } + params_internal = { + "type": CardBase.objects.get(internal_type=True).pk, + "extendedSearch": True, + "form": { + "family": family, + "name": name, + "patronymic": patronymic, + "birthday": birthday, + "archive": False, + }, + "limit": 1, + } + request_obj._body = params_tfoms + current_patient = check_enp(request_obj) + if current_patient.data.get("message"): + request_obj._body = json.dumps(params_internal) + data = patients_search_card(request_obj) + results_json = json.loads(data.content.decode("utf-8")) + if len(results_json["results"]) > 0: + patient_card_pk = results_json["results"][0]["pk"] + patient_card = Card.objects.filter(pk=patient_card_pk).first() + elif len(current_patient.data["list"]) > 1: + return patient_card + else: + patient_card = Individual.import_from_tfoms(current_patient.data["list"], None, None, None, True) + return patient_card + + +def find_and_replace(text, symbol1, symbol2): + result = [] + for i in range(len(text)): + if text[i] == symbol1: + current_text = text[0:i] + symbol2 + text[i + 1:] + result.append(current_text) + elif text[i] == symbol2: + current_text = text[0:i] + symbol1 + text[i + 1:] + result.append(current_text) + return result + + +def search_by_possible_fio(request_obj, name, patronymic, birthday, possible_family): + if not possible_family: + return None + patient_card = None + for i in possible_family: + current_family = i + patient_card = search_by_fio(request_obj, current_family, name, patronymic, birthday) + if patient_card is not None: + break + return patient_card + + +def search_patient(snils_data, request_user, family_data, name_data, patronymic_data, birthday_data): + patient_card = None + bearer_token = get_background_token() + params = {"enp": "", "snils": snils_data, "check_mode": "l2-snils"} + request_obj = HttpRequest() + request_obj._body = params + request_obj.user = request_user + request_obj.method = "POST" + request_obj.META["HTTP_AUTHORIZATION"] = bearer_token + current_patient = None + if snils_data and snils_data != "None": + current_patient = check_enp(request_obj) + if not current_patient or current_patient.data.get("message"): + patient_card = search_by_fio(request_obj, family_data, name_data, patronymic_data, birthday_data) + if patient_card is None: + possible_family = find_and_replace(family_data, "е", "ё") + patient_card = search_by_possible_fio(request_obj, name_data, patronymic_data, birthday_data, possible_family) + if patient_card is None: + return patient_card + elif current_patient.data.get("patient_data") and type(current_patient.data.get("patient_data")) != list: + patient_card_pk = current_patient.data["patient_data"]["card"] + patient_card = Card.objects.filter(pk=patient_card_pk).first() + else: + patient_card = Individual.import_from_tfoms(current_patient.data["patient_data"], None, None, None, True) + + return patient_card + + +def create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data): + patient_indv = Individual( + family=family_data, + name=name_data, + patronymic=patronymic_data, + birthday=birthday_data, + sex=gender_data, + ) + patient_indv.save() + patient_card = Card.add_l2_card(individual=patient_indv) + return patient_card + + +def find_factors(harmful_factors: list): + if not harmful_factors: + return None + incorrect_factor = [] + harmful_factors_data = [] + for i in harmful_factors: + current_code = i.replace(" ", "") + harmful_factor = HarmfulFactor.objects.filter(title=current_code).first() + if harmful_factor: + harmful_factors_data.append({"factorId": harmful_factor.pk}) + else: + incorrect_factor.append(f"{current_code}") + + return harmful_factors_data, incorrect_factor + + +def add_factors_data(patient_card: Card, position: str, factors_data: list, exam_data: str, company_inn: str, department: str): + try: + PatientHarmfullFactor.save_card_harmful_factor(patient_card.pk, factors_data) + company_obj = Company.objects.filter(inn=company_inn).first() + department_obj = CompanyDepartment.objects.filter(company_id=company_obj.pk, title=department).first() + if department_obj: + patient_card.work_department_db_id = department_obj.pk + else: + new_department = CompanyDepartment.save_department(company_obj.pk, department) + patient_card.work_department_db_id = new_department.pk + patient_card.work_position = position.strip() + patient_card.work_place_db = company_obj + patient_card.save() + MedicalExamination.save_examination(patient_card, company_obj, exam_data) + return {"ok": True} + except Exception as e: + return {"ok": False, "message": e} + + +def form_03(request_data): + """ + Загрузка списка на мед. осмотр + + На входе: + Файл XLSX с ФИО и датами осмотра. + Структура: + снилс(snils), фио(fio), дата рождения(birthday), пол(gender), инн организации(inn_company), код вредности(code_harmful) + должность(position), дата мед. осмотра(examination_date), подразделение(department) + + """ + price_id = request_data.get("entity_id") + file = request_data.get("file") + price = PriceName.objects.filter(pk=price_id).first() + if not price: + return {"ok": False, "result": [], "message": "Такого прайса нет"} + wb = load_workbook(filename=file) + ws = wb[wb.sheetnames[0]] + starts = False + incorrect_patients = [] + company_inn = request.POST.get("companyInn", None) + snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date, department = ( + None, + None, + None, + None, + None, + None, + None, + None, + None, + ) + for index, row in enumerate(ws.rows, 1): + cells = [str(x.value) for x in row] + if not starts: + if "код вредности" in cells: + snils = cells.index("снилс") + fio = cells.index("фио") + birthday = cells.index("дата рождения") + gender = cells.index("пол") + inn_company = cells.index("инн организации") + code_harmful = cells.index("код вредности") + position = cells.index("должность") + examination_date = cells.index("дата мед. осмотра") + department = cells.index("подразделение") + starts = True + else: + if company_inn != cells[inn_company].strip(): + incorrect_patients.append({"fio": cells[fio], "reason": "ИНН организации не совпадает"}) + continue + snils_data = cells[snils].replace("-", "").replace(" ", "") + fio_data, family_data, name_data, patronymic_data = None, None, None, None + if cells[fio] and cells[fio] != "None": + fio_data = cells[fio].split(" ") + family_data = fio_data[0] + name_data = fio_data[1] + if len(fio_data) > 2: + patronymic_data = fio_data[2] + birthday_data = cells[birthday].split(" ")[0] + code_harmful_data = cells[code_harmful].split(",") + exam_data = cells[examination_date].split(" ")[0] + try: + datetime.datetime.strptime(birthday_data, '%Y-%m-%d') + datetime.datetime.strptime(exam_data, '%Y-%m-%d') + except ValueError as e: + incorrect_patients.append({"fio": cells[fio], "reason": f"Неверный формат даты/несуществующая дата в файле: {e}"}) + continue + gender_data = cells[gender][0] + department_data = cells[department] + if fio_data is None and snils_data is None: + incorrect_patients.append({"fio": f"Строка: {index}", "reason": "Отсутствует данные"}) + continue + patient_card = search_patient(snils_data, request.user, family_data, name_data, patronymic_data, birthday_data) + if patient_card is None: + patient_card = create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data) + harmful_factors_data, incorrect_factor = find_factors(code_harmful_data) + if incorrect_factor: + incorrect_patients.append({"fio": cells[fio], "reason": f"Неверные факторы: {incorrect_factor}"}) + patient_updated = add_factors_data(patient_card, cells[position], harmful_factors_data, exam_data, company_inn, department_data) + if not patient_updated["ok"]: + incorrect_patients.append({"fio": cells[fio], "reason": f"Сохранение не удалось, ошибка: {patient_updated['message']}"}) + + return {"ok": True, "result": incorrect_patients, "message": ""} From 7c8966217f9ecb317be35a00e88f58f1713a61a4 Mon Sep 17 00:00:00 2001 From: well Date: Sun, 3 Nov 2024 16:06:02 +0800 Subject: [PATCH 02/62] / --- api/parse_file/forms100.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api/parse_file/forms100.py b/api/parse_file/forms100.py index 8453e193cf..9a5c37563a 100644 --- a/api/parse_file/forms100.py +++ b/api/parse_file/forms100.py @@ -304,11 +304,7 @@ def form_03(request_data): должность(position), дата мед. осмотра(examination_date), подразделение(department) """ - price_id = request_data.get("entity_id") file = request_data.get("file") - price = PriceName.objects.filter(pk=price_id).first() - if not price: - return {"ok": False, "result": [], "message": "Такого прайса нет"} wb = load_workbook(filename=file) ws = wb[wb.sheetnames[0]] starts = False From 686eb450114e8b8068965dc002ed035e08aac45f Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:06:29 +0800 Subject: [PATCH 03/62] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/forms100.py | 238 +----------------------------------- api/parse_file/forms101.py | 241 +++++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+), 237 deletions(-) create mode 100644 api/parse_file/forms101.py diff --git a/api/parse_file/forms100.py b/api/parse_file/forms100.py index 9a5c37563a..a7d5481eaf 100644 --- a/api/parse_file/forms100.py +++ b/api/parse_file/forms100.py @@ -1,17 +1,10 @@ import base64 -import datetime import json import requests -from django.http import HttpRequest from openpyxl.reader.excel import load_workbook - -from api.models import Application -from api.patients.views import patients_search_card -from clients.models import Card, Individual, HarmfulFactor, PatientHarmfullFactor, CardBase -from contracts.models import PriceName, PriceCoast, Company, CompanyDepartment, MedicalExamination +from contracts.models import PriceName, PriceCoast from directory.models import Researches -from integration_framework.views import check_enp from laboratory.settings import RMIS_MIDDLE_SERVER_ADDRESS, RMIS_MIDDLE_SERVER_TOKEN @@ -143,232 +136,3 @@ def form_02(request_data): result = response.json() return {"ok": True, "result": [], "message": f"{result}"} - - -def get_background_token(): - application = Application.objects.filter(active=True, is_background_worker=True).first() - if application: - bearer_token = f"Bearer {application.key}" - else: - new_application = Application(name="background_worker", is_background_worker=True) - new_application.save() - bearer_token = f"Bearer {new_application.key}" - return bearer_token - - -def search_by_fio(request_obj, family, name, patronymic, birthday): - patient_card = None - params_tfoms = { - "enp": "", - "family": family, - "name": name, - "bd": birthday, - "check_mode": "l2-enp-full", - } - params_internal = { - "type": CardBase.objects.get(internal_type=True).pk, - "extendedSearch": True, - "form": { - "family": family, - "name": name, - "patronymic": patronymic, - "birthday": birthday, - "archive": False, - }, - "limit": 1, - } - request_obj._body = params_tfoms - current_patient = check_enp(request_obj) - if current_patient.data.get("message"): - request_obj._body = json.dumps(params_internal) - data = patients_search_card(request_obj) - results_json = json.loads(data.content.decode("utf-8")) - if len(results_json["results"]) > 0: - patient_card_pk = results_json["results"][0]["pk"] - patient_card = Card.objects.filter(pk=patient_card_pk).first() - elif len(current_patient.data["list"]) > 1: - return patient_card - else: - patient_card = Individual.import_from_tfoms(current_patient.data["list"], None, None, None, True) - return patient_card - - -def find_and_replace(text, symbol1, symbol2): - result = [] - for i in range(len(text)): - if text[i] == symbol1: - current_text = text[0:i] + symbol2 + text[i + 1:] - result.append(current_text) - elif text[i] == symbol2: - current_text = text[0:i] + symbol1 + text[i + 1:] - result.append(current_text) - return result - - -def search_by_possible_fio(request_obj, name, patronymic, birthday, possible_family): - if not possible_family: - return None - patient_card = None - for i in possible_family: - current_family = i - patient_card = search_by_fio(request_obj, current_family, name, patronymic, birthday) - if patient_card is not None: - break - return patient_card - - -def search_patient(snils_data, request_user, family_data, name_data, patronymic_data, birthday_data): - patient_card = None - bearer_token = get_background_token() - params = {"enp": "", "snils": snils_data, "check_mode": "l2-snils"} - request_obj = HttpRequest() - request_obj._body = params - request_obj.user = request_user - request_obj.method = "POST" - request_obj.META["HTTP_AUTHORIZATION"] = bearer_token - current_patient = None - if snils_data and snils_data != "None": - current_patient = check_enp(request_obj) - if not current_patient or current_patient.data.get("message"): - patient_card = search_by_fio(request_obj, family_data, name_data, patronymic_data, birthday_data) - if patient_card is None: - possible_family = find_and_replace(family_data, "е", "ё") - patient_card = search_by_possible_fio(request_obj, name_data, patronymic_data, birthday_data, possible_family) - if patient_card is None: - return patient_card - elif current_patient.data.get("patient_data") and type(current_patient.data.get("patient_data")) != list: - patient_card_pk = current_patient.data["patient_data"]["card"] - patient_card = Card.objects.filter(pk=patient_card_pk).first() - else: - patient_card = Individual.import_from_tfoms(current_patient.data["patient_data"], None, None, None, True) - - return patient_card - - -def create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data): - patient_indv = Individual( - family=family_data, - name=name_data, - patronymic=patronymic_data, - birthday=birthday_data, - sex=gender_data, - ) - patient_indv.save() - patient_card = Card.add_l2_card(individual=patient_indv) - return patient_card - - -def find_factors(harmful_factors: list): - if not harmful_factors: - return None - incorrect_factor = [] - harmful_factors_data = [] - for i in harmful_factors: - current_code = i.replace(" ", "") - harmful_factor = HarmfulFactor.objects.filter(title=current_code).first() - if harmful_factor: - harmful_factors_data.append({"factorId": harmful_factor.pk}) - else: - incorrect_factor.append(f"{current_code}") - - return harmful_factors_data, incorrect_factor - - -def add_factors_data(patient_card: Card, position: str, factors_data: list, exam_data: str, company_inn: str, department: str): - try: - PatientHarmfullFactor.save_card_harmful_factor(patient_card.pk, factors_data) - company_obj = Company.objects.filter(inn=company_inn).first() - department_obj = CompanyDepartment.objects.filter(company_id=company_obj.pk, title=department).first() - if department_obj: - patient_card.work_department_db_id = department_obj.pk - else: - new_department = CompanyDepartment.save_department(company_obj.pk, department) - patient_card.work_department_db_id = new_department.pk - patient_card.work_position = position.strip() - patient_card.work_place_db = company_obj - patient_card.save() - MedicalExamination.save_examination(patient_card, company_obj, exam_data) - return {"ok": True} - except Exception as e: - return {"ok": False, "message": e} - - -def form_03(request_data): - """ - Загрузка списка на мед. осмотр - - На входе: - Файл XLSX с ФИО и датами осмотра. - Структура: - снилс(snils), фио(fio), дата рождения(birthday), пол(gender), инн организации(inn_company), код вредности(code_harmful) - должность(position), дата мед. осмотра(examination_date), подразделение(department) - - """ - file = request_data.get("file") - wb = load_workbook(filename=file) - ws = wb[wb.sheetnames[0]] - starts = False - incorrect_patients = [] - company_inn = request.POST.get("companyInn", None) - snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date, department = ( - None, - None, - None, - None, - None, - None, - None, - None, - None, - ) - for index, row in enumerate(ws.rows, 1): - cells = [str(x.value) for x in row] - if not starts: - if "код вредности" in cells: - snils = cells.index("снилс") - fio = cells.index("фио") - birthday = cells.index("дата рождения") - gender = cells.index("пол") - inn_company = cells.index("инн организации") - code_harmful = cells.index("код вредности") - position = cells.index("должность") - examination_date = cells.index("дата мед. осмотра") - department = cells.index("подразделение") - starts = True - else: - if company_inn != cells[inn_company].strip(): - incorrect_patients.append({"fio": cells[fio], "reason": "ИНН организации не совпадает"}) - continue - snils_data = cells[snils].replace("-", "").replace(" ", "") - fio_data, family_data, name_data, patronymic_data = None, None, None, None - if cells[fio] and cells[fio] != "None": - fio_data = cells[fio].split(" ") - family_data = fio_data[0] - name_data = fio_data[1] - if len(fio_data) > 2: - patronymic_data = fio_data[2] - birthday_data = cells[birthday].split(" ")[0] - code_harmful_data = cells[code_harmful].split(",") - exam_data = cells[examination_date].split(" ")[0] - try: - datetime.datetime.strptime(birthday_data, '%Y-%m-%d') - datetime.datetime.strptime(exam_data, '%Y-%m-%d') - except ValueError as e: - incorrect_patients.append({"fio": cells[fio], "reason": f"Неверный формат даты/несуществующая дата в файле: {e}"}) - continue - gender_data = cells[gender][0] - department_data = cells[department] - if fio_data is None and snils_data is None: - incorrect_patients.append({"fio": f"Строка: {index}", "reason": "Отсутствует данные"}) - continue - patient_card = search_patient(snils_data, request.user, family_data, name_data, patronymic_data, birthday_data) - if patient_card is None: - patient_card = create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data) - harmful_factors_data, incorrect_factor = find_factors(code_harmful_data) - if incorrect_factor: - incorrect_patients.append({"fio": cells[fio], "reason": f"Неверные факторы: {incorrect_factor}"}) - patient_updated = add_factors_data(patient_card, cells[position], harmful_factors_data, exam_data, company_inn, department_data) - if not patient_updated["ok"]: - incorrect_patients.append({"fio": cells[fio], "reason": f"Сохранение не удалось, ошибка: {patient_updated['message']}"}) - - return {"ok": True, "result": incorrect_patients, "message": ""} diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py new file mode 100644 index 0000000000..9c5f2239ca --- /dev/null +++ b/api/parse_file/forms101.py @@ -0,0 +1,241 @@ +import datetime +import json + +from django.http import HttpRequest +from openpyxl.reader.excel import load_workbook + +from api.models import Application +from api.patients.views import patients_search_card +from clients.models import Card, Individual, HarmfulFactor, PatientHarmfullFactor, CardBase +from contracts.models import Company, CompanyDepartment, MedicalExamination +from integration_framework.views import check_enp + + + +def get_background_token(): + application = Application.objects.filter(active=True, is_background_worker=True).first() + if application: + bearer_token = f"Bearer {application.key}" + else: + new_application = Application(name="background_worker", is_background_worker=True) + new_application.save() + bearer_token = f"Bearer {new_application.key}" + return bearer_token + + +def search_by_fio(request_obj, family, name, patronymic, birthday): + patient_card = None + params_tfoms = { + "enp": "", + "family": family, + "name": name, + "bd": birthday, + "check_mode": "l2-enp-full", + } + params_internal = { + "type": CardBase.objects.get(internal_type=True).pk, + "extendedSearch": True, + "form": { + "family": family, + "name": name, + "patronymic": patronymic, + "birthday": birthday, + "archive": False, + }, + "limit": 1, + } + request_obj._body = params_tfoms + current_patient = check_enp(request_obj) + if current_patient.data.get("message"): + request_obj._body = json.dumps(params_internal) + data = patients_search_card(request_obj) + results_json = json.loads(data.content.decode("utf-8")) + if len(results_json["results"]) > 0: + patient_card_pk = results_json["results"][0]["pk"] + patient_card = Card.objects.filter(pk=patient_card_pk).first() + elif len(current_patient.data["list"]) > 1: + return patient_card + else: + patient_card = Individual.import_from_tfoms(current_patient.data["list"], None, None, None, True) + return patient_card + + +def find_and_replace(text, symbol1, symbol2): + result = [] + for i in range(len(text)): + if text[i] == symbol1: + current_text = text[0:i] + symbol2 + text[i + 1:] + result.append(current_text) + elif text[i] == symbol2: + current_text = text[0:i] + symbol1 + text[i + 1:] + result.append(current_text) + return result + + +def search_by_possible_fio(request_obj, name, patronymic, birthday, possible_family): + if not possible_family: + return None + patient_card = None + for i in possible_family: + current_family = i + patient_card = search_by_fio(request_obj, current_family, name, patronymic, birthday) + if patient_card is not None: + break + return patient_card + + +def search_patient(snils_data, request_user, family_data, name_data, patronymic_data, birthday_data): + patient_card = None + bearer_token = get_background_token() + params = {"enp": "", "snils": snils_data, "check_mode": "l2-snils"} + request_obj = HttpRequest() + request_obj._body = params + request_obj.user = request_user + request_obj.method = "POST" + request_obj.META["HTTP_AUTHORIZATION"] = bearer_token + current_patient = None + if snils_data and snils_data != "None": + current_patient = check_enp(request_obj) + if not current_patient or current_patient.data.get("message"): + patient_card = search_by_fio(request_obj, family_data, name_data, patronymic_data, birthday_data) + if patient_card is None: + possible_family = find_and_replace(family_data, "е", "ё") + patient_card = search_by_possible_fio(request_obj, name_data, patronymic_data, birthday_data, possible_family) + if patient_card is None: + return patient_card + elif current_patient.data.get("patient_data") and type(current_patient.data.get("patient_data")) != list: + patient_card_pk = current_patient.data["patient_data"]["card"] + patient_card = Card.objects.filter(pk=patient_card_pk).first() + else: + patient_card = Individual.import_from_tfoms(current_patient.data["patient_data"], None, None, None, True) + + return patient_card + + +def create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data): + patient_indv = Individual( + family=family_data, + name=name_data, + patronymic=patronymic_data, + birthday=birthday_data, + sex=gender_data, + ) + patient_indv.save() + patient_card = Card.add_l2_card(individual=patient_indv) + return patient_card + + +def find_factors(harmful_factors: list): + if not harmful_factors: + return None + incorrect_factor = [] + harmful_factors_data = [] + for i in harmful_factors: + current_code = i.replace(" ", "") + harmful_factor = HarmfulFactor.objects.filter(title=current_code).first() + if harmful_factor: + harmful_factors_data.append({"factorId": harmful_factor.pk}) + else: + incorrect_factor.append(f"{current_code}") + + return harmful_factors_data, incorrect_factor + + +def add_factors_data(patient_card: Card, position: str, factors_data: list, exam_data: str, company_inn: str, department: str): + try: + PatientHarmfullFactor.save_card_harmful_factor(patient_card.pk, factors_data) + company_obj = Company.objects.filter(inn=company_inn).first() + department_obj = CompanyDepartment.objects.filter(company_id=company_obj.pk, title=department).first() + if department_obj: + patient_card.work_department_db_id = department_obj.pk + else: + new_department = CompanyDepartment.save_department(company_obj.pk, department) + patient_card.work_department_db_id = new_department.pk + patient_card.work_position = position.strip() + patient_card.work_place_db = company_obj + patient_card.save() + MedicalExamination.save_examination(patient_card, company_obj, exam_data) + return {"ok": True} + except Exception as e: + return {"ok": False, "message": e} + + +def form_03(request_data): + """ + Загрузка списка на мед. осмотр + + На входе: + Файл XLSX с ФИО и датами осмотра. + Структура: + снилс(snils), фио(fio), дата рождения(birthday), пол(gender), инн организации(inn_company), код вредности(code_harmful) + должность(position), дата мед. осмотра(examination_date), подразделение(department) + + """ + file = request_data.get("file") + wb = load_workbook(filename=file) + ws = wb[wb.sheetnames[0]] + starts = False + incorrect_patients = [] + company_inn = request.POST.get("companyInn", None) + snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date, department = ( + None, + None, + None, + None, + None, + None, + None, + None, + None, + ) + for index, row in enumerate(ws.rows, 1): + cells = [str(x.value) for x in row] + if not starts: + if "код вредности" in cells: + snils = cells.index("снилс") + fio = cells.index("фио") + birthday = cells.index("дата рождения") + gender = cells.index("пол") + inn_company = cells.index("инн организации") + code_harmful = cells.index("код вредности") + position = cells.index("должность") + examination_date = cells.index("дата мед. осмотра") + department = cells.index("подразделение") + starts = True + else: + if company_inn != cells[inn_company].strip(): + incorrect_patients.append({"fio": cells[fio], "reason": "ИНН организации не совпадает"}) + continue + snils_data = cells[snils].replace("-", "").replace(" ", "") + fio_data, family_data, name_data, patronymic_data = None, None, None, None + if cells[fio] and cells[fio] != "None": + fio_data = cells[fio].split(" ") + family_data = fio_data[0] + name_data = fio_data[1] + if len(fio_data) > 2: + patronymic_data = fio_data[2] + birthday_data = cells[birthday].split(" ")[0] + code_harmful_data = cells[code_harmful].split(",") + exam_data = cells[examination_date].split(" ")[0] + try: + datetime.datetime.strptime(birthday_data, '%Y-%m-%d') + datetime.datetime.strptime(exam_data, '%Y-%m-%d') + except ValueError as e: + incorrect_patients.append({"fio": cells[fio], "reason": f"Неверный формат даты/несуществующая дата в файле: {e}"}) + continue + gender_data = cells[gender][0] + department_data = cells[department] + if fio_data is None and snils_data is None: + incorrect_patients.append({"fio": f"Строка: {index}", "reason": "Отсутствует данные"}) + continue + patient_card = search_patient(snils_data, request.user, family_data, name_data, patronymic_data, birthday_data) + if patient_card is None: + patient_card = create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data) + harmful_factors_data, incorrect_factor = find_factors(code_harmful_data) + if incorrect_factor: + incorrect_patients.append({"fio": cells[fio], "reason": f"Неверные факторы: {incorrect_factor}"}) + patient_updated = add_factors_data(patient_card, cells[position], harmful_factors_data, exam_data, company_inn, department_data) + if not patient_updated["ok"]: + incorrect_patients.append({"fio": cells[fio], "reason": f"Сохранение не удалось, ошибка: {patient_updated['message']}"}) + + return {"ok": True, "result": incorrect_patients, "message": ""} From a041c835ba1cd00b7fb7acea1145807f11538792 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:08:08 +0800 Subject: [PATCH 04/62] rename form --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index 9c5f2239ca..bde0701458 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -160,7 +160,7 @@ def add_factors_data(patient_card: Card, position: str, factors_data: list, exam return {"ok": False, "message": e} -def form_03(request_data): +def form_01(request_data): """ Загрузка списка на мед. осмотр From 288ab0ac4d81d8583b7bfe7d3a06c861d154ee66 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:08:28 +0800 Subject: [PATCH 05/62] =?UTF-8?q?=D0=A1=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l2-frontend/src/construct/ConstructCompany.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/l2-frontend/src/construct/ConstructCompany.vue b/l2-frontend/src/construct/ConstructCompany.vue index a4e2cdb6c6..a1b8dab404 100644 --- a/l2-frontend/src/construct/ConstructCompany.vue +++ b/l2-frontend/src/construct/ConstructCompany.vue @@ -153,7 +153,12 @@
@@ -369,13 +374,19 @@ import ruRu from '@/locales/ve'; import VueTippyTd from '@/construct/VueTippyTd.vue'; import * as actions from '@/store/action-types'; import LoadFile from '@/ui-cards/LoadFile.vue'; +import UploadFileModal from '@/modals/UploadFileModal.vue'; VeLocale.use(ruRu); export default { name: 'ConstructCompany', components: { - LoadFile, VueTippyTd, VeTable, VePagination, Treeselect, + UploadFileModal, + LoadFile, + VueTippyTd, + VeTable, + VePagination, + Treeselect, }, data() { return { From ddd29f9de89d8afa78c42fd8daaf2e0cdf9d7864 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:11:49 +0800 Subject: [PATCH 06/62] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l2-frontend/src/components/types-and-forms-file.ts | 1 + laboratory/settings.py | 1 + 2 files changed, 2 insertions(+) diff --git a/l2-frontend/src/components/types-and-forms-file.ts b/l2-frontend/src/components/types-and-forms-file.ts index 5e887df075..52daf0bda2 100644 --- a/l2-frontend/src/components/types-and-forms-file.ts +++ b/l2-frontend/src/components/types-and-forms-file.ts @@ -37,6 +37,7 @@ export default function typesAndForms() { XLSX: { 100.01: { id: '100.01', label: 'Загрузка цен по прайсу' }, 100.02: { id: '100.02', label: 'Загрузка посещений' }, + 101.01: { id: '101.01', label: 'Загрузка списка на мед. осмотр' }, }, }); const addForms = (type: string, forms = null, allowedForms: string[] = null) => { diff --git a/laboratory/settings.py b/laboratory/settings.py index 23b9592ff8..88dfc23526 100644 --- a/laboratory/settings.py +++ b/laboratory/settings.py @@ -427,6 +427,7 @@ def __getitem__(self, item): ALLOWED_FORMS_FILE = { "100.01": False, "100.02": False, + "101.01": False, } EXCLUDE_TYPE_RESEARCH = { From 9a823eb6c144c5eb937ab658a97360abec9ca6ac Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:17:31 +0800 Subject: [PATCH 07/62] fixs --- api/parse_file/forms101.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index bde0701458..f4a0b900ac 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -172,11 +172,13 @@ def form_01(request_data): """ file = request_data.get("file") + other_need_data = request_data.get("other_need_data") + user = request_data.get("user") wb = load_workbook(filename=file) ws = wb[wb.sheetnames[0]] starts = False incorrect_patients = [] - company_inn = request.POST.get("companyInn", None) + company_inn = other_need_data.get("companyInn", None) snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date, department = ( None, None, @@ -228,7 +230,7 @@ def form_01(request_data): if fio_data is None and snils_data is None: incorrect_patients.append({"fio": f"Строка: {index}", "reason": "Отсутствует данные"}) continue - patient_card = search_patient(snils_data, request.user, family_data, name_data, patronymic_data, birthday_data) + patient_card = search_patient(snils_data, user, family_data, name_data, patronymic_data, birthday_data) if patient_card is None: patient_card = create_patient(family_data, name_data, patronymic_data, birthday_data, gender_data) harmful_factors_data, incorrect_factor = find_factors(code_harmful_data) From 82ad9996da9ab02570cf2b21e456910cfe3fd358 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:18:18 +0800 Subject: [PATCH 08/62] fixs --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index f4a0b900ac..7d545f00eb 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -174,11 +174,11 @@ def form_01(request_data): file = request_data.get("file") other_need_data = request_data.get("other_need_data") user = request_data.get("user") + company_inn = other_need_data.get("companyInn", None) wb = load_workbook(filename=file) ws = wb[wb.sheetnames[0]] starts = False incorrect_patients = [] - company_inn = other_need_data.get("companyInn", None) snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date, department = ( None, None, From c3b6718730661d7cb02cb99cab8ea4d03e64941c Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 09:19:36 +0800 Subject: [PATCH 09/62] fixs --- l2-frontend/src/construct/ConstructCompany.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/l2-frontend/src/construct/ConstructCompany.vue b/l2-frontend/src/construct/ConstructCompany.vue index a1b8dab404..450bf6ce99 100644 --- a/l2-frontend/src/construct/ConstructCompany.vue +++ b/l2-frontend/src/construct/ConstructCompany.vue @@ -373,7 +373,6 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css'; import ruRu from '@/locales/ve'; import VueTippyTd from '@/construct/VueTippyTd.vue'; import * as actions from '@/store/action-types'; -import LoadFile from '@/ui-cards/LoadFile.vue'; import UploadFileModal from '@/modals/UploadFileModal.vue'; VeLocale.use(ruRu); @@ -382,7 +381,6 @@ export default { name: 'ConstructCompany', components: { UploadFileModal, - LoadFile, VueTippyTd, VeTable, VePagination, From 68c2168242e566b3ad5616196226a47a0309d7d8 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 14:54:44 +0800 Subject: [PATCH 10/62] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=20=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- slog/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/slog/models.py b/slog/models.py index 6461cd796f..74107fea67 100644 --- a/slog/models.py +++ b/slog/models.py @@ -181,6 +181,7 @@ class Log(models.Model): (230003, 'Палаты: Пациенту отменили доктора'), (230004, 'Палаты: Пациент переведен в ожидающие'), (230005, 'Палаты: Пациент покинул ожидающих'), + (240000, 'Загрузка файлов: Ошибка'), ) # Виды событий, которые могут быть очищены From 70be09eec74c858cd8b36b0adf423fdb8d964793 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 14:55:18 +0800 Subject: [PATCH 11/62] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/views.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index 187d450466..008ec090b6 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -4,6 +4,7 @@ import logging import re import tempfile +import traceback from copy import deepcopy from sys import stdout @@ -29,6 +30,7 @@ from hospitals.models import Hospitals from laboratory.settings import CONTROL_AGE_MEDEXAM, DAYS_AGO_SEARCH_RESULT, ALLOWED_FORMS_FILE from results.sql_func import check_lab_instrumental_results_by_cards_and_period +from slog.models import Log from statistic.views import commercial_offer_xls_save_file, data_xls_save_file, data_xls_save_headers_file from users.models import AssignmentResearches, DoctorProfile from clients.models import Individual, HarmfulFactor, PatientHarmfullFactor, Card, CardBase, DocumentType, Document @@ -904,25 +906,27 @@ def get_parts_fio(fio_data): @login_required() def upload_file(request): - # todo - Логирование загрузки файлов + file = request.FILES["file"] + request_data = request.POST + selected_form = request_data.get("selectedForm") + entity_id = request_data.get("entityId") + other_need_data = request_data.get("otherNeedData") + user = request.user + data = {"file": file, "selected_form": selected_form, "entity_id": entity_id, "other_need_data": other_need_data} try: - file = request.FILES["file"] - request_data = request.POST - selected_form = request_data.get("selectedForm") - entity_id = request_data.get("entityId") - other_need_data = request_data.get("otherNeedData") - data = {"file": file, "selected_form": selected_form, "entity_id": entity_id, "other_need_data": other_need_data} function = import_string(f"api.parse_file.forms{selected_form[0:3]}.form_{selected_form[4:6]}") result = function( request_data={ **data, - "user": request.user, + "user": user, "hospital": request.user.doctorprofile.get_hospital() if hasattr(request.user, "doctorprofile") else Hospitals.get_default_hospital(), } ) except Exception as e: + tb = traceback.format_exc() exception_string = f"{e}" - stdout.write(exception_string) + stdout.write(tb) + Log.log(selected_form,240000, user, {"exception_string": exception_string, "traceback": tb}) return JsonResponse({"ok": False, "result": [], "message": exception_string}) return JsonResponse({"ok": result["ok"], "result": result["result"], "message": result["message"]}) From 8e94ef074512ddbec4d26bf69115b980c8408ef2 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 19:03:22 +0800 Subject: [PATCH 12/62] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D0=B9=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index 008ec090b6..9f0cca6f60 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -926,8 +926,8 @@ def upload_file(request): tb = traceback.format_exc() exception_string = f"{e}" stdout.write(tb) - Log.log(selected_form,240000, user, {"exception_string": exception_string, "traceback": tb}) - return JsonResponse({"ok": False, "result": [], "message": exception_string}) + Log.log(selected_form,240000, user.doctorprofile, {"exception_string": exception_string, "traceback": tb}) + return JsonResponse({"ok": False, "result": [], "message": "Ошибка загрузки файла"}) return JsonResponse({"ok": result["ok"], "result": result["result"], "message": result["message"]}) From 2b72aa28ef6ddfc9a5d8b74edda6b8883e271b0d Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 19:04:48 +0800 Subject: [PATCH 13/62] 7 --- api/parse_file/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index 9f0cca6f60..65d24f3734 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -927,7 +927,7 @@ def upload_file(request): exception_string = f"{e}" stdout.write(tb) Log.log(selected_form,240000, user.doctorprofile, {"exception_string": exception_string, "traceback": tb}) - return JsonResponse({"ok": False, "result": [], "message": "Ошибка загрузки файла"}) + return JsonResponse({"ok": False, "result": [], "message": "Ошибка обработки файла"}) return JsonResponse({"ok": result["ok"], "result": result["result"], "message": result["message"]}) From 2da33209b5b6400e9f30ab217ab0e46c7227d638 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 19:23:02 +0800 Subject: [PATCH 14/62] otherNeedData to json --- l2-frontend/src/components/UploadFile.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/l2-frontend/src/components/UploadFile.vue b/l2-frontend/src/components/UploadFile.vue index 439261317b..3a386842df 100644 --- a/l2-frontend/src/components/UploadFile.vue +++ b/l2-frontend/src/components/UploadFile.vue @@ -121,7 +121,7 @@ const props = defineProps({ required: false, }, otherNeedData: { - type: Object || Array || String || Number, + type: Object || Array, required: false, }, simpleMode: { @@ -196,7 +196,7 @@ const submitFileUpload = async () => { formData.append('file', file.value); formData.append('selectedForm', selectedForm.value); formData.append('entityId', props.entityId ? String(props.entityId) : null); - formData.append('otherNeedData', props.otherNeedData ? props.otherNeedData : null); + formData.append('otherNeedData', props.otherNeedData ? JSON.stringify(props.otherNeedData) : null); await store.dispatch(actions.INC_LOADING); const { ok, message } = await api('parse-file/upload-file', null, null, null, formData); await store.dispatch(actions.DEC_LOADING); From ebb490feec3f62354b99619593dcbbf055aef1d9 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 19:23:30 +0800 Subject: [PATCH 15/62] . --- api/parse_file/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index 65d24f3734..004ca2656e 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -910,7 +910,7 @@ def upload_file(request): request_data = request.POST selected_form = request_data.get("selectedForm") entity_id = request_data.get("entityId") - other_need_data = request_data.get("otherNeedData") + other_need_data = json.loads(request_data.get("otherNeedData")) user = request.user data = {"file": file, "selected_form": selected_form, "entity_id": entity_id, "other_need_data": other_need_data} try: From 86e4a2325fd7af84008614dd6a21376755d1d046 Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 19:23:39 +0800 Subject: [PATCH 16/62] . --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index 7d545f00eb..a80915c1d2 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -174,7 +174,7 @@ def form_01(request_data): file = request_data.get("file") other_need_data = request_data.get("other_need_data") user = request_data.get("user") - company_inn = other_need_data.get("companyInn", None) + company_inn = other_need_data.get("companyInn") wb = load_workbook(filename=file) ws = wb[wb.sheetnames[0]] starts = False From 4bebd9464a111a8c1e18555e74b92b2b284dfacc Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 19:25:31 +0800 Subject: [PATCH 17/62] . --- l2-frontend/src/modals/UploadFileModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l2-frontend/src/modals/UploadFileModal.vue b/l2-frontend/src/modals/UploadFileModal.vue index f86022b23e..b593b82f20 100644 --- a/l2-frontend/src/modals/UploadFileModal.vue +++ b/l2-frontend/src/modals/UploadFileModal.vue @@ -84,7 +84,7 @@ const props = defineProps({ required: false, }, otherNeedData: { - type: Object || Array || String || Number, + type: Object || Array, required: false, }, }); From 3727fe9e4ab01ad101091275c2330de055ada00b Mon Sep 17 00:00:00 2001 From: well Date: Tue, 5 Nov 2024 20:01:36 +0800 Subject: [PATCH 18/62] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=20=D1=81?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB?= =?UTF-8?q?=D1=8C=D1=82=D0=B0=D1=82=D0=BE=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D1=86=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/forms101.py | 11 +++- l2-frontend/src/components/UploadFile.vue | 64 ++++++++++++++++++- .../src/construct/ConstructCompany.vue | 1 + l2-frontend/src/modals/UploadFileModal.vue | 5 ++ 4 files changed, 77 insertions(+), 4 deletions(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index a80915c1d2..b36de5c730 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -175,6 +175,10 @@ def form_01(request_data): other_need_data = request_data.get("other_need_data") user = request_data.get("user") company_inn = other_need_data.get("companyInn") + columns = [ + {"field": 'fio', "key": 'fio', "title": 'ФИО', "align": 'left', "width": 150}, + {"field": 'reason', "key": 'reason', "title": 'Причина ошибки'} + ] wb = load_workbook(filename=file) ws = wb[wb.sheetnames[0]] starts = False @@ -239,5 +243,8 @@ def form_01(request_data): patient_updated = add_factors_data(patient_card, cells[position], harmful_factors_data, exam_data, company_inn, department_data) if not patient_updated["ok"]: incorrect_patients.append({"fio": cells[fio], "reason": f"Сохранение не удалось, ошибка: {patient_updated['message']}"}) - - return {"ok": True, "result": incorrect_patients, "message": ""} + result = { + "colData": columns, + "data": incorrect_patients, + } + return {"ok": True, "result": result, "message": ""} diff --git a/l2-frontend/src/components/UploadFile.vue b/l2-frontend/src/components/UploadFile.vue index 3a386842df..ea6eb86ad8 100644 --- a/l2-frontend/src/components/UploadFile.vue +++ b/l2-frontend/src/components/UploadFile.vue @@ -62,6 +62,30 @@ Загрузить файл +
+ +
+ Нет записей +
+
+ +
+
From a8ad79176d5eb44def948452082f5c8e52b8e4f0 Mon Sep 17 00:00:00 2001 From: well Date: Fri, 8 Nov 2024 21:06:31 +0800 Subject: [PATCH 52/62] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=BD=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/forms101.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index d87eaf3447..a3c5174660 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -238,6 +238,8 @@ def validate_med_exam_data(normalize_data: dict, inn_company) -> dict: errors.append("Подразделение не указано") if not normalize_data["gender"] in ["м", "ж"]: errors.append("Пол указан не верно") + if len(normalize_data["position"]) > 128: + errors.append("Должность больше 128 символов") if errors: result = {"ok": False, "data": {"fio": fio_local, "reason": ", ".join(errors)}, "empty": False} @@ -283,7 +285,7 @@ def form_01(request_data): None, None, ) - need_col_name = {"фио", "дата рождения", "пол", "инн организации", "код вредности", "должность", "дата мед. осмотра", "подразделение"} + need_col_name = {"снилс", "фио", "дата рождения", "пол", "инн организации", "код вредности", "должность", "дата мед. осмотра", "подразделение"} for index, row in enumerate(ws.rows, 1): cells = [str(x.value) for x in row] if not starts: From b5d85a334e78946bdbbfbf4155fe95038c652622 Mon Sep 17 00:00:00 2001 From: well Date: Fri, 8 Nov 2024 21:16:38 +0800 Subject: [PATCH 53/62] =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=B3?= =?UTF-8?q?=D1=83=D1=80=D0=B7=D0=BA=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= =?UTF-8?q?=20-=20=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=B8=D1=82=D1=8C=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D1=8B=D0=B4=D1=83=D1=89=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l2-frontend/src/components/UploadFile.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/l2-frontend/src/components/UploadFile.vue b/l2-frontend/src/components/UploadFile.vue index 97d6f4e194..37cb493a65 100644 --- a/l2-frontend/src/components/UploadFile.vue +++ b/l2-frontend/src/components/UploadFile.vue @@ -238,6 +238,7 @@ const clearFile = () => { }; const submitFileUpload = async () => { + tableData.value = []; try { const formData = new FormData(); formData.append('file', file.value); From f20ca3af97c81a3a4f62ff37dbf01844172d9177 Mon Sep 17 00:00:00 2001 From: Well <72241044+Wellheor1@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:28:01 +0800 Subject: [PATCH 54/62] Update api/parse_file/forms101.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index a3c5174660..b305630397 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -63,7 +63,7 @@ def find_and_replace(text, symbol1, symbol2): result = [] for i in range(len(text)): if text[i] == symbol1: - current_text = text[0:i] + symbol2 + text[i + 1:] + current_text = text[0:i] + symbol2 + text[i + 1 :] result.append(current_text) elif text[i] == symbol2: current_text = text[0:i] + symbol1 + text[i + 1:] From 7f66f6417286925ba98ee4259e8604c209470701 Mon Sep 17 00:00:00 2001 From: Well <72241044+Wellheor1@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:28:08 +0800 Subject: [PATCH 55/62] Update api/parse_file/forms101.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index b305630397..ee9add26ca 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -66,7 +66,7 @@ def find_and_replace(text, symbol1, symbol2): current_text = text[0:i] + symbol2 + text[i + 1 :] result.append(current_text) elif text[i] == symbol2: - current_text = text[0:i] + symbol1 + text[i + 1:] + current_text = text[0:i] + symbol1 + text[i + 1 :] result.append(current_text) return result From b7e6ddb8d0d06140fbbeff4d954cc4366dedfede Mon Sep 17 00:00:00 2001 From: well Date: Fri, 8 Nov 2024 21:29:23 +0800 Subject: [PATCH 56/62] fix --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index ee9add26ca..61bd350eea 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -214,7 +214,7 @@ def check_date(date): return False try: datetime.datetime.strptime(date, '%Y-%m-%d') - except ValueError as e: + except ValueError: return False return True From 3da2c1df0412f4e7ce0f243bad9fb17c77247cfa Mon Sep 17 00:00:00 2001 From: well Date: Fri, 8 Nov 2024 21:36:28 +0800 Subject: [PATCH 57/62] left --- api/parse_file/forms101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/parse_file/forms101.py b/api/parse_file/forms101.py index 61bd350eea..bd205be4e8 100644 --- a/api/parse_file/forms101.py +++ b/api/parse_file/forms101.py @@ -269,7 +269,7 @@ def form_01(request_data): other_need_data = request_data.get("other_need_data") user = request_data.get("user") company_inn = other_need_data.get("companyInn") - columns = [{"field": 'fio', "key": 'fio', "title": 'ФИО', "align": 'center', "width": 250}, {"field": 'reason', "key": 'reason', "title": 'Причина ошибки'}] + columns = [{"field": 'fio', "key": 'fio', "title": 'ФИО', "align": 'left', "width": 250}, {"field": 'reason', "key": 'reason', "title": 'Причина ошибки'}] wb = load_workbook(filename=file) ws = wb[wb.sheetnames[0]] starts = False From 70a460e0d7a8215d717bf6aeebb14c62acdad520 Mon Sep 17 00:00:00 2001 From: well Date: Sun, 10 Nov 2024 15:29:02 +0800 Subject: [PATCH 58/62] comment + todo --- l2-frontend/src/components/UploadFile.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/l2-frontend/src/components/UploadFile.vue b/l2-frontend/src/components/UploadFile.vue index 37cb493a65..128b7f9e9e 100644 --- a/l2-frontend/src/components/UploadFile.vue +++ b/l2-frontend/src/components/UploadFile.vue @@ -113,6 +113,7 @@