From 47addc550d53c6fce21b072a59d5c448713afb4d Mon Sep 17 00:00:00 2001 From: sergei kasianenko Date: Sun, 15 Dec 2024 20:15:15 +0800 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B2=20530?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/directions/views.py | 6 +- forms/forms106.py | 68 +++++++++++++++++-- ...template_federal_order_530_titul_page.json | 10 +-- 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/api/directions/views.py b/api/directions/views.py index 618c67fa74..44446cafe8 100644 --- a/api/directions/views.py +++ b/api/directions/views.py @@ -2259,7 +2259,11 @@ 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"] + print(field) + 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: diff --git a/forms/forms106.py b/forms/forms106.py index 6233c53e83..c843a98d4d 100644 --- a/forms/forms106.py +++ b/forms/forms106.py @@ -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")) @@ -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) @@ -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)] @@ -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"{title}, код по МКБ {code}" - 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: @@ -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}{title}, код по МКБ {code}
" @@ -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 = " " + 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"{result}", style), Paragraph(f"код по МКБ {space_symbol * 3}{result_mkb_code}", 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 diff --git a/forms/pdf_templates/template_federal_order_530_titul_page.json b/forms/pdf_templates/template_federal_order_530_titul_page.json index e8a94a5a16..5307d34d6a 100644 --- a/forms/pdf_templates/template_federal_order_530_titul_page.json +++ b/forms/pdf_templates/template_federal_order_530_titul_page.json @@ -34,12 +34,12 @@ {"text": "Основное заболевание: {}", "cdaTitles": [ "п.п.-Основное Ds мкб"], "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Осложнения основного заболевания: {}", "cdaTitles": ["п.п.-Пусто"], "style": "style"}, - {"text": "{}", "cdaTitles": ["п.п.-Осложнения Ds мкб"], "style": "style"}, + {"tbl": "Таблица", "cdaTitles": ["п.п.-Осложнения табл"], "type": "Осложнения", "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Внешняя причина при травмах, отравлениях: {} код по МКБ: {}", "cdaTitles": ["п.п.-Внешняя причина Ds текст", "п.п.-Внешняя причина Ds мкб" ], "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Сопутствующие заболевания: {}", "cdaTitles": ["п.п.-Пусто"], "style": "style"}, - {"text": "{}", "cdaTitles": ["п.п.-Сопутствующие Ds мкб"], "style": "style"}, + {"tbl": "Таблица", "cdaTitles": ["п.п.-Сопутствующие табл"], "type": "Сопутствующие", "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Дополнительные сведения о заболевании: {}", "cdaTitles": ["п.п.-Дополнительные сведения заболевания"], "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, @@ -60,11 +60,13 @@ {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Основное заболевание: {} код по МКБ: {}", "cdaTitles": ["в.э.-Основное Ds текст", "в.э.-Основное Ds мкб"], "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, - {"text": "Осложнения основного заболевания: {} код по МКБ: {}", "cdaTitles": ["в.э.-Осложнения Ds текст", "в.э.-Осложнения Ds мкб"], "style": "style"}, + {"text": "Осложнения основного заболевания: {}", "cdaTitles": ["в.э.-Пусто"], "style": "style"}, + {"tbl": "Таблица", "cdaTitles": ["в.э.-Осложнения табл"], "type": "Осложнения", "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Внешняя причина при травмах, отравлениях: {} код по МКБ: {}", "cdaTitles": ["в.э.-Внешняя причина Ds текст", "в.э.-Внешняя причина Ds мкб"], "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, - {"text": "Сопутствующие заболевания: {} код по МКБ: {}", "cdaTitles": ["в.э.-Сопутствующие Ds текс", "в.э.-Сопутствующие Ds мкб"], "style": "style"}, + {"text": "Сопутствующие заболевания: {}", "cdaTitles": ["в.э.-Пусто"], "style": "style"}, + {"tbl": "Таблица", "cdaTitles": ["в.э.-Сопутствующие табл"], "type": "Сопутствующие", "style": "style"}, {"text": "", "spacer_data": 0.5, "Spacer": "true", "style": "styleCenter"}, {"text": "Дополнительные сведения о заболевании: {}", "cdaTitles": ["в.э.-Дополнительные сведения заболевания"], "style": "style"}, {"text": "", "spacer_data": 0.6, "Spacer": "true", "style": "styleCenter"},