From 4fbd8ab74719e930100a025f0c0687e0c0eeccb6 Mon Sep 17 00:00:00 2001 From: sergei kasianenko Date: Wed, 11 Dec 2024 23:17:17 +0800 Subject: [PATCH 1/3] spefic field type in json-schema proto --- directory/models.py | 2 +- results/forms/forms999.py | 57 +++++++++++++++++++++++++-------------- results/sql_func.py | 1 + 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/directory/models.py b/directory/models.py index 964dee728b..dfdd48a00e 100644 --- a/directory/models.py +++ b/directory/models.py @@ -1316,7 +1316,7 @@ class ConstructorEditAccessResearch(models.Model): doctor = models.ForeignKey(DoctorProfile, default=None, null=True, blank=True, verbose_name="Пользователь", on_delete=models.CASCADE, db_index=True) def __str__(self): - return f"{self.research.title} - {self.department.title}" + return f"{self.research.title} - {self.department} {self.doctor}" class Meta: verbose_name = "Доступ подразделений к изменению услуги(не создание)" diff --git a/results/forms/forms999.py b/results/forms/forms999.py index c823dc5d5d..835ac7e3e9 100644 --- a/results/forms/forms999.py +++ b/results/forms/forms999.py @@ -13,6 +13,7 @@ from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont +from results.prepare_data import lab_iss_to_pdf, text_iss_to_pdf, previous_procedure_list_result from results.sql_func import get_paraclinic_result_by_iss @@ -83,6 +84,9 @@ def form_01(direction: Napravleniya, iss: Issledovaniya, fwb, doc, leftnone, use result_data = {i.field_title: i.field_value for i in fields_values} result_data_by_id = {i.field_id: i.field_value for i in fields_values} + result_field_type_by_id = {i.field_id: i.field_type for i in fields_values} + result_field_type_by_title = {i.field_title: i.field_type for i in fields_values} + if current_template_file: with open(current_template_file) as json_file: data = json.load(json_file) @@ -93,35 +97,18 @@ def form_01(direction: Napravleniya, iss: Issledovaniya, fwb, doc, leftnone, use objs = [] if current_template_file: for section in header_paragraphs: - objs = check_section_param(objs, styles_obj, section, result_data, show_title, result_data_by_id) + objs = check_section_param(objs, styles_obj, section, result_data, show_title, result_data_by_id, result_field_type_by_title, result_field_type_by_id) fwb.extend(objs) objs = [] for section in body_paragraphs: - objs = check_section_param(objs, styles_obj, section, result_data, show_title, result_data_by_id) + objs = check_section_param(objs, styles_obj, section, result_data, show_title, result_data_by_id, result_field_type_by_title, result_field_type_by_id) fwb.extend(objs) return fwb -def check_section_param(objs, styles_obj, section, field_titles_value, show_title): - if section.get("Spacer"): - height_spacer = section.get("spacer_data") - objs.append(Spacer(1, height_spacer * mm)) - elif section.get("page_break"): - objs.append(PageBreak()) - elif section.get("text"): - field_titles_sec = section.get("fieldTitles") - data_fields = [f"{i} - {field_titles_value.get(i)}" if i in show_title else field_titles_value.get(i) for i in field_titles_sec if field_titles_value.get(i)] - difference = len(field_titles_sec) - len(data_fields) - if len(data_fields) < len(field_titles_sec): - data_fields = [*data_fields, *["" for count in range(difference)]] - if styles_obj.get(section.get("style")): - objs.append(Paragraph(section.get("text").format(*data_fields), styles_obj[section.get("style")])) - return objs - - -def check_section_param_with_field_id(objs, styles_obj, section, field_titles_value, show_title, field_id_value): +def check_section_param(objs, styles_obj, section, field_titles_value, show_title, field_id_value, result_field_type_by_title, result_field_type_by_id): if section.get("Spacer"): height_spacer = section.get("spacer_data") objs.append(Spacer(1, height_spacer * mm)) @@ -130,15 +117,45 @@ def check_section_param_with_field_id(objs, styles_obj, section, field_titles_va elif section.get("text"): field_titles_sec = section.get("fieldTitles") data_fields = [] + field_type = None for i in field_titles_sec: field_value = "" if field_titles_value.get(i): field_value = field_titles_value.get(i) + field_type = result_field_type_by_title.get(i) elif field_id_value.get(i): field_value = field_id_value.get(i) + field_type = result_field_type_by_id.get(i) + if field_type in [17, 38]: + field_value = prepare_aggr_desc(field_value, field_type) + objs.extend(field_value) + return objs if i in show_title: field_value = f"{i} - {field_value}" data_fields.append(field_value) if styles_obj.get(section.get("style")): objs.append(Paragraph(section.get("text").format(*data_fields), styles_obj[section.get("style")])) return objs + + +def prepare_aggr_desc(field_value, field_type): + v = field_value.replace('<', '<').replace('>', '>').replace("\n", "
") + v = v.replace('<sub>', '') + v = v.replace('</sub>', '') + v = v.replace('<sup>', '') + v = v.replace('</sup>', '') + if field_type == 17: + if v: + v = json.loads(v) + if not v['directions']: + return [] + aggr_text = text_iss_to_pdf(v) + if not aggr_text: + return [] + return aggr_text + if field_type == 38: + previous_procedure_result = previous_procedure_list_result(v) + if not previous_procedure_result: + return [] + return previous_procedure_result + diff --git a/results/sql_func.py b/results/sql_func.py index 184e519cd2..3a8fa9dd2c 100644 --- a/results/sql_func.py +++ b/results/sql_func.py @@ -130,6 +130,7 @@ def get_paraclinic_result_by_iss(pk_iss): SELECT directions_paraclinicresult.value as field_value, directions_paraclinicresult.field_id as field_id, + directions_paraclinicresult.field_type as field_type, directory_paraclinicInputField.title as field_title, directory_paraclinicinputgroups.title as group_title FROM directions_paraclinicresult From ac59af4038e799a7c43e2a328bada2b17610e2e3 Mon Sep 17 00:00:00 2001 From: sergei kasianenko Date: Wed, 11 Dec 2024 23:27:38 +0800 Subject: [PATCH 2/3] type_ field 16 --- results/forms/forms999.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/results/forms/forms999.py b/results/forms/forms999.py index 835ac7e3e9..12b17ca1cd 100644 --- a/results/forms/forms999.py +++ b/results/forms/forms999.py @@ -126,7 +126,7 @@ def check_section_param(objs, styles_obj, section, field_titles_value, show_titl elif field_id_value.get(i): field_value = field_id_value.get(i) field_type = result_field_type_by_id.get(i) - if field_type in [17, 38]: + if field_type in [17, 38, 16]: field_value = prepare_aggr_desc(field_value, field_type) objs.extend(field_value) return objs @@ -159,3 +159,12 @@ def prepare_aggr_desc(field_value, field_type): return [] return previous_procedure_result + if field_type == 16: + v = json.loads(v) + if not v['directions']: + return [] + aggr_lab = lab_iss_to_pdf(v) + if not aggr_lab: + return [] + return aggr_lab + From 7398aff5a2a3ff8fd6ad47aa998c008f069ac11c Mon Sep 17 00:00:00 2001 From: sergei kasianenko Date: Wed, 11 Dec 2024 23:28:21 +0800 Subject: [PATCH 3/3] fix --- results/forms/forms999.py | 1 - 1 file changed, 1 deletion(-) diff --git a/results/forms/forms999.py b/results/forms/forms999.py index 12b17ca1cd..7bc45cfc4d 100644 --- a/results/forms/forms999.py +++ b/results/forms/forms999.py @@ -167,4 +167,3 @@ def prepare_aggr_desc(field_value, field_type): if not aggr_lab: return [] return aggr_lab -