Skip to content

Commit

Permalink
Merge pull request #3860 from mikhailprivalov/MSH_headers_HL7
Browse files Browse the repository at this point in the history
MSH Headers
  • Loading branch information
Wellheor1 authored May 31, 2024
2 parents e7812cb + 6120344 commit 36efa67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion clients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ def import_from_simple_data(data: dict, owner, patient_id_company, email, phone)
sex = data.get('sex', '').lower().strip()
birthday = data.get('birthday', '').split(' ')[0]
snils = data.get('snils', '').split(' ')[0]
enp = data.get('enp', '').split(' ')[0]

i = None
card = None
Expand Down Expand Up @@ -835,7 +836,9 @@ def import_from_simple_data(data: dict, owner, patient_id_company, email, phone)
if i:
snils_type = DocumentType.objects.filter(title__startswith="СНИЛС").first()
document_snils = i.add_or_update_doc(snils_type, '', snils)
card = Card.add_l2_card(individual=i, force=True, owner=owner, snils=document_snils)
enp_type = DocumentType.objects.filter(title__startswith="полис омс").first()
document_enp = i.add_or_update_doc(enp_type, '', enp)
card = Card.add_l2_card(individual=i, force=True, owner=owner, snils=document_snils, polis=document_enp)

return card

Expand Down
16 changes: 10 additions & 6 deletions ftp_orders/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def pull_order(self, file: str):
if RegisteredOrders.objects.filter(file_name=file).exists():
self.error(f"Skipping file {file} because it already exists")
return

hl7_result, hl7_content = self.read_file_as_hl7(file)

if not hl7_content or not hl7_result:
Expand Down Expand Up @@ -212,7 +211,11 @@ def pull_order(self, file: str):

snils = pid.PID_19.value
snils = snils.replace("-", "").replace(" ", "")

enp = ""
if len(pid.PID_18.value) > 1:
document_data = pid.PID_18.value.split("^")
if document_data[2] == "Полис":
enp = document_data[4]
adds_data = pid.to_er7().split("|")[13].split("~")

phone = adds_data[0] if adds_data[0] else ""
Expand Down Expand Up @@ -245,6 +248,7 @@ def pull_order(self, file: str):
"sex": sex,
"birthday": birthday,
"snils": snils,
"enp": enp,
},
self.hospital,
patient_id_company,
Expand Down Expand Up @@ -438,8 +442,8 @@ def pull_result(self, file: str):
def push_order(self, direction: Napravleniya):
hl7 = core.Message("ORM_O01", validation_level=VALIDATION_LEVEL.QUIET)

hl7.msh.msh_3 = "L2"
hl7.msh.msh_4 = "ORDER"
hl7.msh.msh_3 = direction.hospital.hl7_sender_application if direction.hospital.hl7_sender_application else "L2"
hl7.msh.msh_4 = direction.hospital.hl7_sender_org if direction.hospital.hl7_sender_org else "ORDER"
hl7.msh.msh_5 = "qLIS"
hl7.msh.msh_6 = "LukaLab"
hl7.msh.msh_9 = "ORM^O01"
Expand All @@ -454,7 +458,7 @@ def push_order(self, direction: Napravleniya):
patient.pid.pid_7 = individual.birthday.strftime("%Y%m%d")
patient.pid.pid_8 = individual.sex.upper()
byte_email = direction.client.email.encode("utf-8")
field_13 = f"{direction.client.phone.replace(' ', '').replace('-', '')}~~~{base64.b64encode(byte_email).decode('UTF-8')}"
field_13 = f"{direction.client.phone.replace(' ', '').replace('-', '')}@@@{base64.b64encode(byte_email).decode('UTF-8')}"
patient.pid.pid_13.value = field_13
patient.pid.pid_18 = f"^^Полис^^{data_indivdual['enp']}"
patient.pid.pid_19 = data_indivdual["snils"]
Expand Down Expand Up @@ -502,7 +506,7 @@ def push_order(self, direction: Napravleniya):
obr.obr_34.value = ""

content = hl7.value.replace("\r", "\n").replace("ORC|1\n", "")
content = content.replace("\R", "").replace("\\", "")
content = content.replace("R", "~").replace("\\", "")
filename = f"form1c_orm_{direction.pk}_{created_at}.ord"

self.log("Writing file", filename, "\n", content)
Expand Down
1 change: 1 addition & 0 deletions hospitals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Hospitals(models.Model):
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 приложение получатель')
hl7_rule_file = models.CharField(max_length=60, null=True, blank=True, default="default.json", help_text="Название ф-ла правил HL7")
is_auto_transfer_hl7_file = models.BooleanField(default=False, blank=True, help_text='Автоматическая отправка файла в каталог', db_index=True)
Expand Down

0 comments on commit 36efa67

Please sign in to comment.