Skip to content

Commit

Permalink
SELF_WATERMARKS
Browse files Browse the repository at this point in the history
  • Loading branch information
urchinpro committed Oct 13, 2023
1 parent 1c1ccbd commit 167e37a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions laboratory/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def __getitem__(self, item):
TITLE_RESULT_FORM_USE_HOSPITAL_STAMP = False
QR_CODE_ANKETA = ""
RESULT_LABORATORY_FORM = ""
SELF_WATERMARKS = ""

try:
from laboratory.local_settings import * # noqa: F403,F401
Expand Down
51 changes: 46 additions & 5 deletions results/laboratory_form.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from appconf.manager import SettingManager
from directions.models import Result
from refprocessor.common import RANGE_IN, RANGE_NOT_IN
from utils.flowable import InteractiveTextField, QrCodeSite
Expand Down Expand Up @@ -977,6 +978,9 @@ def lab_form_2(fwb, interactive_text_field, pw, direction, styleSheet, directory
styleLeft = deepcopy(style)
styleLeft.alignment = TA_LEFT

styleLeftFont7 = deepcopy(style)
styleLeftFont7.fontSize = 7

styleCenterBold = deepcopy(styleBold)
styleCenterBold.alignment = TA_CENTER

Expand All @@ -987,7 +991,8 @@ def lab_form_2(fwb, interactive_text_field, pw, direction, styleSheet, directory
styleJustified.leading = 4.5 * mm

styleBackgroundcolor = deepcopy(style)
styleBackgroundcolor.backColor = HexColor(0xFF6666)
# styleBackgroundcolor.backColor = HexColor(0xFF6666)
styleBackgroundcolor.textColor = colors.white
styleBackgroundcolor.alignment = TA_CENTER
styleBackgroundcolor.spaceAfter = 2 * mm

Expand Down Expand Up @@ -1171,7 +1176,7 @@ def lab_form_2(fwb, interactive_text_field, pw, direction, styleSheet, directory
result_is_norm.append(True)
else:
# tmp.append(Paragraph('<font face="FreeSansBold" size="8">' + result + RANGE_NOT_IN.get(sign, "") + "</font>", styleBackgroundcolor))
tmp.append(Paragraph('<font face="FreeSansBold" size="8">' + result + "</font>", styleBackgroundcolor))
tmp.append(Paragraph('<font face="FreeSansBold" size="8">' + result + "*" + "</font>", styleBackgroundcolor))
result_is_norm.append(False)
if not no_units_and_ref:
tmp.append(Paragraph('<font face="FreeSans" size="7">' + get_r(ref) + "</font>", stl))
Expand All @@ -1185,9 +1190,12 @@ def lab_form_2(fwb, interactive_text_field, pw, direction, styleSheet, directory
style_t.add('TOPPADDING', (0, 0), (0, -1), 0)
style_t.add('BOTTOMPADDING', (0, 0), (0, -1), 0)

step = 0
for is_norm in result_is_norm:
if not is_norm:
pass
style_t.add('BACKGROUND', (1, step + 1), (1, step + 1), HexColor(0xFF6666))

step += 1

t = Table(data, colWidths=cw)
t.setStyle(style_t)
Expand All @@ -1210,8 +1218,6 @@ def lab_form_2(fwb, interactive_text_field, pw, direction, styleSheet, directory
]

data.append(tmp)
# if iss.api_app and iss.api_app.name:


cw = (90 * mm, 90 * mm)
t = Table(data, repeatRows=1, colWidths=cw, hAlign='CENTRE')
Expand All @@ -1223,10 +1229,45 @@ def lab_form_2(fwb, interactive_text_field, pw, direction, styleSheet, directory
]
)

t.setStyle(style_t)
t.spaceBefore = 3 * mm
t.spaceAfter = 0
fwb.append(t)

data1 = []
tmp = [
Paragraph(
"* Референсные значения приводятся с учетом возраста, пола, фазы менструального цикла, срока беременности. "
"Результаты исследований не являются диагнозом, необходима консультация специалиста.",
styleLeftFont7),
Paragraph("", styleLeftFont7),
]

data1.append(tmp)

cw = (150 * mm, 20 * mm)
t = Table(data1, repeatRows=1, colWidths=cw, hAlign='LEFT')
style_t = TableStyle(
[
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
('LEFTPADDING', (0, 0), (-1, -1), 2 * mm),
]
)

t.setStyle(style_t)
t.spaceBefore = 3 * mm
t.spaceAfter = 0

fwb.append(t)


return fwb


def self_watermarks_func(canvas_mark):
canvas_mark.line(10 * mm, 10.7 * mm, 200 * mm, 10.7 * mm)
canvas_mark.setFont('FreeSans', 7)
canvas_mark.drawString(120 * mm, 8 * mm, 'Исследования выполнены в {} {} {}'.format(SettingManager.get("org_title"), SettingManager.get("org_www"), SettingManager.get("org_phones") ))
canvas_mark.drawString(15 * mm, 8 * mm, 'Дата печати: {}'.format("13.10.2023 12:15"))
return canvas_mark
10 changes: 8 additions & 2 deletions results/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from directions.models import Issledovaniya, Result, Napravleniya, ParaclinicResult, Recipe, DirectionDocument, DocumentSign
from laboratory.decorators import logged_in_or_token
from laboratory.settings import DEATH_RESEARCH_PK, LK_USER, SYSTEM_AS_VI, QRCODE_OFFSET_SIZE, LEFT_QRCODE_OFFSET_SIZE, GISTOLOGY_RESEARCH_PK, RESEARCHES_NOT_PRINT_FOOTERS, \
RESULT_LABORATORY_FORM
RESULT_LABORATORY_FORM, SELF_WATERMARKS
from laboratory.settings import FONTS_FOLDER
from laboratory.utils import strdate, strtime
from podrazdeleniya.models import Podrazdeleniya
Expand Down Expand Up @@ -357,7 +357,7 @@ def mark_pages(canvas_mark, direction: Napravleniya, qr_data: Optional[str] = No
canvas_mark.drawString(155 * mm, 285 * mm, '{}'.format(" НЕ ПОДТВЕРЖДЕНО "))
canvas_mark.setFont('FreeSans', 12)
canvas_mark.drawString(175 * mm, 281 * mm, '{}'.format("( образец )"))
if not watermarks and not DEATH_RESEARCH_PK and not GISTOLOGY_RESEARCH_PK:
if not watermarks and not DEATH_RESEARCH_PK and not GISTOLOGY_RESEARCH_PK and not SELF_WATERMARKS:
if direction.hospital:
canvas_mark.drawString(55 * mm, 13 * mm, direction.hospital.safe_short_title)
else:
Expand All @@ -378,6 +378,10 @@ def mark_pages(canvas_mark, direction: Napravleniya, qr_data: Optional[str] = No
d = Drawing()
d.add(qr_code)
renderPDF.draw(d, canvas_mark, 20 * mm, 3 * mm)
if SELF_WATERMARKS:
self_watermarks_func = import_string('results.laboratory_form.' + SELF_WATERMARKS)
canvas_mark = self_watermarks_func(canvas_mark)

canvas_mark.restoreState()

count_pages = 0
Expand Down Expand Up @@ -763,6 +767,8 @@ def local_mark_pages(c, _):

if len(pk) == 1 and has_own_form_result:
doc.build(fwb)
elif SELF_WATERMARKS:
doc.build(fwb)
elif len(pk) == 1 and not link_result and not hosp and fwb:
doc.build(fwb, canvasmaker=PageNumCanvas)
elif len(pk) == 1 and not link_result and hosp:
Expand Down

0 comments on commit 167e37a

Please sign in to comment.