Created
May 23, 2014 19:52
-
-
Save masonjm/74e15e15d161f29698a3 to your computer and use it in GitHub Desktop.
Example of printing an armband to a ZPL printer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Armband | |
def initialize(encounter, options = {}) | |
@encounter = encounter | |
end | |
def to_zpl(format) | |
# Units are in dots | |
zpl = "^XA" # ZPL Begin | |
zpl << "^LH0,0" # Home position X, Y | |
zpl << "^PON" # Print orientation normal | |
zpl << "^BY2,3,60" # Barcode defaults: width, ratio, height | |
case format.to_sym | |
when :adult | |
zpl << text(@encounter.patient.name.to_s.upcase, 86, 2569, :size => 46) | |
zpl << code128_barcode(@encounter.encounter_number, 254, 2567) | |
zpl << code128_barcode(@encounter.patient.medical_record_number, 56, 1854, :orientation => "N", :height => 75) | |
zpl << centered_text(@encounter.patient.medical_record_number, 40, 1681, 260, :orientation => "I", :size => 46) | |
zpl << text("DOB #{I18n.l(@encounter.patient.date_of_birth)} #{@encounter.patient.long_age} #{@encounter.patient.gender.code}", 134, 2570) | |
zpl << text(@encounter.attending_physician, 181, 2570) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 1223) | |
zpl << centered_text(Configuration.instance.facility_name, 40, 2595, 260, :size => 33, :orientation => "N", :lines => 3) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 1385) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 1898) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 1060) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 898) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 735) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 572) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 410) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 247) | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 2051) | |
zpl << text("FIN: #{@encounter.encounter_number}", 299, 2569, :size => 46) | |
zpl << text("MRN:", 217, 1739, :orientation => "I") | |
zpl << aztec_barcode(@encounter.encounter_number, 197, 1551) | |
when :infant | |
zpl << text(@encounter.patient.name.to_s.upcase, 105, 1992, :size => 33) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 1289) | |
zpl << text("DOB: #{I18n.l(@encounter.patient.date_of_birth)} #{@encounter.patient.gender}", 149, 1992, :size => 33) | |
zpl << text("FIN: #{@encounter.encounter_number}", 202, 1992, :size => 33) | |
zpl << code128_barcode(@encounter.encounter_number, 267, 1995, :height => 54) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 1148) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 1011) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 873) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 739) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 598) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 470) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 342) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 195) | |
zpl << aztec_barcode(@encounter.encounter_number, 128, 1492) | |
when :pediatric | |
zpl << text(@encounter.patient.name.to_s.upcase, 83, 1481, :size => 46) | |
zpl << code128_barcode(@encounter.encounter_number, 251, 1478) | |
zpl << code128_barcode(@encounter.patient.medical_record_number, 53, 766, :orientation => "N", :height => 75) | |
zpl << centered_text(@encounter.patient.medical_record_number, 40, 593, 260, :orientation => "I", :size => 46) | |
zpl << text("DOB #{I18n.l(@encounter.patient.date_of_birth)} #{@encounter.patient.long_age} #{@encounter.patient.gender.code}", 131, 1481) | |
zpl << text(@encounter.attending_physician, 178, 1481) | |
zpl << aztec_barcode(@encounter.encounter_number, 194, 150) | |
zpl << centered_text(Configuration.instance.facility_name, 40, 1507, 260, :size => 33, :orientation => "N", :lines => 3) | |
zpl << aztec_barcode(@encounter.encounter_number, 194, 297) | |
zpl << aztec_barcode(@encounter.encounter_number, 200, 809) | |
zpl << aztec_barcode(@encounter.encounter_number, 200, 962) | |
zpl << text("FIN: #{@encounter.encounter_number}", 296, 1481, :size => 46) | |
zpl << text("MRN:", 214, 651, :orientation => "I") | |
zpl << aztec_barcode(@encounter.encounter_number, 194, 463) | |
when :infant_with_clip | |
zpl << aztec_barcode(@encounter.encounter_number, 184, 472) | |
zpl << code128_barcode(@encounter.encounter_number, 298, 1516) | |
zpl << text("FIN: #{@encounter.encounter_number}", 227, 1516, :size => 46) | |
zpl << text(@encounter.patient.name.to_s.upcase, 80, 1516, :size => 46) | |
zpl << text("DOB: #{I18n.l(@encounter.patient.date_of_birth)} #{@encounter.patient.gender}", 128, 1516) | |
zpl << text(@encounter.attending_physician, 175, 1516) | |
zpl << text(Configuration.instance.facility_name, 68, 681, :size => 33) | |
zpl << aztec_barcode(@encounter.encounter_number, 184, 997) | |
zpl << aztec_barcode(@encounter.encounter_number, 184, 631) | |
zpl << aztec_barcode(@encounter.encounter_number, 184, 316) | |
zpl << aztec_barcode(@encounter.encounter_number, 184, 159) | |
zpl << centered_text(@encounter.patient.medical_record_number, 40, 803, 260, :size => 46, :orientation => "I") | |
zpl << text("MRN:", 203, 867, :size => 42, :orientation => "I") | |
zpl << aztec_barcode(@encounter.encounter_number, 184, 3) | |
end | |
zpl << "^XZ" # ZPL End | |
zpl | |
end | |
alias_method(:to_s, :to_zpl) | |
private | |
def aztec_barcode(data, x, y, options = {}) | |
options[:size] ||= 5 | |
# Field origin x,y | |
# Aztec barcode normal orientation, size | |
"^FO#{x},#{y}^BON,#{options[:size]}^FD#{data}^FS" | |
end | |
def code128_barcode(data, x, y, options = {}) | |
options[:orientation] ||= "B" | |
options[:height] ||= "" | |
# Field typset x, y | |
# Code 128 barcode orientation, height, no interpreation text, not above, no UCC check digit | |
"^FT#{x},#{y}^BC#{options[:orientation]},#{options[:height]},N,N,N^FD#{data}^FS" | |
end | |
def text(data, x, y, options = {}) | |
options[:orientation] ||= "B" | |
options[:size] ||= 38 | |
# scalable font #0 orientation, height, width | |
"^A0#{options[:size]},#{options[:size]}^FT#{x},#{y}^FW#{options[:orientation]}^FD#{data}^FS" | |
end | |
def centered_text(data, x, y, width, options = {}) | |
options[:orientation] ||= "B" | |
options[:size] ||= 38 | |
options[:lines] ||= 1 | |
"^A0#{options[:size]},#{options[:size]}^FO#{x},#{y}^FW#{options[:orientation]}^FB#{width},#{options[:lines]},,C^FD#{data}^FS" | |
end | |
end | |
class ArmbandPrintManager < PrintManager | |
def print(copies = 1) | |
if copies >= 1 && @printer | |
host, port = @printer.device.split(":") | |
port ||= 9100 | |
zpl = Armband.new(@encounter).to_zpl(@printer.armband_size) | |
copies.times do | |
s = TCPSocket.open(host, port) | |
s.puts(zpl) | |
s.close | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment