From 1c0ba87a653d8f74214d3a8b3cdec6f3f6de6e31 Mon Sep 17 00:00:00 2001 From: sergei kasianenko Date: Mon, 1 Jul 2024 13:05:06 +0800 Subject: [PATCH 1/4] fix result --- directions/models.py | 1 + directory/sql_func.py | 17 +++++++++++++++++ ftp_orders/main.py | 30 +++++++++++++++++++++++++----- ftp_orders/sql_func.py | 2 +- slog/models.py | 1 + 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/directions/models.py b/directions/models.py index 9ff679f60c..d9cb915610 100644 --- a/directions/models.py +++ b/directions/models.py @@ -566,6 +566,7 @@ class Napravleniya(models.Model): cpp_upload_id = models.CharField(max_length=128, default=None, blank=True, null=True, db_index=True, help_text='Id-загрузки ЦПП') need_resend_cpp = models.BooleanField(default=False, blank=True, help_text='Требуется отправка в ЦПП') ecp_direction_number = models.CharField(max_length=64, default=None, blank=True, null=True, db_index=True, help_text='Id-направления ЕЦП') + is_cito = models.BooleanField(default=False, blank=True, help_text='Срочное исполнение') def sync_confirmed_fields(self, skip_post=False): has_confirmed_iss = Issledovaniya.objects.filter(napravleniye=self, time_confirmation__isnull=False).exists() diff --git a/directory/sql_func.py b/directory/sql_func.py index 2b36524b12..ea1b3870b3 100644 --- a/directory/sql_func.py +++ b/directory/sql_func.py @@ -68,3 +68,20 @@ def get_lab_research_reference_books(): ) rows = namedtuplefetchall(cursor) return rows + + +def get_fsli_fractions_by_research_id(research_id): + with connection.cursor() as cursor: + cursor.execute( + """ + SELECT + directory_fractions.id as fraction_id, + directory_fractions.title as fraction_title, + directory_fractions.fsli as fraction_fsli + FROM directory_fractions + WHERE directory_fractions.research_id = %(research_id)s + """, + params={}, + ) + rows = namedtuplefetchall(cursor) + return rows diff --git a/ftp_orders/main.py b/ftp_orders/main.py index 55804db71b..230d8162e0 100644 --- a/ftp_orders/main.py +++ b/ftp_orders/main.py @@ -19,6 +19,7 @@ from clients.models import Individual, CardBase from contracts.models import PriceName from directions.models import Napravleniya, RegisteredOrders, NumberGenerator, TubesRegistration, IstochnikiFinansirovaniya, NapravleniyaHL7LinkFiles, Issledovaniya, Result +from directory.sql_func import get_fsli_fractions_by_research_id from ftp_orders.sql_func import get_tubesregistration_id_by_iss from hospitals.models import Hospitals from directory.models import Researches, Fractions @@ -371,6 +372,17 @@ def pull_result(self, file: str): external_add_order = obr.OBR_2.OBR_2_1.value else: iss_id = (obr.OBR_2.OBR_2_1.value).split("_")[1] + tube_number = obr.OBR_3.OBR_3_1.value + internal_code = obr.OBR_4.OBR_4_4.value + research_title = obr.OBR_4.OBR_4_5.value + + if external_add_order: + iss = Issledovaniya.objects.filter(external_add_order__external_add_order=external_add_order).first() + else: + iss = Issledovaniya.objects.filter(id=iss_id).first() + fractions_data = get_fsli_fractions_by_research_id(iss.research_id) + fractions_fsl = [i.fraction_fsli for i in fractions_data] + doctor_family_confirm = obr.OBR_32.OBR_32_2.value doctor_name_confirm = obr.OBR_32.OBR_32_3.value doctor_patronymic_confirm = obr.OBR_32.OBR_32_4.value @@ -384,6 +396,7 @@ def pull_result(self, file: str): obxes = hl7_result.ORU_R01_RESPONSE.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION fractions = {"fsli": "", "title_fraction": "", "value": "", "refs": "", "units": "", "jpeg": "", "html": "", "doc_confirm": "", "date_confirm": "", "note_data": ""} result = [] + for obx in obxes: tmp_fractions = fractions.copy() if (obx.OBX.obx_3.obx_3_1.value).lower == "pdf": @@ -396,17 +409,24 @@ def pull_result(self, file: str): tmp_fractions["html"] = obx.OBX.obx_5.obx_5_1.value result.append(tmp_fractions.copy()) continue - tmp_fractions["fsli"] = obx.OBX.obx_3.obx_3_1.value + tmp_fsli = obx.OBX.obx_3.obx_3_1.value + if tmp_fsli not in fractions_fsl: + Log.log(key=tube_number, type=190005, body=json.dumps({ + "tube": tube_number, + "internal_code": internal_code, + "researchTile": research_title, + "file": file + }), user=None).save() + self.copy_file(file, FTP_PATH_TO_SAVE) + self.delete_file(file) + return + tmp_fractions["fsli"] = tmp_fsli tmp_fractions["title_fraction"] = obx.OBX.obx_3.obx_3_2.value tmp_fractions["value"] = obx.OBX.obx_5.obx_5_1.value tmp_fractions["units"] = obx.OBX.obx_6.value tmp_fractions["refs"] = obx.OBX.obx_7.obx_7_1.value result.append(tmp_fractions.copy()) - if external_add_order: - iss = Issledovaniya.objects.filter(external_add_order__external_add_order=external_add_order).first() - else: - iss = Issledovaniya.objects.filter(id=iss_id).first() if is_confirm: iss.lab_comment = "" diff --git a/ftp_orders/sql_func.py b/ftp_orders/sql_func.py index b9b2b030ca..4c8f54aee9 100644 --- a/ftp_orders/sql_func.py +++ b/ftp_orders/sql_func.py @@ -15,4 +15,4 @@ def get_tubesregistration_id_by_iss(iss_id): params={'iss_id': iss_id}, ) rows = namedtuplefetchall(cursor) - return rows \ No newline at end of file + return rows diff --git a/slog/models.py b/slog/models.py index d4e965b8de..7e86a9a722 100644 --- a/slog/models.py +++ b/slog/models.py @@ -161,6 +161,7 @@ class Log(models.Model): (190002, 'FTP HL7: результат pull'), (190003, 'FTP HL7: результат push'), (190004, 'REST: заказ принятие'), + (190005, 'FTP HL7: Ошибка результат pull'), (200000, 'Счет на оплату: подтверждение'), (200001, 'Счет на оплату: сброс подтверждения'), (210000, 'Комплексные услуги: создание комплекса'), From 632c72ba8647e5938e0cd11e92764edf97caf69d Mon Sep 17 00:00:00 2001 From: Sergei Kasianenko <41939763+urchinpro@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:07:47 +0800 Subject: [PATCH 2/4] Update ftp_orders/main.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- ftp_orders/main.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ftp_orders/main.py b/ftp_orders/main.py index 230d8162e0..ad073b47f7 100644 --- a/ftp_orders/main.py +++ b/ftp_orders/main.py @@ -411,12 +411,7 @@ def pull_result(self, file: str): continue tmp_fsli = obx.OBX.obx_3.obx_3_1.value if tmp_fsli not in fractions_fsl: - Log.log(key=tube_number, type=190005, body=json.dumps({ - "tube": tube_number, - "internal_code": internal_code, - "researchTile": research_title, - "file": file - }), user=None).save() + Log.log(key=tube_number, type=190005, body=json.dumps({"tube": tube_number, "internal_code": internal_code, "researchTile": research_title, "file": file}), user=None).save() self.copy_file(file, FTP_PATH_TO_SAVE) self.delete_file(file) return From b842cd849a08385e90e8236bcdde749d118738f9 Mon Sep 17 00:00:00 2001 From: Sergei Kasianenko <41939763+urchinpro@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:07:52 +0800 Subject: [PATCH 3/4] Update ftp_orders/main.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- ftp_orders/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ftp_orders/main.py b/ftp_orders/main.py index ad073b47f7..6745253d5f 100644 --- a/ftp_orders/main.py +++ b/ftp_orders/main.py @@ -422,7 +422,6 @@ def pull_result(self, file: str): tmp_fractions["refs"] = obx.OBX.obx_7.obx_7_1.value result.append(tmp_fractions.copy()) - if is_confirm: iss.lab_comment = "" iss.time_confirmation = datetime.datetime.strptime(date_time_confirm, "%Y%m%d%H%M%S") From 01db04125c418aeb3dbca9c52fb9899e5009457c Mon Sep 17 00:00:00 2001 From: Sergei Kasianenko <41939763+urchinpro@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:08:38 +0800 Subject: [PATCH 4/4] Update ftp_orders/main.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- ftp_orders/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ftp_orders/main.py b/ftp_orders/main.py index 6745253d5f..342f66508c 100644 --- a/ftp_orders/main.py +++ b/ftp_orders/main.py @@ -421,7 +421,6 @@ def pull_result(self, file: str): tmp_fractions["units"] = obx.OBX.obx_6.value tmp_fractions["refs"] = obx.OBX.obx_7.obx_7_1.value result.append(tmp_fractions.copy()) - if is_confirm: iss.lab_comment = "" iss.time_confirmation = datetime.datetime.strptime(date_time_confirm, "%Y%m%d%H%M%S")