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.9'
- COL =
{ :ODDB => { :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 }, :MIGEL => { :PHAR => 1, # G :ABEZ => 3, # H :PRMO => 6, # M :PRPU => 7, # N :CEAN => 2, # E } }
- LEN =
{ :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
-
#target ⇒ Object
Returns the value of attribute target.
-
#transfer ⇒ Object
Returns the value of attribute transfer.
-
#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, *options) ⇒ Oddb2tdat
constructor
A new instance of Oddb2tdat.
- #output ⇒ Object
- #parse ⇒ Object
- #parse_migel ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(input, output, *options) ⇒ Oddb2tdat
Returns a new instance of Oddb2tdat.
76 77 78 79 80 81 82 83 |
# File 'lib/oddb2tdat.rb', line 76 def initialize(input, output, *) @target = [:oddb] @transfer = false @import = nil @input = input @output = output @options = end |
Instance Attribute Details
#target ⇒ Object
Returns the value of attribute target.
74 75 76 |
# File 'lib/oddb2tdat.rb', line 74 def target @target end |
#transfer ⇒ Object
Returns the value of attribute transfer.
74 75 76 |
# File 'lib/oddb2tdat.rb', line 74 def transfer @transfer end |
#updated_prmo ⇒ Object (readonly)
Returns the value of attribute updated_prmo.
75 76 77 |
# File 'lib/oddb2tdat.rb', line 75 def updated_prmo @updated_prmo end |
Instance Method Details
#expired?(date_str) ⇒ Boolean
120 121 122 123 124 125 126 127 |
# File 'lib/oddb2tdat.rb', line 120 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
113 114 115 116 117 118 119 |
# File 'lib/oddb2tdat.rb', line 113 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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/oddb2tdat.rb', line 97 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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/oddb2tdat.rb', line 200 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
226 227 228 229 230 231 232 |
# File 'lib/oddb2tdat.rb', line 226 def output open(@output, "w") do |out| @rows.each do |line| out.print line, "\n" end end end |
#parse ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/oddb2tdat.rb', line 128 def parse @rows = [] File.open(@input, 'r:iso-8859-1') do |input| while line=input.gets row = '' cols = line.split(/;/) if cmut = cols[COL[:ODDB][:CMUT]] and cmut =~ /Ja/ or cmut =~ /Nein/ row << "%#{LEN[:RECA]}s" % '11' row << "%#{LEN[:CMUT]}s" % if(phar = cols[COL[:ODDB][:PHAR]] and phar.size > 3) or (!expired?(cols[COL[:ODDB][:GULT]])) (cmut =~ /Ja/ ? '3':'1') else '3' end row << "%0#{LEN[:PHAR]}d" % cols[COL[:ODDB][:PHAR]].to_i row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:ODDB][:ABEZ]].to_s.gsub(/"/,'') + " " + cols[COL[:ODDB][:PACK]]).to_s[0,LEN[:ABEZ]].gsub(/"/,'') row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:ODDB][:PRMO]]) row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:ODDB][:PRPU]]) row << "%#{LEN[:CKZL]}s" % if cols[COL[:ODDB][:CKZL1]] =~ /Ja/ 1 elsif cols[COL[:ODDB][:CKZL2]] =~ /Ja/ 2 else 3 end row << "%#{LEN[:CLAG]}s" % 0 row << "%#{LEN[:CBGG]}s" % (cols[COL[:ODDB][:CBGG]] =~ /Ja/ ? 1:0) row << "%#{LEN[:CIKS]}s" % if ciks = cols[COL[:ODDB][:CIKS]] and ciks != '""' ciks else 0 end row << "%#{LEN[:ITHE]}s" % format_date(cols[COL[:ODDB][:ITHE]]) row << "%#{LEN[:CEAN]}s" % cols[COL[:ODDB][:CEAN]] row << "%#{LEN[:CMWS]}s" % '2' @rows << row end end end end |
#parse_migel ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/oddb2tdat.rb', line 167 def parse_migel return if @rows.empty? File.open(@input, 'r:utf-8:iso-8859-1') do |input| while line=input.gets row = '' cols = line.split(/,/) if cols[COL[:MIGEL][:CEAN]].length == LEN[:CEAN] row << "%#{LEN[:RECA]}s" % '11' row << "%#{LEN[:CMUT]}s" % if (phar = cols[COL[:MIGEL][:PHAR]] and phar.size > 3) '1' else '3' end row << "%0#{LEN[:PHAR]}d" % cols[COL[:MIGEL][:PHAR]].to_i row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:MIGEL][:ABEZ]].to_s.gsub(/"/,'')).to_s[0,LEN[:ABEZ]].gsub(/"/,'') row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:MIGEL][:PRMO]].to_i.to_s) if cols[COL[:MIGEL][:PRMO]] row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:MIGEL][:PRPU]].to_i.to_s) if cols[COL[:MIGEL][:PRPU]] row << "%#{LEN[:CKZL]}s" % 3 row << "%#{LEN[:CLAG]}s" % 0 row << "%#{LEN[:CBGG]}s" % 0 row << "%#{LEN[:CIKS]}s" % 0 row << "%0#{LEN[:ITHE]}d" % 0 row << "%0#{LEN[:CEAN]}d" % if (ean = cols[COL[:MIGEL][:CEAN]] and !ean.empty?) ean.to_i else 0 end row << "%#{LEN[:CMWS]}s" % '2' @rows << row end end end end |
#run ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/oddb2tdat.rb', line 84 def run parse if @target.include?(:migel) @input = @options.first parse_migel end output if @transfer @import = @options.last @input = @output import_prmo end end |