Class: Oddb2tdat
- Inherits:
-
Object
- Object
- Oddb2tdat
- Defined in:
- lib/oddb2tdat.rb
Overview
01 RECA Recordart 001 – 002 2 alpha: 11 02 CMUT Mutationscode 003 – 003 1 num: 3 ausser Handel (AE) sonst 1. If there is no Pharmacode or Gültig bis is before today, CMUT must be 3. 03 PHAR Pharmacode 004 – 010 7 num: Pharmacode (G) 04 ABEZ Artikelbezeichnung 011 – 060 50 alpha: Präparate (H,K) 05 PRMO Arztpreis (=Galexis-Basis-Preis) 061 – 066 6 num: NIL 06 PRPU Publikumspreis (inkl. MWSt) 067 – 072 6 num: PP (N) 07 CKZL Kassenzulässigkeit 073 – 073 1 num: (Q,V)
1 = SL (Q)
2 = LPPV (V)
3 = hors list (No SL, should be 3 not 0)
08 CLAG Lagerart 074 – 074 1 num: NIL 09 CBGG Betäubung - Gift 075 – 075 1 num: (AI) 10 CIKS Swissmedic-Listencode 076 – 076 1 alpha: (P) 11 ITHE Index-Therapeutikus 077 – 083 7 num: (AH) 12 CEAN EAN-Code 084 – 096: 13 num (E) 13 CMWS Mehrwertsteuer-Code 097 - 097 1 num: 2
Constant Summary collapse
- VERSION =
'1.0.8'
- COL =
{ :CMUT => 30, # AE :PHAR => 6, # G :ABEZ => 7, # H :PRMO => 12, # M :PRPU => 13, # N :CKZL1 => 16, # Q :CKZL2 => 21, # V :CBGG => 34, # AI :CIKS => 15, # P :ITHE => 33, # AH :CEAN => 4, # E :PACK => 10, # K :GULT => 23, # X }
- LEN =
X
{ :RECA => 2, :CMUT => 1, :PHAR => 7, :ABEZ => 50, :PRMO => 6, :PRPU => 6, :CKZL => 1, :CLAG => 1, :CBGG => 1, :CIKS => 1, :ITHE => 7, :CEAN => 13, :CMWS => 1, }
- POS =
{ :PHAR => 3, :PRMO => 60, :PRPU => 66, :CEAN => 83, }
Instance Attribute Summary collapse
-
#updated_prmo ⇒ Object
readonly
Returns the value of attribute updated_prmo.
Instance Method Summary collapse
- #expired?(date_str) ⇒ Boolean
- #format_date(date_str, len = 7) ⇒ Object
- #format_price(price_str, len = 6, int_len = 4, frac_len = 2) ⇒ Object
- #import_prmo ⇒ Object
-
#initialize(input, output, import = nil) ⇒ Oddb2tdat
constructor
A new instance of Oddb2tdat.
- #output ⇒ Object
- #parse ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(input, output, import = nil) ⇒ Oddb2tdat
Returns a new instance of Oddb2tdat.
64 65 66 67 68 |
# File 'lib/oddb2tdat.rb', line 64 def initialize(input, output, import=nil) @input = input @output = output @import = import end |
Instance Attribute Details
#updated_prmo ⇒ Object (readonly)
Returns the value of attribute updated_prmo.
147 148 149 |
# File 'lib/oddb2tdat.rb', line 147 def updated_prmo @updated_prmo end |
Instance Method Details
#expired?(date_str) ⇒ Boolean
100 101 102 103 104 105 106 107 |
# File 'lib/oddb2tdat.rb', line 100 def expired?(date_str) d = date_str.split('.') if d.length == 3 d.map!{|i| i.to_i} date = Date.new(d[2],d[1],d[0]) Date.today > date end end |
#format_date(date_str, len = 7) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/oddb2tdat.rb', line 93 def format_date(date_str, len=7) date = date_str.gsub('.','') if date.size < len date = date + '0'*(len-date.size) end date[0,len] end |
#format_price(price_str, len = 6, int_len = 4, frac_len = 2) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/oddb2tdat.rb', line 77 def format_price(price_str, len=6, int_len=4, frac_len=2) price = price_str.split('.') pre = '' las = '' pre = "%0#{int_len}d" % (price[0] ? price[0] : '0') las = if price[1] if price[1].size < frac_len price[1] + "0"*(frac_len-price[2].size) else price[1][0,frac_len] end else '0'*frac_len end (pre.to_s + las.to_s)[0,len] end |
#import_prmo ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/oddb2tdat.rb', line 148 def import_prmo import_ean = {} import_pha = {} File.readlines(@import).each do |line| import_ean.store(line[POS[:CEAN], LEN[:CEAN]], line.chomp) import_pha.store(line[POS[:PHAR], LEN[:PHAR]], line.chomp) end @rows = [] @updated_prmo = 0 File.readlines(@input).each do |line| row = '' if (ean_code = line[POS[:CEAN], LEN[:CEAN]] and line_imp = import_ean[ean_code]) \ or (pharma_code = line[POS[:PHAR], LEN[:PHAR]] and line_imp = import_pha[pharma_code]) row << line[0..(POS[:PRMO]-1)] row << line_imp[POS[:PRMO], LEN[:PRMO]] row << line[POS[:PRPU], 1000].chomp @updated_prmo += 1 else row << line.chomp end @rows << row end output end |
#output ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/oddb2tdat.rb', line 174 def output open(@output, "w") do |out| @rows.each do |line| out.print line, "\n" end end end |
#parse ⇒ Object
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 140 141 142 143 144 145 146 |
# File 'lib/oddb2tdat.rb', line 108 def parse @rows = [] File.open(@input, 'r:iso-8859-1') do |input| while line=input.gets row = '' cols = line.split(/;/) if cmut = cols[COL[:CMUT]] and cmut =~ /Ja/ or cmut =~ /Nein/ row << "%#{LEN[:RECA]}s" % '11' row << "%#{LEN[:CMUT]}s" % if(phar = cols[COL[:PHAR]] and phar.size > 3) or (!expired?(cols[COL[:GULT]])) (cmut =~ /Ja/ ? '3':'1') else '3' end row << "%0#{LEN[:PHAR]}d" % cols[COL[:PHAR]].to_i row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:ABEZ]].to_s.gsub(/"/,'') + " " + cols[COL[:PACK]]).to_s[0,LEN[:ABEZ]].gsub(/"/,'') row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:PRMO]]) row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:PRPU]]) row << "%#{LEN[:CKZL]}s" % if cols[COL[:CKZL1]] =~ /Ja/ 1 elsif cols[COL[:CKZL2]] =~ /Ja/ 2 else 3 end row << "%#{LEN[:CLAG]}s" % 0 row << "%#{LEN[:CBGG]}s" % (cols[COL[:CBGG]] =~ /Ja/ ? 1:0) row << "%#{LEN[:CIKS]}s" % if ciks = cols[COL[:CIKS]] and ciks != '""' ciks else 0 end row << "%#{LEN[:ITHE]}s" % format_date(cols[COL[:ITHE]]) row << "%#{LEN[:CEAN]}s" % cols[COL[:CEAN]] row << "%#{LEN[:CMWS]}s" % '2' @rows << row end end end end |
#run ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/oddb2tdat.rb', line 69 def run parse output if @import @input = @output import_prmo end end |