gtin2atc 0.1.5 → 0.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b6d462072d516aec948e6cf2ec404d60d78634d0
4
- data.tar.gz: 965cfb24672bc54f53ec3cd347104dda20d8d39b
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWFiNWE5NTUwZTA3ZWE3M2RiMjIwYjVmOTdlZDI4Zjc0MjVmMTQ1OA==
5
+ data.tar.gz: !binary |-
6
+ NmMwYmQwOTA1Y2Y1NzZjMjBmZWNkZGNlMDY0Mjk2NmFhY2YwZWZiNA==
5
7
  SHA512:
6
- metadata.gz: 5a9490c9a9d5efa5498153c8020b9119cfba390d7d09fc59524decb26f497502402f01ab79f10fdb5ae1757fe65be9a4b839a430d0f21c4d4e53130d7ba2c6b1
7
- data.tar.gz: d1acea60db039502005e629dbb48f611dd9f4c18c50ef58c3bbf7426cb843090cf227bb4d6e88ef3f51f1aef1529afc7428e7567491b02e25a0b95e66578fdee
8
+ metadata.gz: !binary |-
9
+ OWUwOTY5MmM3OTFjMGRjYWU5M2U5YTY0ZDg4YmRjMDA0OWM1MzJlNGViNWY4
10
+ NDI4OGE1ODA2MDFiMGZiYzIwNzRhNmExNzVlNTQzOGFhYTNiNTBiYWViZWVh
11
+ Mzk1YTE5MTE0MmI5OGY2NjYwYTQyZWU5NWIxNWI1MTcyODkyYjg=
12
+ data.tar.gz: !binary |-
13
+ NjU5Y2MzMTYwYjk0MWZlODJmNjNhYTc2ZTNkNjljZDZmMDkzZmFhMDk5ZmM2
14
+ ZWQxZTA1N2E1MmFlZmZjMDZiYzUwNDRhODI1ODcwYTk3ZGNlZDIzYWFkNjBi
15
+ ZjNjNGZiNTBjMzM1M2IwZmE5ZGY2YjcxODg2YTRhYTlkY2ZiYzQ=
data/History.txt CHANGED
@@ -1,5 +1,12 @@
1
+ === 0.1.6 10.03.2015
2
+
3
+ * Adapted to changed delimiter
4
+ * updated EPha URL for wido ATC download.
5
+
1
6
  === 0.1.5 04.03.2015
2
7
 
8
+ * Splitted ddd into qty, unit, route of administration
9
+ * Added exfactory and public price
3
10
  * Added optional second parameter to specify output file
4
11
  * Added output for dosis (name, unit, qty) for mono-preparations
5
12
 
@@ -15,6 +15,10 @@ module Gtin2atc
15
15
  AtcNotInBag = 'atc not in bag'
16
16
  AtcDifferent = 'atc differed'
17
17
  CsvOutputOptions = { :col_sep => ';', :encoding => 'UTF-8'}
18
+ Mesurements = [ 'g', 'kg', 'l', 'mg', 'ml', 'cm', 'GBq']
19
+ # see Selection of units of WHO DDD guidelines
20
+ RouteOfAdministrations = ['Inhal', 'R', 'N', 'O', 'SL', 'P', 'V', 'TD']
21
+
18
22
  def initialize(opts)
19
23
  Util.set_logging(opts[:log])
20
24
  @output = opts[:output]
@@ -38,9 +42,9 @@ module Gtin2atc
38
42
  end
39
43
  def epha_atc_extractor
40
44
  data = {}
41
- body = open('https://download.epha.ch/cleaned/atc.csv').read.force_encoding('UTF-8')
45
+ body = open('https://download.epha.ch/data/atc/atc.csv').read.force_encoding('UTF-8')
42
46
  Util.debug_msg "epha_atc_extractor is #{body.size} bytes long"
43
- csv = CSV.new(body, { :headers => false, :col_sep => '|' } )
47
+ csv = CSV.new(body, { :headers => false, :col_sep => ',' } )
44
48
  csv.to_a.each{
45
49
  |line|
46
50
  data[line[0]] = line[2] if line[2]
@@ -137,6 +141,10 @@ module Gtin2atc
137
141
  gtin = gtin.to_i
138
142
  item[:gtin] = gtin
139
143
  item[:name] = seq.NameDe + " " + pac.DescriptionDe
144
+ if pac.Prices
145
+ item[:exfactory_price] = pac.Prices.ExFactoryPrice.Price if pac.Prices.ExFactoryPrice
146
+ item[:public_price] = pac.Prices.PublicPrice.Price if pac.Prices.PublicPrice
147
+ end
140
148
  data[gtin] = item
141
149
  Util.debug_msg "run_bag_extractor add #{item}" if $VERBOSE
142
150
  else
@@ -149,12 +157,44 @@ module Gtin2atc
149
157
  data
150
158
  end
151
159
 
160
+ # return [qty, unit, roa] for simple, valid ddd
161
+ # return [nil, nil, full_text] for structured DDDs like Standarddosis: 10 Tabletten oder 50 ml Mixtur
162
+ # a simple ddd is valid if meets the following three criteria
163
+ # first part is a float value
164
+ # second part is a unit e.g. ml
165
+ # third part is one or several (separated by ',') RouteOfAdministrations
166
+ def get_valid_ddd(full_text)
167
+ result =[nil, nil, full_text]
168
+ return result unless full_text
169
+ return result if full_text.index(';') # e.g. 0,12 g O,R; 18 mg P; 60 mg SL; 3 mg TD; 50 mg TD Gel; 12 mg P bezogen auf Testosteronundecanoat
170
+ return result if full_text.index(':') # e.g. Standarddosis: 10 Tabletten oder 50 ml Mixture
171
+ if full_text
172
+ parts = full_text.split(' ')
173
+ return result if parts.size > 3
174
+ qty = parts[0] ? parts[0].sub(',', '.').to_f : ''
175
+ if Mesurements.index(parts[1]) and qty != 0.0
176
+ roas = parts[2].split(',')
177
+ valid = roas.size > 0
178
+ roas.each{
179
+ |roa|
180
+ unless RouteOfAdministrations.index(roa)
181
+ valid = false
182
+ break
183
+ end
184
+ }
185
+ result = [qty, parts[1], parts[2]] if valid
186
+ end
187
+ end
188
+ result
189
+ end
190
+
152
191
  def run(gtins_to_parse=[], output_name=nil)
153
192
  Util.debug_msg("run #{gtins_to_parse}")
154
193
  Util.debug_msg("@use_swissindex true")
155
194
  @oddb_calc = oddb_calc_xml_extractor
156
195
  @data_epha_atc = epha_atc_extractor
157
196
  @data_swissindex = swissindex_xml_extractor
197
+ @data_bag = bag_xml_extractor
158
198
  emitted_ids = []
159
199
  if @do_compare
160
200
  output_name = File.join(Util.get_archive, 'gtin2atc_swissindex.csv')
@@ -163,21 +203,23 @@ module Gtin2atc
163
203
  output_name = File.join(Util.get_archive, output_name)
164
204
  end
165
205
  CSV.open(output_name,'w+', CsvOutputOptions) do |csvfile|
166
- csvfile << ["gtin", "ATC", 'pharmacode', 'description', 'daily drug dose', 'selling units']
206
+ csvfile << ["gtin", "ATC", 'pharmacode', 'description', 'exfactory_price', 'public_price', 'selling units', 'name', 'qty', 'unit', 'ddd:qty', 'ddd:unit', 'ddd:full_text']
167
207
  @data_swissindex.sort.each do |gtin, item|
168
208
  if @do_compare or gtins_to_parse.size == 0 or
169
209
  gtins_to_parse.index(gtin.to_s) or
170
210
  gtins_to_parse.index(item[:pharmacode].to_s)
171
211
  atc = item[:atc_code]
172
- ddd = @data_epha_atc[atc]
212
+ ddd = get_valid_ddd(@data_epha_atc[atc])
173
213
  selling_units = @oddb_calc[gtin] ? @oddb_calc[gtin][:SELLING_UNITS] : nil
214
+ exfactory_price = @data_bag[gtin] ? @data_bag[gtin][:exfactory_price] : nil
215
+ public_price = @data_bag[gtin] ? @data_bag[gtin][:public_price] : nil
174
216
  emitted_ids << gtin.to_i if gtin
175
217
  emitted_ids << item[:pharmacode].to_i if item[:pharmacode]
176
218
  if @oddb_calc[gtin] and @oddb_calc[gtin][:COMPOSITIONS]
177
219
  comp = @oddb_calc[gtin][:COMPOSITIONS].COMPONENT.first
178
- csvfile << [gtin, atc, item[:pharmacode], item[:description], ddd, selling_units, comp.NAME, comp.QTY, comp.UNIT]
220
+ csvfile << [gtin, atc, item[:pharmacode], item[:description], exfactory_price, public_price, selling_units, comp.NAME, comp.QTY, comp.UNIT, ddd].flatten
179
221
  else
180
- csvfile << [gtin, atc, item[:pharmacode], item[:description], ddd, selling_units]
222
+ csvfile << [gtin, atc, item[:pharmacode], item[:description], exfactory_price, public_price, selling_units, nil, nil, nil, ddd].flatten
181
223
  end
182
224
  end
183
225
  end
@@ -194,7 +236,6 @@ module Gtin2atc
194
236
  msg = "swissindex: Could not find info for #{missing_ids.size} missing ids see file pharmacode_gtin_not_found.txt"
195
237
  Util.debug_msg(msg)
196
238
  return unless @do_compare
197
- @data_bag = bag_xml_extractor
198
239
  output_name = File.join(Util.get_archive, 'gtin2atc_bag.csv')
199
240
  CSV.open(output_name,'w+', CsvOutputOptions) do |csvfile|
200
241
  csvfile << ["gtin", "ATC", 'description']
@@ -1,3 +1,3 @@
1
1
  module Gtin2atc
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -21,6 +21,7 @@ end
21
21
  describe Gtin2atc::Builder do
22
22
  include ServerMockHelper
23
23
  CSV_NAME = 'gtin2atc.csv'
24
+ FERRO = '7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;;;30;Ferrum(ii);105.0;mg;;;0,2 g O Fe2+'
24
25
  before(:each) do
25
26
  @savedDir = Dir.pwd
26
27
  FileUtils.makedirs Gtin2atc::WorkDir
@@ -50,8 +51,8 @@ describe Gtin2atc::Builder do
50
51
  inhalt = IO.readlines(filename)
51
52
  /^\d{13};\w{4}/.should match inhalt[1]
52
53
  # Packungsgrösse, Dosierung, DDD, Route of Administration
53
- /^gtin;ATC;pharmacode;description;daily drug dose/.should match inhalt.first
54
- /^7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;0,2 g O Fe2\+;/.should match inhalt.join("\n")
54
+ /^gtin;ATC;pharmacode;description;exfactory_price;public_price;selling units;name;qty;unit;ddd:qty;ddd:unit;ddd:full_text/.should match inhalt.first
55
+ IO.read(filename).index(FERRO).should_not == nil
55
56
  end
56
57
 
57
58
  context 'when 20273 41803 (Pharmacodes) is given' do
@@ -101,8 +102,8 @@ describe Gtin2atc::Builder do
101
102
  check_csv(CSV_NAME)
102
103
  inhalt = IO.readlines(CSV_NAME)
103
104
  inhalt.size.should eq 2+1 # one header lines + two items
104
- inhalt[1].chomp.should eq '7680147690482;N07BC02;41803;KETALGIN Inj Lös 10 mg/ml;25 mg O,P;'
105
- inhalt[2].chomp.should eq '7680353660163;B03AE10;20273;KENDURAL Depottabl;;'
105
+ inhalt[1].chomp.should eq '7680147690482;N07BC02;41803;KETALGIN Inj Lös 10 mg/ml;;;;;;;25.0;mg;O,P'
106
+ inhalt[2].chomp.should eq '7680353660163;B03AE10;20273;KENDURAL Depottabl;;;;;;;;;'
106
107
  end
107
108
  end
108
109
 
@@ -208,10 +209,14 @@ describe Gtin2atc::Builder do
208
209
  it 'should contain dose for FERRO-GRADUMET Depottab' do
209
210
  oddb_calc_xml = File.expand_path(File.join( __FILE__, '../data/oddb_calc.xml'))
210
211
  FileUtils.cp(oddb_calc_xml, Gtin2atc::WorkDir, :verbose => false)
211
- @res = buildr_capture(:stdout){ cli.run() }
212
+ # buildr_capture(:stdout){ cli.run() }
213
+ cli.run()
212
214
  check_csv(CSV_NAME)
213
- inhalt = IO.readlines(CSV_NAME)
214
- inhalt.index("7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;0,2 g O Fe2+;30;Ferrum(ii);105.0;mg\n").should_not == nil
215
+ inhalt = IO.read(CSV_NAME)
216
+ puts inhalt
217
+ inhalt.index(FERRO).should_not == nil
218
+ inhalt.index('7680291520390;N02BE01;31532;BEN-U-RON Supp 250 mg Kind;;;;;;;;;"3 g O,P,R; 0,75 g O Kinder DDD; 0,375 g R Säuglings DDD; 0,75 g R Kinder DDD"').should_not == nil
219
+ inhalt.index('7680147700112;N07BC02;41826;KETALGIN Tabl 5 mg;;;;;;;25.0;mg;O,P').should_not == nil
215
220
  end
216
221
  end
217
222
 
Binary file
data/spec/spec_helper.rb CHANGED
@@ -53,7 +53,7 @@ module ServerMockHelper
53
53
  end
54
54
  def setup_epha_atc_server_mock
55
55
  # zip
56
- stub_url = 'https://download.epha.ch/cleaned/atc.csv'
56
+ stub_url = 'https://download.epha.ch/data/atc/atc.csv'
57
57
  stub_response = File.read(File.join(Gtin2atc::SpecData, 'atc.csv'))
58
58
  stub_request(:get, stub_url).
59
59
  with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtin2atc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklaus Giger, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.1.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.1.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mechanize
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.5.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.5.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.5.10
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.5.10
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: savon
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.4.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.4.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubyXL
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 3.3.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sax-machine
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.3.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.3.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - ! '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: webmock
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - ! '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - ! '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rdoc
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - ! '>='
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - ! '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  description: gtin2atc file with gtin, atc_code, pharmanr from input file with gtin
@@ -171,8 +171,8 @@ executables:
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
- - ".gitignore"
175
- - ".travis.yml"
174
+ - .gitignore
175
+ - .travis.yml
176
176
  - Gemfile
177
177
  - History.txt
178
178
  - LICENSE
@@ -207,17 +207,17 @@ require_paths:
207
207
  - lib
208
208
  required_ruby_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
- - - ">="
210
+ - - ! '>='
211
211
  - !ruby/object:Gem::Version
212
212
  version: '0'
213
213
  required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - ">="
215
+ - - ! '>='
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.4.5
220
+ rubygems_version: 2.3.0
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: gtin2atc creates csv files with GTIN and ATC.