Skip to content

Commit

Permalink
Merge pull request #4117 from mikhailprivalov/ftpPushResult
Browse files Browse the repository at this point in the history
uplod pdf to result
  • Loading branch information
Wellheor1 authored Jul 20, 2024
2 parents 7fe31a4 + 2329032 commit 64fe8fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3952,8 +3952,8 @@ def eds_documents(request):
if v in ["", None]:
error_doctor = f"{k} - не верно;{error_doctor}"

if not iss_obj.doc_confirmation.podrazdeleniye.n3_id or not iss_obj.doc_confirmation.hospital.code_tfoms:
return JsonResponse({"documents": [], "edsTitle": "", "executors": "", "error": True, "message": "UUID подразделения или код ТФОМС не заполнен"})
# if not iss_obj.doc_confirmation.podrazdeleniye.n3_id or not iss_obj.doc_confirmation.hospital.code_tfoms:
# return JsonResponse({"documents": [], "edsTitle": "", "executors": "", "error": True, "message": "UUID подразделения или код ТФОМС не заполнен"})

base = SettingManager.get_cda_base_url()
if base != "empty":
Expand Down
32 changes: 28 additions & 4 deletions ftp_orders/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from django.core.files.base import ContentFile
import datetime
import ftplib
import json
Expand All @@ -18,7 +19,17 @@
from appconf.manager import SettingManager
from clients.models import Individual, CardBase
from contracts.models import PriceName
from directions.models import Napravleniya, RegisteredOrders, NumberGenerator, TubesRegistration, IstochnikiFinansirovaniya, NapravleniyaHL7LinkFiles, Issledovaniya, Result
from directions.models import (
Napravleniya,
RegisteredOrders,
NumberGenerator,
TubesRegistration,
IstochnikiFinansirovaniya,
NapravleniyaHL7LinkFiles,
Issledovaniya,
Result,
IssledovaniyaFiles,
)
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
Expand Down Expand Up @@ -410,7 +421,13 @@ def pull_result(self, file: str):
for obx in obxes:
tmp_fractions = fractions.copy()
if (obx.OBX.obx_3.obx_3_1.value).lower == "pdf":
continue
pdf_base_64 = obx.OBX.obx_5.obx_5_5.value
base64_bytes = pdf_base_64.encode('utf-8')
data = ContentFile(base64.b64decode(base64_bytes))
iss_file = IssledovaniyaFiles(issledovaniye=iss, uploaded_file=data)
file_name_internal_code = internal_code.replace(".", "_")
iss_file.uploaded_file.name = f"{tube_number}_{file_name_internal_code}.pdf"
iss_file.save()
elif (obx.OBX.obx_3.obx_3_1.value).lower() == "jpg":
tmp_fractions["jpg"] = obx.OBX.obx_5.obx_5_5.value
result.append(tmp_fractions.copy())
Expand All @@ -421,6 +438,12 @@ def pull_result(self, file: str):
continue
tmp_fsli = obx.OBX.obx_3.obx_3_1.value
if tmp_fsli not in fractions_fsl:
if is_confirm:
iss.lab_comment = ""
iss.time_confirmation = datetime.datetime.strptime(date_time_confirm, "%Y%m%d%H%M%S")
iss.time_save = current_time()
iss.doc_confirmation_string = doctor_fio
iss.save()
Log.log(key=tube_number, type=190005, body={"tube": tube_number, "internal_code": internal_code, "researchTile": research_title, "file": file}, user=None)
self.copy_file(file, FTP_PATH_TO_SAVE)
self.delete_file(file)
Expand Down Expand Up @@ -632,13 +655,14 @@ def check_replace_fields(field_replace, line_new, direction):
for fr in field_replace:
if fr == "2" and line_new[0] == "MSH":
line_new[int(fr)] = direction.external_executor_hospital.hl7_sender_application
line_new[int(fr)] = direction.hospital.hl7_sender_application
elif fr == "3" and line_new[0] == "MSH":
line_new[int(fr)] = direction.external_executor_hospital.short_title
line_new[int(fr)] = direction.hospital.hl7_sender_org
elif fr == "2-2" and line_new[0] == "OBR":
positions = fr.split("-")
data = line_new[int(positions[0])]
data_pos = data.split("^")
data_pos[int(positions[1]) - 1] = direction.external_executor_hospital.hl7_sender_application
data_pos[int(positions[1]) - 1] = direction.hospital.hl7_sender_application
data = "^".join(data_pos)
line_new[int(positions[0])] = data
return line_new
Expand Down
3 changes: 3 additions & 0 deletions hospitals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Hospitals(models.Model):
result_pull_by_numbers = models.CharField(
max_length=256, blank=True, default=None, null=True, help_text='URL для FTP директории получения результатов (ftp://user:[email protected]/path)'
)
result_push_by_numbers = models.CharField(
max_length=256, blank=True, default=None, null=True, help_text='URL для FTP директории отрпавки результатов (ftp://user:[email protected]/path)'
)
hl7_sender_application = models.CharField(max_length=55, blank=True, default=None, null=True, help_text='HL7 приложение отправитель')
hl7_sender_org = models.CharField(max_length=55, blank=True, default=None, null=True, help_text='HL7 организация отправитель')
hl7_receiver_appplication = models.CharField(max_length=55, blank=True, default=None, null=True, help_text='HL7 приложение получатель')
Expand Down

0 comments on commit 64fe8fb

Please sign in to comment.