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..7bc45cfc4d 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,53 @@ 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, 16]:
+ 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
+
+ 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
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