Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

таблица для диагнозов в 530 #4560

Merged
merged 7 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,10 @@ def directions_paraclinic_result(request):
f_result = ParaclinicResult(issledovaniye=iss, field=f, value="")
else:
f_result = ParaclinicResult.objects.filter(issledovaniye=iss, field=f)[0]
f_result.value = field["value"]
if not field["value"]:
f_result.value = ""
else:
f_result.value = field["value"]
f_result.field_type = f.field_type
if f.field_type in [27, 28, 29, 32, 33, 34, 35]:
try:
Expand Down
39 changes: 39 additions & 0 deletions command_utils/management/commands/import_mkb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.core.management import BaseCommand
from directions.models import Diagnoses
import requests
from openpyxl import load_workbook


def fetch(url):
page = requests.get(url)
return page.json()['list']


class Command(BaseCommand):
help = "Импорт справочника МКБ"

def add_arguments(self, parser):
parser.add_argument('path', type=str)
parser.add_argument('mode', type=str)

def handle(self, *args, **kwargs):
fp = kwargs["path"]
self.stdout.write("Path: " + fp)
wb = load_workbook(filename=fp)
ws = wb[wb.sheetnames[0]]
starts = False
mode = kwargs.get("mode")
code, nsi_id, title = "", "", ""
for row in ws.rows:
cells = [str(x.value) for x in row]
if not starts:
if "Уникальный идентификатор" in cells:
title = cells.index("Наименование")
code = cells.index("Код МКБ-10")
nsi_id = cells.index("Уникальный идентификатор")
starts = True
else:
r = Diagnoses.objects.filter(code=cells[code], d_type=mode)
if not r.exists():
Diagnoses(d_type=mode, code=cells[code], title=cells[title], nsi_id=cells[nsi_id], hide=False, m_type=2).save()
print('сохранено', cells[code]) # noqa: T001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flake8] <201> reported by reviewdog 🐶
print found.

68 changes: 64 additions & 4 deletions forms/forms106.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,9 @@ def form_02(request_data):
)
)

table_data = {"operation": tbl_o, "transfers": transfers}
table_data = {"operation": tbl_o, "transfers": transfers, "Сопутствующие": ""}
cda_data_result = {}

if hosp_extract_data.get("result_by_cda"):
cda_data_result.update(hosp_extract_data.get("result_by_cda"))

Expand All @@ -1302,6 +1303,10 @@ def form_02(request_data):
if not cda_data_result.get("п.п.-Kell"):
cda_data_result["п.п.-Kell"] = " "

if cda_data_result.get("п.п.-Сопутствующие табл"):
accomponement_tbl = parse_accompanement_diagnos(cda_data_result.get("п.п.-Сопутствующие табл"), style)
table_data["Сопутствующие"] = accomponement_tbl

if current_template_file:
for section in body_paragraphs:
objs = check_section_param(objs, styles_obj, section, table_data, cda_data_result)
Expand All @@ -1324,6 +1329,10 @@ def check_section_param(objs, styles_obj, section, tbl_specification, cda_titles
objs.append(tbl_specification.get("operation"))
elif section.get("type") == "Движение":
objs.append(Paragraph(tbl_specification.get("transfers"), styles_obj[section.get("style")]))
elif section.get("type") == "Сопутствующие":
objs.append(tbl_specification.get("Сопутствующие"))
elif section.get("type") == "Осложнения":
objs.append(tbl_specification.get("Осложнения"))
elif section.get("text"):
cda_titles_sec = section.get("cdaTitles")
data_cda = [cda_titles.get(i) for i in cda_titles_sec if cda_titles.get(i)]
Expand All @@ -1347,11 +1356,11 @@ def check_diagnos_row_is_dict(data_cda):
except:
is_dict = False
try:
if is_dict and not field_json.get('columns'):
if is_dict and not field_json.get("columns"):
code = field_json.get("code")
title = field_json.get("title")
new_result = f"<u>{title}</u>, код по МКБ <u>{code}</u>"
elif is_dict and field_json.get('columns'):
elif is_dict and field_json.get("columns"):
new_result = ""
rows_data = field_json.get("rows")
for r_data in rows_data:
Expand All @@ -1362,7 +1371,7 @@ def check_diagnos_row_is_dict(data_cda):
is_dict = True
except:
is_dict = False
if is_dict and diag_data.get('code'):
if is_dict and diag_data.get("code"):
title = diag_data.get("title")
code = diag_data.get("code")
new_result = f"{new_result}<u>{title}</u>, код по МКБ <u>{code}</u><br/>"
Expand All @@ -1372,3 +1381,54 @@ def check_diagnos_row_is_dict(data_cda):
result = [new_result]

return result


def parse_accompanement_diagnos(accompanement_data, style):
try:
value = json.loads(accompanement_data)
except:
return None

if not value:
return None
opinion = []
table_rows = value["rows"]
accomponement_result = []
space_symbol = "&nbsp;"
for t in table_rows:
result = ""
result_mkb_code = ""
result_mkb_title = ""
clinic_diag_text = ""
for value_raw in t:
try:
row_data = json.loads(value_raw)
if isinstance(row_data, dict):
if row_data.get("code", None):
result_mkb_code = f"{row_data.get('code')}"
if row_data.get("title", None):
result_mkb_title = f"{row_data.get('title')}"
except:
clinic_diag_text = value_raw
result = f"{result_mkb_title}; {clinic_diag_text}"
accomponement_result.append([Paragraph(f"<u>{result}</u>", style), Paragraph(f"код по МКБ {space_symbol * 3}<u>{result_mkb_code}</u>", style)])
accomponement_result.append([Paragraph("", style), Paragraph("", style)])
opinion.extend(accomponement_result)

tbl_o = Table(
opinion,
colWidths=(
138 * mm,
40 * mm,
),
)
tbl_o.setStyle(
TableStyle(
[
("GRID", (0, 0), (-1, -1), 1.0, colors.white),
("TOPPADDING", (0, 0), (-1, -1), 1 * mm),
("VALIGN", (0, 0), (-1, -1), "TOP"),
]
)
)
return tbl_o
10 changes: 6 additions & 4 deletions forms/pdf_templates/template_federal_order_530_titul_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
{"text": "Основное заболевание: {}", "cdaTitles": [ "п.п.-Основное Ds мкб"], "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Осложнения основного заболевания: <u>{}</u>", "cdaTitles": ["п.п.-Пусто"], "style": "style"},
{"text": "{}", "cdaTitles": ["п.п.-Осложнения Ds мкб"], "style": "style"},
{"tbl": "Таблица", "cdaTitles": ["п.п.-Осложнения табл"], "type": "Осложнения", "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Внешняя причина при травмах, отравлениях: <u>{}</u> код по МКБ: <u>{}</u>", "cdaTitles": ["п.п.-Внешняя причина Ds текст", "п.п.-Внешняя причина Ds мкб" ], "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Сопутствующие заболевания: <u>{}</u>", "cdaTitles": ["п.п.-Пусто"], "style": "style"},
{"text": "{}", "cdaTitles": ["п.п.-Сопутствующие Ds мкб"], "style": "style"},
{"tbl": "Таблица", "cdaTitles": ["п.п.-Сопутствующие табл"], "type": "Сопутствующие", "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Дополнительные сведения о заболевании: <u>{}</u>", "cdaTitles": ["п.п.-Дополнительные сведения заболевания"], "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
Expand All @@ -60,11 +60,13 @@
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Основное заболевание: <u>{}</u> код по МКБ: <u>{}</u>", "cdaTitles": ["в.э.-Основное Ds текст", "в.э.-Основное Ds мкб"], "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Осложнения основного заболевания: <u>{}</u> код по МКБ: <u>{}</u>", "cdaTitles": ["в.э.-Осложнения Ds текст", "в.э.-Осложнения Ds мкб"], "style": "style"},
{"text": "Осложнения основного заболевания: <u>{}</u>", "cdaTitles": ["в.э.-Пусто"], "style": "style"},
{"tbl": "Таблица", "cdaTitles": ["в.э.-Осложнения табл"], "type": "Осложнения", "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Внешняя причина при травмах, отравлениях: <u>{}</u> код по МКБ: <u>{}</u>", "cdaTitles": ["в.э.-Внешняя причина Ds текст", "в.э.-Внешняя причина Ds мкб"], "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Сопутствующие заболевания: <u>{}</u> код по МКБ: <u>{}</u>", "cdaTitles": ["в.э.-Сопутствующие Ds текс", "в.э.-Сопутствующие Ds мкб"], "style": "style"},
{"text": "Сопутствующие заболевания: {}", "cdaTitles": ["в.э.-Пусто"], "style": "style"},
{"tbl": "Таблица", "cdaTitles": ["в.э.-Сопутствующие табл"], "type": "Сопутствующие", "style": "style"},
{"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"},
{"text": "Дополнительные сведения о заболевании: <u>{}</u>", "cdaTitles": ["в.э.-Дополнительные сведения заболевания"], "style": "style"},
{"text": "", "spacer_data": 0.6, "Spacer": "true", "style": "styleCenter"},
Expand Down
Loading