Skip to content

Commit

Permalink
add watermarls to reports and labels during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Nov 23, 2024
1 parent c1aa827 commit e8a8651
Show file tree
Hide file tree
Showing 20 changed files with 410 additions and 196 deletions.
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ Create new stock from an existing stock item. The container of the new stock ite
For example, create bottles of 128 tabs from a single bulk barrel of tablets.


User Testing
============

Watermarks
++++++++++

Print a watermark on labels during UAT deployments

.. code-block:: python
EDC_PHARMACY_LABEL_WATERMARK_WORD = "DO NOT USE"
See also `pylabels2 <https://github.com/erikvw/pylabels2>`__.

Print watermark on reports during UAT deployments

.. code-block:: python
EDC_PDF_REPORTS_WATERMARK_WORD = "SAMPLE"
EDC_PDF_REPORTS_WATERMARK_FONT = ("Helvetica", 100)
See also `edc-pdf-reports <https://github.com/clinicedc/edc-pdf-reports>`__.


.. |pypi| image:: https://img.shields.io/pypi/v/edc-pharmacy.svg
:target: https://pypi.python.org/pypi/edc-pharmacy
Expand Down
25 changes: 24 additions & 1 deletion edc_pharmacy/admin/medication/formulation_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,23 @@ class FormulationAdmin(ModelAdminMixin, admin.ModelAdmin):
"units",
"formulation_type",
"route",
"notes",
"description",
)
},
),
(
"Investigational medicinal product",
{
"fields": (
"imp",
"imp_description",
)
},
),
(
"Notes",
{"fields": ("notes",)},
),
audit_fieldset_tuple,
)

Expand All @@ -41,6 +54,16 @@ class FormulationAdmin(ModelAdminMixin, admin.ModelAdmin):
}

list_filter: Tuple[str, ...] = (
"imp",
"strength",
"units",
"formulation_type",
"route",
)

list_display = (
"description",
"medication",
"strength",
"units",
"formulation_type",
Expand Down
2 changes: 1 addition & 1 deletion edc_pharmacy/labels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .draw_bulk_stock_label_code39 import draw_bulk_stock_label_code39
from .draw_bulk_stock_label_code128 import draw_bulk_stock_label_code128
from .draw_label_watermark import draw_label_watermark
from .draw_patient_stock_label_code128 import draw_patient_stock_label_code128
from .draw_vertical_barcode_only_code128 import draw_vertical_barcode_only_code128
from .label_data import LabelData
from .print_sheets import print_sheets
4 changes: 4 additions & 0 deletions edc_pharmacy/labels/draw_bulk_stock_label_code128.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from reportlab.graphics.shapes import Drawing, String

from ..utils import format_qty
from .draw_label_watermark import draw_label_watermark

if TYPE_CHECKING:
from ..models import Stock
Expand All @@ -21,6 +22,9 @@ def draw_bulk_stock_label_code128(
"""Callable to draw a single study medication label given a model
instance `obj`
"""

draw_label_watermark(label, width, height, fontSize=18)

text = str(ResearchProtocolConfig().protocol_name)
qty = format_qty(obj.container.qty, obj.container)
br = BarcodeCode128(humanReadable=True, barHeight=30, barWidth=0.7, gap=1.7)
Expand Down
20 changes: 20 additions & 0 deletions edc_pharmacy/labels/draw_label_watermark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.conf import settings
from reportlab.graphics.shapes import Group, String
from reportlab.lib import colors


def draw_label_watermark(label, width, height, **string_options):
if word := getattr(settings, "EDC_PHARMACY_LABEL_WATERMARK_WORD", None):
string_opts = dict(
fontName="Helvetica",
fontSize=28,
textAnchor="middle",
fillColor=colors.Color(0.5, 0.5, 0.5, alpha=0.7),
)
string_opts.update(string_options)
text_group = Group()
watermark = String(height / 2, 10, word, **string_opts)
text_group.add(watermark)
text_group.translate(width / 3, height - height * 0.95)
text_group.rotate(45)
label.add(text_group)
4 changes: 4 additions & 0 deletions edc_pharmacy/labels/draw_patient_stock_label_code128.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from reportlab.graphics.shapes import Drawing, String

from ..utils import format_qty
from .draw_label_watermark import draw_label_watermark

if TYPE_CHECKING:
from ..models import Stock
Expand All @@ -21,6 +22,9 @@ def draw_patient_stock_label_code128(
"""Callable to draw a single study medication label given a model
instance `obj`
"""

draw_label_watermark(label, width, height)

br = BarcodeCode128(humanReadable=True, barHeight=30, barWidth=0.7, gap=1.7)
br.value = obj.code
br.x = 0
Expand Down
3 changes: 3 additions & 0 deletions edc_pharmacy/labels/draw_vertical_barcode_only_code128.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from reportlab.pdfbase.pdfmetrics import stringWidth

from ..utils import format_qty
from .draw_label_watermark import draw_label_watermark

if TYPE_CHECKING:
from ..models import Stock
Expand All @@ -20,6 +21,8 @@ def draw_vertical_barcode_only_code128(
obj: Stock,
) -> Drawing:

draw_label_watermark(label, width, height)

br = BarcodeCode128(humanReadable=True, barHeight=30, barWidth=0.7, gap=1.7)
br.value = obj.code
br.x = 0
Expand Down
96 changes: 0 additions & 96 deletions edc_pharmacy/labels/print_sheets.py

This file was deleted.

Empty file removed edc_pharmacy/labels/utils.py
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.1.2 on 2024-11-22 13:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"edc_pharmacy",
"0051_alter_historicalstocktransferconfirmationitem_options_and_more",
),
]

operations = [
migrations.AddField(
model_name="formulation",
name="imp",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="formulation",
name="imp_description",
field=models.CharField(blank=True, max_length=250, null=True),
),
migrations.AddField(
model_name="historicalformulation",
name="imp",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="historicalformulation",
name="imp_description",
field=models.CharField(blank=True, max_length=250, null=True),
),
]
14 changes: 12 additions & 2 deletions edc_pharmacy/models/medication/formulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Formulation(BaseUuidModel):

description = models.CharField(max_length=250, null=True, blank=True)

imp = models.BooleanField(default=False)

imp_description = models.CharField(max_length=250, null=True, blank=True)

objects = Manager()

history = HistoricalRecords()
Expand All @@ -56,21 +60,27 @@ def natural_key(self):

def save(self, *args, **kwargs):
self.description = self.get_description()
if not self.imp:
self.imp_description = None
else:
self.imp_description = (
self.imp_description if self.imp_description else self.description
)
super().save(*args, **kwargs)

def get_description(self):
return (
f"{self.medication} {round_half_away_from_zero(self.strength, 0)}"
f"{self.get_units_display()} "
f"{self.get_formulation_type_display()} "
# f"{self.get_formulation_type_display()} "
f"{self.get_route_display()}"
)

def get_product_description(self):
return (
f"{self.medication} {round_half_away_from_zero(self.strength, 0)}"
f"{self.get_units_display()} "
f"{self.get_formulation_type_display()} "
# f"{self.get_formulation_type_display()} "
)

def get_description_with_assignment(self, assignment: Assignment) -> str:
Expand Down
Loading

0 comments on commit e8a8651

Please sign in to comment.