Skip to content

Commit

Permalink
Merge pull request #4552 from mikhailprivalov/specificFieldType
Browse files Browse the repository at this point in the history
spefic field type in json-schema proto
  • Loading branch information
Wellheor1 authored Dec 11, 2024
2 parents 1f52c7a + 7398aff commit a9fd0e2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "Доступ подразделений к изменению услуги(не создание)"
Expand Down
65 changes: 45 additions & 20 deletions results/forms/forms999.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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"<u>{i}</u> - {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))
Expand All @@ -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"<u>{i}</u> - {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('<', '&lt;').replace('>', '&gt;').replace("\n", "<br/>")
v = v.replace('&lt;sub&gt;', '<sub>')
v = v.replace('&lt;/sub&gt;', '</sub>')
v = v.replace('&lt;sup&gt;', '<sup>')
v = v.replace('&lt;/sup&gt;', '</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
1 change: 1 addition & 0 deletions results/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9fd0e2

Please sign in to comment.