From 64a98adea8b46b277081f0a64f962d86f512ee6c Mon Sep 17 00:00:00 2001 From: Wellheor Date: Fri, 2 Feb 2024 09:15:52 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=B0=D1=86=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20-?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BD=D0=BE=D1=81=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/views.py | 43 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index 0995e1aaee..344be6fc94 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -73,6 +73,19 @@ def http_func(data, user): return endpoint(http_obj) +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 search_patient(snils_data, request_user, family_data, name_data, patronymic_data, birthday_data, gender_data): patient_card = None application = Application.objects.filter(active=True, is_background_worker=True).first() @@ -93,24 +106,12 @@ def search_patient(snils_data, request_user, family_data, name_data, patronymic_ if snils_data and snils_data != "None": current_patient = check_enp(request_obj) if not current_patient or current_patient.data.get("message"): - patient_data = [family_data, name_data, birthday_data] - if None in patient_data or "None" in patient_data: - return patient_card - else: - patient_card = search_by_fio(request_obj, family_data, name_data, patronymic_data, birthday_data) + 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: - 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: - 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 None 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() @@ -184,7 +185,7 @@ def add_factors_from_file(request): incorrect_patients.append({"fio": cells[fio], "reason": "ИНН организации не совпадает"}) continue snils_data = cells[snils].replace("-", "").replace(" ", "") - family_data, name_data, patronymic_data = None, None, None + 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] @@ -201,10 +202,12 @@ def add_factors_from_file(request): incorrect_patients.append({"fio": cells[fio], "reason": f"Неверный формат даты/несуществующая дата в файле: {e}"}) continue gender_data = cells[gender][0] - patient_card = search_patient(snils_data, request.user, family_data, name_data, patronymic_data, birthday_data, gender_data) - if patient_card is None: + 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, gender_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}"}) From 57f35287b0b9d832274c60fe53007ed145316e01 Mon Sep 17 00:00:00 2001 From: Wellheor Date: Fri, 2 Feb 2024 10:05:36 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20background=5Ftoken=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D1=8E,=20fixs=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D1=83=D0=B1=D0=BB=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index 344be6fc94..368968f14d 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -86,8 +86,7 @@ def create_patient(family_data, name_data, patronymic_data, birthday_data, gende return patient_card -def search_patient(snils_data, request_user, family_data, name_data, patronymic_data, birthday_data, gender_data): - patient_card = None +def get_background_token(): application = Application.objects.filter(active=True, is_background_worker=True).first() if application: bearer_token = f"Bearer {application.key}" @@ -95,7 +94,12 @@ def search_patient(snils_data, request_user, family_data, name_data, patronymic_ 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_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 @@ -111,7 +115,7 @@ def search_patient(snils_data, request_user, family_data, name_data, patronymic_ 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 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() From c2666d8ac92e30eed16dea55058696ff231ee08e Mon Sep 17 00:00:00 2001 From: Wellheor Date: Fri, 2 Feb 2024 10:14:59 +0800 Subject: [PATCH 3/5] . --- 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 368968f14d..db2d94fa2a 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -209,7 +209,7 @@ def add_factors_from_file(request): 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, gender_data) + 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) From e9273562b0ae8fd298c1e495f4baefd6577e4075 Mon Sep 17 00:00:00 2001 From: Wellheor Date: Fri, 2 Feb 2024 11:00:37 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/parse_file/views.py | 17 +++++++++++++---- contracts/models.py | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/api/parse_file/views.py b/api/parse_file/views.py index db2d94fa2a..5dbaf986da 100644 --- a/api/parse_file/views.py +++ b/api/parse_file/views.py @@ -19,7 +19,7 @@ from api.views import endpoint from openpyxl import load_workbook from appconf.manager import SettingManager -from contracts.models import PriceCoast, Company, MedicalExamination +from contracts.models import PriceCoast, Company, MedicalExamination, CompanyDepartment import directions.models as directions from directory.models import SetOrderResearch, Researches, ParaclinicInputGroups, ParaclinicInputField from directory.sql_func import is_paraclinic_filter_research, is_lab_filter_research @@ -141,10 +141,16 @@ def find_factors(harmful_factors: list): return harmful_factors_data, incorrect_factor -def add_factors_data(patient_card: Card, position: str, factors_data: list, exam_data: str, company_inn: str): +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() @@ -161,7 +167,8 @@ def add_factors_from_file(request): wb = load_workbook(filename=company_file) ws = wb.worksheets[0] starts = False - snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date = ( + snils, fio, birthday, gender, inn_company, code_harmful, position, examination_date, department = ( + None, None, None, None, @@ -183,6 +190,7 @@ def add_factors_from_file(request): code_harmful = cells.index("код вредности") position = cells.index("должность") examination_date = cells.index("дата мед. осмотра") + department = cells.index("cтруктурное подразделение") starts = True else: if company_inn != cells[inn_company].strip(): @@ -206,6 +214,7 @@ def add_factors_from_file(request): 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 @@ -215,7 +224,7 @@ def add_factors_from_file(request): 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) + 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']}"}) diff --git a/contracts/models.py b/contracts/models.py index 373f5618e5..d03feefe41 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -225,6 +225,13 @@ def search_departments(company_id): company_departments = CompanyDepartment.objects.filter(company_id=company_id) return [{"id": d.id, "label": d.title} for d in company_departments] + @staticmethod + def save_department(company_id: int, department_title: str): + new_department = CompanyDepartment(title=department_title, company_id=company_id) + new_department.save() + return new_department + + class Meta: verbose_name = "Отдел компании" verbose_name_plural = "Отделы компаний" From 735bcfdd32a72c5d7ab9583d66e197188d97714a Mon Sep 17 00:00:00 2001 From: Sergei Kasianenko <41939763+urchinpro@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:19:16 +0800 Subject: [PATCH 5/5] Update contracts/models.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- contracts/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/models.py b/contracts/models.py index d03feefe41..bb8620ad04 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -231,7 +231,6 @@ def save_department(company_id: int, department_title: str): new_department.save() return new_department - class Meta: verbose_name = "Отдел компании" verbose_name_plural = "Отделы компаний"