File size: 5,104 Bytes
6ea020b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!-- templates/print_barcode.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PrintBarcode - {{ patient.patient_id if patient else 'NexLab' }}</title>
    <style>
        @page {
            size: {{ template_data.paper_width if template_data else '4in' }} {{ template_data.paper_height if template_data else '2in' }};
            margin: 0;
        }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Arial', sans-serif;
            background: #f3f4f6;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
        }
        .toolbar {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            background: white;
            padding: 10px 20px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
            z-index: 100;
        }
        .toolbar button {
            padding: 8px 20px;
            border: none;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s;
        }
        .btn-print {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .btn-print:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); }
        .btn-close {
            background: #f3f4f6;
            color: #374151;
        }
        .btn-close:hover { background: #e5e7eb; }
        .barcode-pages {
            margin-top: 60px;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 20px;
        }
        .barcode-page {
            background: white;
            border: 1px solid #d1d5db;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            position: relative;
            overflow: visible;
            width: {{ template_data.paper_width if template_data else '4in' }};
            height: {{ template_data.paper_height if template_data else '2in' }};
        }
        .barcode-page img {
            width: 100%;
            height: 100%;
            display: block;
            image-rendering: pixelated; /* crisp 1-bit barcode rendering */
        }
        .page-label {
            font-size: 12px;
            color: #6b7280;
            margin-bottom: 4px;
            font-weight: 500;
        }
        @media print {
            html, body { background: white; padding: 0 !important; margin: 0 !important; width: 100%; height: 100%; }
            .toolbar { display: none !important; }
            .barcode-pages { margin: 0 !important; padding: 0 !important; gap: 0; display: block; }
            .barcode-page {
                border: none;
                box-shadow: none;
                page-break-after: always;
                margin: 0 !important;
                padding: 0 !important;
                width: 100% !important;
                height: 100% !important;
                position: relative;
                left: 4mm;
                top: -2mm;
            }
            .barcode-page:last-child {
                page-break-after: auto;
            }
            .barcode-page img {
                width: 100% !important;
                height: 100% !important;
                object-fit: fill;
            }
            .page-label { display: none !important; }
        }
    </style>
</head>
<body>
    <!-- Toolbar (hidden during print) -->
    <div class="toolbar">
        <button class="btn-print" onclick="window.print()">🖨️ Print</button>
        <button class="btn-close" onclick="window.close()">✕ Close</button>
    </div>

    <div class="barcode-pages">
        {% if template_data and template_data.elements %}
            <!-- Render one barcode page per sample type using server-generated PNG images -->
            {% set page_index = namespace(val=0) %}
            {% for sample_type, test_names in tests_by_sample_type.items() %}
                <div class="page-label">{{ sample_type }} ({{ test_names | join(', ') }})</div>
                <div class="barcode-page">
                    <img src="/api/print-barcode-image/{{ patient.patient_id }}?print_token={{ print_token }}&page={{ page_index.val }}" 
                         alt="Barcode - {{ sample_type }}">
                </div>
                {% set page_index.val = page_index.val + 1 %}
            {% endfor %}
        {% else %}
            <!-- Fallback: No saved design -->
            <div style="padding: 40px; text-align: center; color: #ef4444;">
                <h2>⚠️ No Barcode Design Found</h2>
                <p>Please create and save a barcode design in the <a href="/print-barcode-designer">Barcode Designer</a> first.</p>
            </div>
        {% endif %}
    </div>
</body>
</html>