Class: Auto12Epl

Inherits:
Object
  • Object
show all
Defined in:
lib/auto12epl.rb

Overview

Generates EPL code that conforms to the Auto12-A standard for specimen labeling

Constant Summary collapse

DPI =
203
LABEL_WIDTH_IN =
2.0
LABEL_HEIGHT_IN =
0.5
FONT_X_DOTS =

font constants

[8, 10, 12, 14, 32].freeze
FONT_Y_DOTS =
[12, 16, 20, 24, 24].freeze
FONT_PAD_DOTS =
2
HEIGHT_MARGIN =

element heights

0.031
HEIGHT_ELEMENT =
0.1
HEIGHT_ELEMENT_SPACE =
0.01
HEIGHT_PID =
0.1
HEIGHT_BARCODE =
0.200
HEIGHT_BARCODE_HUMAN =
0.050
WIDTH_ELEMENT =

element widths

1.94
WIDTH_BARCODE =
1.395
WIDTH_BARCODE_HUMAN =
1.688
L_MARGIN =

margins

0.031
L_MARGIN_BARCODE =
0.25
L_MARGIN_BARCODE_W_STAT =

stat locations

0.200
L_MARGIN_W_STAT =
0.150
STAT_WIDTH_ELEMENT =
1.78
STAT_WIDTH_BARCODE =
1.150
STAT_WIDTH_BARCODE_HUMAN =
1.400
BARCODE_TYPE =

constants for generated EPL code

'1A'
BARCODE_NARROW_WIDTH =
'2'
BARCODE_WIDE_WIDTH =
'2'
BARCODE_ROTATION =
'0'
BARCODE_IS_HUMAN_READABLE =
'N'
ASCII_HORZ_MULT =
1
ASCII_VERT_MULT =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_font = 1, barcode_human_font = 1) ⇒ Auto12Epl

Returns a new instance of Auto12Epl.



60
61
62
63
# File 'lib/auto12epl.rb', line 60

def initialize(element_font = 1, barcode_human_font = 1)
  @element_font = element_font
  @barcode_human_font = barcode_human_font
end

Instance Attribute Details

#barcode_human_fontObject

Returns the value of attribute barcode_human_font.



16
17
18
# File 'lib/auto12epl.rb', line 16

def barcode_human_font
  @barcode_human_font
end

#element_fontObject

Returns the value of attribute element_font.



16
17
18
# File 'lib/auto12epl.rb', line 16

def element_font
  @element_font
end

Instance Method Details

#concatName(last_name, first_name, middle_initial) ⇒ Object



95
96
97
# File 'lib/auto12epl.rb', line 95

def concatName(last_name, first_name, middle_initial)
  "#{last_name}, #{first_name}#{middle_initial.nil? ? '' : " #{middle_initial}"}"
end

#full_justify(pid, dag, font, length) ⇒ Object

Add spaces between the NPID and the dob/age/gender so that line is fully justified



147
148
149
150
151
152
153
154
155
# File 'lib/auto12epl.rb', line 147

def full_justify(pid, dag, font, length)
  max_char = max_characters(font, length)
  spaces_needed = max_char - pid.length - dag.length
  space = ''
  spaces_needed.times do
    space += ' '
  end
  pid + space + dag
end

#generate_ascii_element(x, y, rotation, font, is_reverse, text) ⇒ Object

generate ascii EPL



163
164
165
# File 'lib/auto12epl.rb', line 163

def generate_ascii_element(x, y, rotation, font, is_reverse, text)
  "A#{x},#{y},#{rotation},#{font},#{ASCII_HORZ_MULT},#{ASCII_VERT_MULT},#{is_reverse ? 'R' : 'N'},\"#{text}\""
end

#generate_barcode_element(x, y, height, schema_track) ⇒ Object

generate barcode EPL



168
169
170
171
# File 'lib/auto12epl.rb', line 168

def generate_barcode_element(x, y, height, schema_track)
  schema_track = schema_track.gsub('-', '').strip
  "B#{x},#{y},#{BARCODE_ROTATION},#{BARCODE_TYPE},#{BARCODE_NARROW_WIDTH},#{BARCODE_WIDE_WIDTH},#{height},#{BARCODE_IS_HUMAN_READABLE},\"#{schema_track}\""
end

#generate_epl(last_name, first_name, middle_initial, pid, dob, age, gender, col_date_time, col_name, tests, stat, acc_num, schema_track, arv_number, number_of_copies = print_copies) ⇒ Object

The main function to generate the EPL



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/auto12epl.rb', line 116

def generate_epl(last_name, first_name, middle_initial, pid, dob, age, gender, col_date_time, col_name, tests, stat,
                 acc_num, schema_track, arv_number, number_of_copies = print_copies)
  # Show ARV number only if test contains 'vl' (case insensitive)
  arv_display = tests.match?(/vl/i) ? arv_number : ''
  
  <<~TEXT
    N
    R130,0
    ZT
    S1
    A100,6,0,1,1,1,N,"#{last_name} #{first_name} (#{age})"
    B100,30,0,1A,2,2,37,N,"#{acc_num}"
    A100,80,0,1,1,1,N,"#{acc_num}   #{arv_display}"
    A100,100,0,1,1,1,N,"#{col_date_time}	#{tests}"
    A80,6,1,1,1,1,R," #{stat} "
    P#{number_of_copies}
  TEXT
end

#generate_small_specimen_label(last_name, first_name, gender, col_date_time, tests, acc_num, arv_number, number_of_copies = print_copies) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/auto12epl.rb', line 99

def generate_small_specimen_label(last_name, first_name, gender, col_date_time, tests, acc_num, arv_number, number_of_copies = print_copies)
  arv_display = tests.match?(/vl/i) ? arv_number : ''
  <<~TEXT
    N
    R216,0
    ZT
    S1
    A100,6,0,1,1,1,N,"#{first_name}, #{last_name} - #{gender}"
    B120,40,0,1A,1,2,48,N,"#{acc_num}"
    A100,100,0,1,1,1,N,"#{acc_num}    #{arv_display}"
    A100,118,0,1,1,1,N,"#{col_date_time}"
    A100,140,0,1,1,1,N,"#{tests}"
    P#{number_of_copies}
  TEXT
end

#max_characters(font, length) ⇒ Object

Calculate the number of characters that will fit in a given length



66
67
68
69
70
71
72
# File 'lib/auto12epl.rb', line 66

def max_characters(font, length)
  dots_per_char = FONT_X_DOTS.at(font - 1) + FONT_PAD_DOTS

  num_char = ((length * DPI) / dots_per_char).round_down

  num_char.to_int
end

#pad_stat_w_space(stat) ⇒ Object

Add spaces before and after the stat text so that black bars appear across the left edge of label



136
137
138
139
140
141
142
143
144
# File 'lib/auto12epl.rb', line 136

def pad_stat_w_space(stat)
  num_char = max_characters(@element_font, LABEL_HEIGHT_IN)
  spaces_needed = (num_char - stat.length) / 1
  space = ''
  spaces_needed.times do
    space += ' '
  end
  space + stat + space
end


173
174
175
176
177
# File 'lib/auto12epl.rb', line 173

def print_copies
  property = ::GlobalProperty.find_by(property: 'max.lab.order.print.copies')
  value = property&.property_value&.strip
  value || 3
end

#to_dots(inches) ⇒ Object

convert inches to number of dots using DPI



158
159
160
# File 'lib/auto12epl.rb', line 158

def to_dots(inches)
  (inches * DPI).round
end

#truncate_name(last_name, first_name, middle_initial, is_stat) ⇒ Object

Use basic truncation rule to truncate the name element i.e., if > maxCharacters cutoff and trail with +



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/auto12epl.rb', line 75

def truncate_name(last_name, first_name, middle_initial, is_stat)
  name_max_characters = if is_stat
                          max_characters(@element_font, STAT_WIDTH_ELEMENT)
                        else
                          max_characters(@element_font, WIDTH_ELEMENT)
                        end

  if concatName(last_name, first_name, middle_initial).length > name_max_characters
    # truncate last?
    last_name = "#{last_name[0..11]}+" if last_name.length > 12

    # truncate first?
    if concatName(last_name, first_name, middle_initial).length > name_max_characters && first_name.length > 7
      first_name = "#{first_name[0..7]}+"
    end
  end

  concatName(last_name, first_name, middle_initial)
end