oddb2tdat 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/History.txt +4 -0
  2. data/bin/oddb2tdat +29 -5
  3. data/lib/oddb2tdat.rb +99 -47
  4. metadata +6 -6
@@ -1,3 +1,7 @@
1
+ === 1.0.9 / 16.03.2012
2
+
3
+ * Updated for migel.csv support.
4
+
1
5
  === 1.0.8 / 07.03.2012
2
6
 
3
7
  * Do not convert to iso-8859-1 as the input is already iso-8859-1.
@@ -8,18 +8,42 @@ def usage
8
8
  #$0 ver.#{Oddb2tdat::VERSION}
9
9
  Usage:
10
10
  #$0 <input file (oddb.csv)> <output file (oddb.dat)>
11
- or
12
- #$0 <input file (oddb.csv)> <output file (oddb.dat)> <transfer file (trasfer.dat)>
11
+ #$0 <input file (oddb.csv)> <output file (oddb.dat)> <transfer file (transfer.dat)>
12
+ #$0 <input file (oddb.csv)> <output file (oddb.dat)> <optional input file (migel.csv)>
13
+ #$0 <input file (oddb.csv)> <output file (oddb.dat)> <optional input file (migel.csv)> <transfer file (transfer.dat)>
13
14
 
14
15
  EOS
15
16
  end
16
17
 
17
- if ARGV.length < 2 or !File.exist?(ARGV[0]) or (ARGV[2] and !File.exist?(ARGV[2]))
18
+ transfer = false
19
+ migel = false
20
+ valid = false
21
+ if !ARGV.empty? and File.exist?(ARGV[0])
22
+ case ARGV.length
23
+ when 2
24
+ valid = true
25
+ when 3
26
+ valid = true if File.exist?(ARGV[2])
27
+ if File.extname(ARGV[2]) == '.csv'
28
+ migel = true
29
+ else
30
+ transfer = true
31
+ end
32
+ when 4
33
+ valid = true if (File.exist?(ARGV[2]) and File.exist?(ARGV[3]))
34
+ migel = true
35
+ transfer = true
36
+ end
37
+ end
38
+
39
+ unless valid
18
40
  usage
19
41
  exit
20
42
  end
21
43
 
22
44
  app = Oddb2tdat.new(*ARGV)
45
+ app.transfer = transfer
46
+ if (migel)
47
+ app.target.push(:migel)
48
+ end
23
49
  app.run
24
-
25
-
@@ -1,43 +1,54 @@
1
1
  #! /usr/bin/env ruby
2
2
  # encoding: utf-8
3
+ # Oddb2tdat -- 16.03.2012 -- yasaka@ywesee.com
3
4
  # Oddb2tdat -- 15.02.2012 -- mhatakeyama@ywesee.com
4
5
 
5
6
  require 'date'
6
7
  =begin
7
- 01 RECA Recordart 001 – 002 2 alpha: 11
8
- 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.
9
- 03 PHAR Pharmacode 004 010 7 num: Pharmacode (G)
10
- 04 ABEZ Artikelbezeichnung 011 060 50 alpha: Präparate (H,K)
11
- 05 PRMO Arztpreis (=Galexis-Basis-Preis) 061 066 6 num: NIL
12
- 06 PRPU Publikumspreis (inkl. MWSt) 067072 6 num: PP (N)
13
- 07 CKZL Kassenzulässigkeit 073073 1 num: (Q,V)
8
+ 01 RECA Recordart 001 – 002 2 alpha: 11
9
+ 02 CMUT Mutationscode 003 – 003 1 num: 3 ausser Handel (AE) sonst 1.
10
+ If there is no Pharmacode or Gültig bis is before today, CMUT must be 3.
11
+ 03 PHAR Pharmacode 004010 7 num: Pharmacode (G)
12
+ 04 ABEZ Artikelbezeichnung 011060 50 alpha: Präparate (H,K)
13
+ 05 PRMO Arztpreis (=Galexis-Basis-Preis) 061066 6 num: NIL
14
+ 06 PRPU Publikumspreis (inkl. MWSt) 067 072 6 num: PP (N)
15
+ 07 CKZL Kassenzulässigkeit 073 – 073 1 num: (Q,V)
14
16
  1 = SL (Q)
15
17
  2 = LPPV (V)
16
18
  3 = hors list (No SL, should be 3 not 0)
17
- 08 CLAG Lagerart 074 – 074 1 num: NIL
18
- 09 CBGG Betäubung - Gift 075 – 075 1 num: (AI)
19
- 10 CIKS Swissmedic-Listencode 076 – 076 1 alpha: (P)
20
- 11 ITHE Index-Therapeutikus 077 – 083 7 num: (AH)
21
- 12 CEAN EAN-Code 084 – 096: 13 num (E)
22
- 13 CMWS Mehrwertsteuer-Code 097 - 097 1 num: 2
19
+ 08 CLAG Lagerart 074 – 074 1 num: NIL
20
+ 09 CBGG Betäubung - Gift 075 – 075 1 num: (AI)
21
+ 10 CIKS Swissmedic-Listencode 076 – 076 1 alpha: (P)
22
+ 11 ITHE Index-Therapeutikus 077 – 083 7 num: (AH)
23
+ 12 CEAN EAN-Code 084 – 096 13 num: (E)
24
+ 13 CMWS Mehrwertsteuer-Code 097 - 097 1 num: 2
23
25
  =end
24
26
 
25
27
  class Oddb2tdat
26
- VERSION = '1.0.8'
28
+ VERSION = '1.0.9'
27
29
  COL = {
28
- :CMUT => 30, # AE
29
- :PHAR => 6, # G
30
- :ABEZ => 7, # H
31
- :PRMO => 12, # M
32
- :PRPU => 13, # N
33
- :CKZL1 => 16, # Q
34
- :CKZL2 => 21, # V
35
- :CBGG => 34, # AI
36
- :CIKS => 15, # P
37
- :ITHE => 33, # AH
38
- :CEAN => 4, # E
39
- :PACK => 10, # K
40
- :GULT => 23, # X
30
+ :ODDB => {
31
+ :CMUT => 30, # AE
32
+ :PHAR => 6, # G
33
+ :ABEZ => 7, # H
34
+ :PRMO => 12, # M
35
+ :PRPU => 13, # N
36
+ :CKZL1 => 16, # Q
37
+ :CKZL2 => 21, # V
38
+ :CBGG => 34, # AI
39
+ :CIKS => 15, # P
40
+ :ITHE => 33, # AH
41
+ :CEAN => 4, # E
42
+ :PACK => 10, # K
43
+ :GULT => 23, # X
44
+ },
45
+ :MIGEL => {
46
+ :PHAR => 1, # G
47
+ :ABEZ => 3, # H
48
+ :PRMO => 6, # M
49
+ :PRPU => 7, # N
50
+ :CEAN => 2, # E
51
+ }
41
52
  }
42
53
  LEN = {
43
54
  :RECA => 2,
@@ -60,17 +71,26 @@ class Oddb2tdat
60
71
  :PRPU => 66,
61
72
  :CEAN => 83,
62
73
  }
63
-
64
- def initialize(input, output, import=nil)
65
- @input = input
66
- @output = output
67
- @import = import
74
+ attr_accessor :target, :transfer
75
+ attr_reader :updated_prmo
76
+ def initialize(input, output, *options)
77
+ @target = [:oddb]
78
+ @transfer = false
79
+ @import = nil
80
+ @input = input
81
+ @output = output
82
+ @options = options
68
83
  end
69
84
  def run
70
85
  parse
86
+ if @target.include?(:migel)
87
+ @input = @options.first
88
+ parse_migel
89
+ end
71
90
  output
72
- if @import
73
- @input = @output
91
+ if @transfer
92
+ @import = @options.last
93
+ @input = @output
74
94
  import_prmo
75
95
  end
76
96
  end
@@ -111,40 +131,72 @@ class Oddb2tdat
111
131
  while line=input.gets
112
132
  row = ''
113
133
  cols = line.split(/;/)
114
- if cmut = cols[COL[:CMUT]] and cmut =~ /Ja/ or cmut =~ /Nein/
134
+ if cmut = cols[COL[:ODDB][:CMUT]] and cmut =~ /Ja/ or cmut =~ /Nein/
115
135
  row << "%#{LEN[:RECA]}s" % '11'
116
- row << "%#{LEN[:CMUT]}s" % if(phar = cols[COL[:PHAR]] and phar.size > 3) or (!expired?(cols[COL[:GULT]]))
136
+ row << "%#{LEN[:CMUT]}s" % if(phar = cols[COL[:ODDB][:PHAR]] and phar.size > 3) or (!expired?(cols[COL[:ODDB][:GULT]]))
117
137
  (cmut =~ /Ja/ ? '3':'1')
118
138
  else
119
139
  '3'
120
140
  end
121
- row << "%0#{LEN[:PHAR]}d" % cols[COL[:PHAR]].to_i
122
- row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:ABEZ]].to_s.gsub(/"/,'') + " " + cols[COL[:PACK]]).to_s[0,LEN[:ABEZ]].gsub(/"/,'')
123
- row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:PRMO]])
124
- row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:PRPU]])
125
- row << "%#{LEN[:CKZL]}s" % if cols[COL[:CKZL1]] =~ /Ja/
141
+ row << "%0#{LEN[:PHAR]}d" % cols[COL[:ODDB][:PHAR]].to_i
142
+ row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:ODDB][:ABEZ]].to_s.gsub(/"/,'') + " " + cols[COL[:ODDB][:PACK]]).to_s[0,LEN[:ABEZ]].gsub(/"/,'')
143
+ row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:ODDB][:PRMO]])
144
+ row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:ODDB][:PRPU]])
145
+ row << "%#{LEN[:CKZL]}s" % if cols[COL[:ODDB][:CKZL1]] =~ /Ja/
126
146
  1
127
- elsif cols[COL[:CKZL2]] =~ /Ja/
147
+ elsif cols[COL[:ODDB][:CKZL2]] =~ /Ja/
128
148
  2
129
149
  else
130
150
  3
131
151
  end
132
152
  row << "%#{LEN[:CLAG]}s" % 0
133
- row << "%#{LEN[:CBGG]}s" % (cols[COL[:CBGG]] =~ /Ja/ ? 1:0)
134
- row << "%#{LEN[:CIKS]}s" % if ciks = cols[COL[:CIKS]] and ciks != '""'
153
+ row << "%#{LEN[:CBGG]}s" % (cols[COL[:ODDB][:CBGG]] =~ /Ja/ ? 1:0)
154
+ row << "%#{LEN[:CIKS]}s" % if ciks = cols[COL[:ODDB][:CIKS]] and ciks != '""'
135
155
  ciks
136
156
  else
137
157
  0
138
158
  end
139
- row << "%#{LEN[:ITHE]}s" % format_date(cols[COL[:ITHE]])
140
- row << "%#{LEN[:CEAN]}s" % cols[COL[:CEAN]]
159
+ row << "%#{LEN[:ITHE]}s" % format_date(cols[COL[:ODDB][:ITHE]])
160
+ row << "%#{LEN[:CEAN]}s" % cols[COL[:ODDB][:CEAN]]
161
+ row << "%#{LEN[:CMWS]}s" % '2'
162
+ @rows << row
163
+ end
164
+ end
165
+ end
166
+ end
167
+ def parse_migel
168
+ return if @rows.empty?
169
+ File.open(@input, 'r:utf-8:iso-8859-1') do |input|
170
+ while line=input.gets
171
+ row = ''
172
+ cols = line.split(/,/)
173
+ if cols[COL[:MIGEL][:CEAN]].length == LEN[:CEAN]
174
+ row << "%#{LEN[:RECA]}s" % '11'
175
+ row << "%#{LEN[:CMUT]}s" % if (phar = cols[COL[:MIGEL][:PHAR]] and phar.size > 3)
176
+ '1'
177
+ else
178
+ '3'
179
+ end
180
+ row << "%0#{LEN[:PHAR]}d" % cols[COL[:MIGEL][:PHAR]].to_i
181
+ row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:MIGEL][:ABEZ]].to_s.gsub(/"/,'')).to_s[0,LEN[:ABEZ]].gsub(/"/,'')
182
+ row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:MIGEL][:PRMO]].to_i.to_s) if cols[COL[:MIGEL][:PRMO]]
183
+ row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:MIGEL][:PRPU]].to_i.to_s) if cols[COL[:MIGEL][:PRPU]]
184
+ row << "%#{LEN[:CKZL]}s" % 3
185
+ row << "%#{LEN[:CLAG]}s" % 0
186
+ row << "%#{LEN[:CBGG]}s" % 0
187
+ row << "%#{LEN[:CIKS]}s" % 0
188
+ row << "%0#{LEN[:ITHE]}d" % 0
189
+ row << "%0#{LEN[:CEAN]}d" % if (ean = cols[COL[:MIGEL][:CEAN]] and !ean.empty?)
190
+ ean.to_i
191
+ else
192
+ 0
193
+ end
141
194
  row << "%#{LEN[:CMWS]}s" % '2'
142
195
  @rows << row
143
196
  end
144
197
  end
145
198
  end
146
199
  end
147
- attr_reader :updated_prmo
148
200
  def import_prmo
149
201
  import_ean = {}
150
202
  import_pha = {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2tdat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &20333320 !ruby/object:Gem::Requirement
16
+ requirement: &8718900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *20333320
24
+ version_requirements: *8718900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &20332880 !ruby/object:Gem::Requirement
27
+ requirement: &8718440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *20332880
35
+ version_requirements: *8718440
36
36
  description: ! '* oddb2tdat converts oddb.csv to oddb.dat
37
37
 
38
38
  * http://dev.ywesee.com/wiki.php/ODDB/Oddb2tdat'