class Auto12Epl
Generates EPL code that conforms to the Auto12-A standard for specimen labeling
Constants
- ASCII_HORZ_MULT
- ASCII_VERT_MULT
- BARCODE_IS_HUMAN_READABLE
- BARCODE_NARROW_WIDTH
- BARCODE_ROTATION
- BARCODE_TYPE
constants for generated EPL code
- BARCODE_WIDE_WIDTH
- DPI
- FONT_PAD_DOTS
- FONT_X_DOTS
font constants
- FONT_Y_DOTS
- HEIGHT_BARCODE
- HEIGHT_BARCODE_HUMAN
- HEIGHT_ELEMENT
- HEIGHT_ELEMENT_SPACE
- HEIGHT_MARGIN
element heights
- HEIGHT_PID
- LABEL_HEIGHT_IN
- LABEL_WIDTH_IN
- L_MARGIN
margins
- L_MARGIN_BARCODE
- L_MARGIN_BARCODE_W_STAT
stat locations
- L_MARGIN_W_STAT
- STAT_WIDTH_BARCODE
- STAT_WIDTH_BARCODE_HUMAN
- STAT_WIDTH_ELEMENT
- WIDTH_BARCODE
- WIDTH_BARCODE_HUMAN
- WIDTH_ELEMENT
element widths
Attributes
barcode_human_font[RW]
element_font[RW]
Public Class Methods
new(element_font = 1, barcode_human_font = 1)
click to toggle source
# File lib/auto12epl.rb, line 62 def initialize(element_font = 1, barcode_human_font = 1) @element_font = element_font @barcode_human_font = barcode_human_font end
Public Instance Methods
concatName(last_name, first_name, middle_initial)
click to toggle source
# File lib/auto12epl.rb, line 101 def concatName(last_name, first_name, middle_initial) last_name + ', ' + first_name + (middle_initial == nil ? '' : ' ' + middle_initial) end
full_justify(pid, dag, font, length)
click to toggle source
Add spaces between the NPID and the dob/age/gender so that line is fully justified
# File lib/auto12epl.rb, line 155 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 = space + ' ' end pid + space + dag end
generate_ascii_element(x, y, rotation, font, is_reverse, text)
click to toggle source
generate ascii EPL
# File lib/auto12epl.rb, line 171 def generate_ascii_element(x, y, rotation, font, is_reverse, text) "A#{x.to_s},#{y.to_s},#{rotation.to_s},#{font.to_s},#{ASCII_HORZ_MULT},#{ASCII_VERT_MULT},#{is_reverse ? 'R' : 'N'},\"#{text}\"" end
generate_barcode_element(x, y, height, schema_track)
click to toggle source
generate barcode EPL
# File lib/auto12epl.rb, line 176 def generate_barcode_element(x, y, height, schema_track) schema_track = schema_track.gsub("-", "").strip "B#{x.to_s},#{y.to_s},#{BARCODE_ROTATION},#{BARCODE_TYPE},#{BARCODE_NARROW_WIDTH},#{BARCODE_WIDE_WIDTH},#{height.to_s},#{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)
click to toggle source
The main function to generate the EPL
# File lib/auto12epl.rb, line 106 def generate_epl(last_name, first_name, middle_initial, pid, dob, age, gender, col_date_time, col_name, tests, stat, acc_num, schema_track) # format text and set margin if stat == nil name_text = truncate_name(last_name, first_name, middle_initial, false) pid_dob_age_gender_text = full_justify(pid, dob + ' ' + age + ' ' + gender, @element_font, WIDTH_ELEMENT) l_margin = L_MARGIN l_margin_barcode = L_MARGIN_BARCODE else name_text = truncate_name(last_name, first_name, middle_initial, true) pid_dob_age_gender_text = full_justify(pid, dob + ' ' + age + ' ' + gender, @element_font, STAT_WIDTH_ELEMENT) stat_element_text = pad_stat_w_space(stat) l_margin = L_MARGIN_W_STAT l_margin_barcode = L_MARGIN_BARCODE_W_STAT end barcode_human_text = "#{acc_num} * #{schema_track.gsub(/\-/i, '')}" collector_element_text = "Col: #{col_date_time} #{col_name}" tests_element_text = tests # generate EPL statements name_element = generate_ascii_element(to_dots(l_margin), to_dots(HEIGHT_MARGIN), 0, @element_font, false, name_text) pid_dob_age_gender_element = generate_ascii_element(to_dots(l_margin), to_dots(HEIGHT_MARGIN + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE), 0, @element_font, false, pid_dob_age_gender_text) barcode_human_element = generate_ascii_element(to_dots(l_margin_barcode), to_dots(HEIGHT_MARGIN + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_BARCODE), 0, @barcode_human_font, false, barcode_human_text) collector_element = generate_ascii_element(to_dots(l_margin), to_dots(HEIGHT_MARGIN + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_BARCODE + HEIGHT_BARCODE_HUMAN + HEIGHT_ELEMENT_SPACE), 0, @element_font, false, collector_element_text) tests_element = generate_ascii_element(to_dots(l_margin), to_dots(HEIGHT_MARGIN + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_BARCODE + HEIGHT_BARCODE_HUMAN + HEIGHT_ELEMENT_SPACE + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE), 0, @element_font, false, tests_element_text) barcode_element = generate_barcode_element(to_dots(l_margin_barcode), to_dots(HEIGHT_MARGIN + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE + HEIGHT_ELEMENT + HEIGHT_ELEMENT_SPACE), to_dots(HEIGHT_BARCODE)-4, schema_track) stat_element = generate_ascii_element(to_dots(L_MARGIN)+FONT_Y_DOTS.at(@element_font - 1)+FONT_PAD_DOTS, to_dots(HEIGHT_MARGIN), 1, @element_font, true, stat_element_text) # combine EPL statements if stat == nil "\nN\nR216,0\nZT\nS1\n#{name_element}\n#{pid_dob_age_gender_element}\n#{barcode_element}\n#{barcode_human_element}\n#{collector_element}\n#{tests_element}\nP3\n" else "\nN\nR216,0\nZT\nS1\n#{name_element}\n#{pid_dob_age_gender_element}\n#{barcode_element}\n#{barcode_human_element}\n#{collector_element}\n#{tests_element}\n#{stat_element}\nP3\n" end end
max_characters(font, length)
click to toggle source
Calculate the number of characters that will fit in a given length
# File lib/auto12epl.rb, line 68 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)
click to toggle source
Add spaces before and after the stat text so that black bars appear across the left edge of label
# File lib/auto12epl.rb, line 144 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 = space + ' ' end space + stat + space end
to_dots(inches)
click to toggle source
convert inches to number of dots using DPI
# File lib/auto12epl.rb, line 166 def to_dots(inches) (inches * DPI).round end
truncate_name(last_name, first_name, middle_initial, is_stat)
click to toggle source
Use basic truncation rule to truncate the name element i.e., if > maxCharacters cutoff and trail with +
# File lib/auto12epl.rb, line 78 def truncate_name(last_name, first_name, middle_initial, is_stat) if is_stat name_max_characters = max_characters(@element_font, STAT_WIDTH_ELEMENT) else name_max_characters = max_characters(@element_font, WIDTH_ELEMENT) end if concatName(last_name, first_name, middle_initial).length > name_max_characters # truncate last? if last_name.length > 12 last_name = last_name[0..11] + '+' end # 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