gtin2atc 0.1.3 → 0.1.4

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDRhOWFiNzFhNzM0YmE0N2NlYTA0NWI5MDEyOGRkNjY5YWZjYTU3Yg==
5
- data.tar.gz: !binary |-
6
- YmZlMDkxMWRiM2VkNTY0MDZiMjk0YWFkYjM0MGY3ZDFjMDEzMTBlYw==
2
+ SHA1:
3
+ metadata.gz: 88ed6172e67a5d527bfa4c4f55fe1d49d4af214f
4
+ data.tar.gz: b7daf74015a79a3f797037eaa0cc8c45f84ec3b8
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Yzk0OGY2MTU2NmY2ZmY0NmRiYTM2MGI4Mzc0NzdhNjFmM2RlMGJjNTVjZDhm
10
- NmEzMDI1NjYxNzk0Njg2MDhhYTQ4ZDNkZDNiZTUyYzE0MTRiODdiZmYxODc5
11
- NjJhMDk3MDY1ODRlMzBmY2YxNzUyMTM4ZDQwNzZjNzNjMDQ0MTY=
12
- data.tar.gz: !binary |-
13
- ZDk1NDkxZmY0NGY3OTZjYzY3MTYwMzFmMmFkMjQ3OTExZmRmZWE2YTcxZDQ0
14
- MmUxNWE4OGRiOGRiZmIzMGEyNGQwYmYzMTA1NWQzYmEwMTBiODFkNTcxNmVj
15
- MWE1YzAyNDg3OTgyYjJlMTg4ZmQ3YTI4ZjhhOWNhYTExNjllMGU=
6
+ metadata.gz: a98367cbe6b716cee86116d9e100b7ea0fd8c44a85e5b7bb633d292f0f04de78d907865c9eebddf9fb74609161dbe3e69464d8353287ffc2f19596e51318a3c7
7
+ data.tar.gz: a7d711d4fa0305d21540c6445669e09082734a99d0b30b9cfa4f05494ff242cadb365d2d89bc9d46d504a52959c5938e4675e0e435d7f33a43a4c749b180ca0c
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.4 03.03.2015
2
+
3
+ * Create file pharmacode_gtin_not_found.txt
4
+
1
5
  === 0.1.3 27.01.2015
2
6
 
3
7
  * Clearer filenames
@@ -4,6 +4,7 @@ require "gtin2atc/options"
4
4
  require "gtin2atc/downloader"
5
5
  require "gtin2atc/xml_definitions"
6
6
  require 'mechanize'
7
+ require 'open-uri'
7
8
 
8
9
  module Gtin2atc
9
10
  class Builder
@@ -33,6 +34,18 @@ module Gtin2atc
33
34
  end
34
35
  ((10-(sum%10))%10).to_s
35
36
  end
37
+ def epha_atc_extractor
38
+ data = {}
39
+ body = open('https://download.epha.ch/cleaned/atc.csv').read.force_encoding('UTF-8')
40
+ Util.debug_msg "epha_atc_extractor is #{body.size} bytes long"
41
+ csv = CSV.new(body, { :headers => false, :col_sep => '|' } )
42
+ csv.to_a.each{
43
+ |line|
44
+ data[line[0]] = line[2] if line[2]
45
+ }
46
+ Util.debug_msg "epha_atc_extractor extracted #{data.size} items"
47
+ data
48
+ end
36
49
  def swissmedic_xls_extractor
37
50
  @swissmedic = SwissmedicDownloader.new
38
51
  filename = @swissmedic.download
@@ -111,20 +124,35 @@ module Gtin2atc
111
124
  def run(gtins_to_parse=[])
112
125
  Util.debug_msg("run #{gtins_to_parse}")
113
126
  Util.debug_msg("@use_swissindex true")
127
+ @data_epha_atc = epha_atc_extractor
114
128
  @data_swissindex = swissindex_xml_extractor
129
+ emitted_ids = []
115
130
  output_name = File.join(Util.get_archive, @do_compare ? 'gtin2atc_swissindex.csv' : 'gtin2atc.csv')
116
131
  CSV.open(output_name,'w+') do |csvfile|
117
- csvfile << ["gtin", "ATC", 'pharmacode', 'description']
132
+ csvfile << ["gtin", "ATC", 'pharmacode', 'description', 'daily drug dose']
118
133
  @data_swissindex.sort.each do |gtin, item|
119
134
  if @do_compare or gtins_to_parse.size == 0 or
120
- gtins_to_parse.index(gtin.to_s) or
121
- gtins_to_parse.index(item[:pharmacode])
122
- csvfile << [gtin, item[:atc_code], item[:pharmacode], item[:description]]
135
+ gtins_to_parse.index(gtin.to_s) or
136
+ gtins_to_parse.index(item[:pharmacode])
137
+ atc = item[:atc_code]
138
+ ddd = @data_epha_atc[atc]
139
+ emitted_ids << gtin if gtin
140
+ emitted_ids << item[:pharmacode] if item[:pharmacode]
141
+ csvfile << [gtin, atc, item[:pharmacode], item[:description], ddd]
123
142
  end
124
143
  end
125
144
  end
126
145
  msg = "swissindex: Extracted #{gtins_to_parse.size} of #{@data_swissindex.size} items into #{output_name} for #{gtins_to_parse}"
127
146
  Util.debug_msg(msg)
147
+ missing_ids = []
148
+ gtins_to_parse.each{
149
+ |id|
150
+ next if emitted_ids.index(id)
151
+ missing_ids << id
152
+ }
153
+ File.open('pharmacode_gtin_not_found.txt', 'w+') { |f| f.write missing_ids.join("\n") }
154
+ msg = "swissindex: Could not find info for #{missing_ids.size} missing ids see file pharmacode_gtin_not_found.txt"
155
+ Util.debug_msg(msg)
128
156
  return unless @do_compare
129
157
  @data_bag = bag_xml_extractor
130
158
  output_name = File.join(Util.get_archive, 'gtin2atc_bag.csv')
@@ -148,7 +176,6 @@ module Gtin2atc
148
176
  check_swissmedic
149
177
  compare
150
178
  end
151
- # require 'pry';
152
179
  def check_bag
153
180
  matching_atc_codes = []
154
181
 
@@ -201,8 +228,6 @@ module Gtin2atc
201
228
  end
202
229
  total1 = not_in_swissindex + match_in_swissindex + longer_in_swissindex + shorter_in_swissindex + different_atc_in_swissindex
203
230
  total2 = not_in_swissmedic + match_in_swissmedic + longer_in_swissmedic + shorter_in_swissmedic + different_atc_in_swissmedic
204
- # binding.pry if j != (total1 + matching_atc_codes)
205
- # binding.pry if j != (total2 + matching_atc_codes)
206
231
  # Util.debug_msg "#{gtin}: j #{j} finished #{total1} #{total2} #{atc_code} matching_atc_codes #{matching_atc_codes}"
207
232
  }
208
233
  Util.info "Result of verifing data from bag (SL):
@@ -1,3 +1,3 @@
1
1
  module Gtin2atc
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -45,6 +45,30 @@ describe Gtin2atc::Builder do
45
45
  Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
46
46
  end
47
47
 
48
+ def check_csv(filename)
49
+ File.exists?(filename).should eq true
50
+ inhalt = IO.readlines(filename)
51
+ puts inhalt
52
+ /^\d{13},\w{4}/.should match inhalt[1]
53
+ # Packungsgrösse, Dosierung, DDD, Route of Administration
54
+ /^gtin,ATC,pharmacode,description,daily drug dose/.should match inhalt.first
55
+ /^7680316440115,B03AA07,20244,FERRO-GRADUMET Depottabl,"0,2 g O Fe2\+"/.should match inhalt.join("\n")
56
+ end
57
+
58
+ context 'when 20273 41803 (Pharmacodes) is given' do
59
+ let(:cli) do
60
+ options = Gtin2atc::Options.new
61
+ options.parser.parse!('20273 41803'.split(' '))
62
+ Gtin2atc::Builder.new(options.opts)
63
+ end
64
+
65
+ it 'should produce a correct csv' do
66
+ # @res = buildr_capture(:stdout){ cli.run }
67
+ cli.run
68
+ check_csv(CSV_NAME)
69
+ end
70
+ end
71
+
48
72
  context 'when --log is given' do
49
73
  let(:cli) do
50
74
  options = Gtin2atc::Options.new
@@ -78,8 +102,8 @@ describe Gtin2atc::Builder do
78
102
  check_csv(CSV_NAME)
79
103
  inhalt = IO.readlines(CSV_NAME)
80
104
  inhalt.size.should eq 2+1 # one header lines + two items
81
- inhalt[1].chomp.should eq '7680147690482,N07BC02,41803,KETALGIN Inj Lös 10 mg/ml'
82
- 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 mg O,P"'
106
+ inhalt[2].chomp.should eq '7680353660163,B03AE10,20273,KENDURAL Depottabl,'
83
107
  end
84
108
  end
85
109
 
@@ -151,9 +175,10 @@ describe Gtin2atc::Builder do
151
175
  Gtin2atc::Builder.new(options.opts)
152
176
  end
153
177
 
154
- it 'should produce a many report files' do
178
+ it 'should produce many report files' do
155
179
  @res = buildr_capture(:stdout){ cli.run }
156
180
  Dir.glob(Gtin2atc::WorkDir + '/compare_all_*.txt').size.should == 5
181
+ Dir.glob(Gtin2atc::WorkDir + '/pharmacode_gtin_not_found.txt').size.should == 1
157
182
  Dir.glob(Gtin2atc::WorkDir + '/compare_swissmedic_to_swisssindex_*.txt').size.should == 5
158
183
  Dir.glob(Gtin2atc::WorkDir + '/compare_bag_to_swissindex_*.txt').size.should == 5
159
184
  Dir.glob(Gtin2atc::WorkDir + '/compare_bag_to_swissmedic_*.txt').size.should == 5
data/spec/data/atc.csv ADDED
@@ -0,0 +1,18 @@
1
+ A|ALIMENTÄRES SYSTEM UND STOFFWECHSEL||
2
+ A01AA01|Natriumfluorid|1,1 mg O 0.5 mg Fluorid|
3
+ A01AA03|Olaflur|1,1 mg O|
4
+ A01AB02|Wasserstoffperoxid|60 mg O|
5
+ A01AB33|Nystatin|500 000 IE O|
6
+ A06AA01|Dickflüssiges Paraffin|15 g O|
7
+ B03AA07|Eisen(II)sulfat|0,2 g O Fe2+|
8
+ B03AE10|Verschiedene Kombinationen||
9
+ D11AC03|Selen-haltige Verbindungen||
10
+ G03GA01|Choriongonadotrophin|7,5 TSD E P zur Ovulationsauslösung|
11
+ J01FA01|Erythromycin|1 g O; 2 g O Erythromycinethylsuccinat-Tabletten; 2 g P; 1 g O Kinder DDD für Erythromycinethylsuccinat-haltige Mittel|
12
+ N02BE01|Paracetamol|3 g O,P,R; 0,75 g O Kinder DDD; 0,375 g R Säuglings DDD; 0,75 g R Kinder DDD|
13
+ N05CP01|Baldrianwurzel|7 g O Droge; 6,5 ml O Tinktur|
14
+ N07BC02|Methadon|25 mg O,P|
15
+ S01EB02|Carbachol|0,4 ml|
16
+ S01EB06|Neostigmin|40 mg Salbe; 0,4 ml|
17
+ S01XA28|Hyaluronsäure|0,4 ml AT|
18
+ S01XC20|Kombinationen|Standarddosis: 0,4 ml AT; 0,4 g AS|