Skip to content

Commit

Permalink
Added exfactory and public price
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Mar 4, 2015
1 parent f9373cf commit 56f304d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions History.txt
@@ -1,5 +1,6 @@
=== 0.1.4 03.03.2015

* Added exfactory and public price
* Added optional second parameter to specify output file
* Added output for dosis (name, unit, qty) for mono-preparations
* Add selling units ot generated gtin2atc.csv file
Expand Down
14 changes: 10 additions & 4 deletions lib/gtin2atc/builder.rb
Expand Up @@ -137,6 +137,10 @@ def bag_xml_extractor
gtin = gtin.to_i
item[:gtin] = gtin
item[:name] = seq.NameDe + " " + pac.DescriptionDe
if pac.Prices
item[:exfactory_price] = pac.Prices.ExFactoryPrice.Price if pac.Prices.ExFactoryPrice
item[:public_price] = pac.Prices.PublicPrice.Price if pac.Prices.PublicPrice
end
data[gtin] = item
Util.debug_msg "run_bag_extractor add #{item}" if $VERBOSE
else
Expand All @@ -155,6 +159,7 @@ def run(gtins_to_parse=[], output_name=nil)
@oddb_calc = oddb_calc_xml_extractor
@data_epha_atc = epha_atc_extractor
@data_swissindex = swissindex_xml_extractor
@data_bag = bag_xml_extractor
emitted_ids = []
if @do_compare
output_name = File.join(Util.get_archive, 'gtin2atc_swissindex.csv')
Expand All @@ -163,21 +168,23 @@ def run(gtins_to_parse=[], output_name=nil)
output_name = File.join(Util.get_archive, output_name)
end
CSV.open(output_name,'w+', CsvOutputOptions) do |csvfile|
csvfile << ["gtin", "ATC", 'pharmacode', 'description', 'daily drug dose', 'selling units']
csvfile << ["gtin", "ATC", 'pharmacode', 'description', 'exfactory_price', 'public_price', 'selling units', 'name', 'qty', 'unit', 'ddd:qty', 'ddd:unit', 'ddd:full_text']
@data_swissindex.sort.each do |gtin, item|
if @do_compare or gtins_to_parse.size == 0 or
gtins_to_parse.index(gtin.to_s) or
gtins_to_parse.index(item[:pharmacode].to_s)
atc = item[:atc_code]
ddd = @data_epha_atc[atc]
selling_units = @oddb_calc[gtin] ? @oddb_calc[gtin][:SELLING_UNITS] : nil
exfactory_price = @data_bag[gtin] ? @data_bag[gtin][:exfactory_price] : nil
public_price = @data_bag[gtin] ? @data_bag[gtin][:public_price] : nil
emitted_ids << gtin.to_i if gtin
emitted_ids << item[:pharmacode].to_i if item[:pharmacode]
if @oddb_calc[gtin] and @oddb_calc[gtin][:COMPOSITIONS]
comp = @oddb_calc[gtin][:COMPOSITIONS].COMPONENT.first
csvfile << [gtin, atc, item[:pharmacode], item[:description], ddd, selling_units, comp.NAME, comp.QTY, comp.UNIT]
csvfile << [gtin, atc, item[:pharmacode], item[:description], exfactory_price, public_price, selling_units, comp.NAME, comp.QTY, comp.UNIT, ddd].flatten
else
csvfile << [gtin, atc, item[:pharmacode], item[:description], ddd, selling_units]
csvfile << [gtin, atc, item[:pharmacode], item[:description], exfactory_price, public_price, selling_units, nil, nil, nil, ddd].flatten
end
end
end
Expand All @@ -194,7 +201,6 @@ def run(gtins_to_parse=[], output_name=nil)
msg = "swissindex: Could not find info for #{missing_ids.size} missing ids see file pharmacode_gtin_not_found.txt"
Util.debug_msg(msg)
return unless @do_compare
@data_bag = bag_xml_extractor
output_name = File.join(Util.get_archive, 'gtin2atc_bag.csv')
CSV.open(output_name,'w+', CsvOutputOptions) do |csvfile|
csvfile << ["gtin", "ATC", 'description']
Expand Down
12 changes: 6 additions & 6 deletions spec/builder_spec.rb
Expand Up @@ -50,8 +50,8 @@ def check_csv(filename)
inhalt = IO.readlines(filename)
/^\d{13};\w{4}/.should match inhalt[1]
# Packungsgrösse, Dosierung, DDD, Route of Administration
/^gtin;ATC;pharmacode;description;daily drug dose/.should match inhalt.first
/^7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;0,2 g O Fe2\+;/.should match inhalt.join("\n")
/^gtin;ATC;pharmacode;description;selling units;name;qty;unit;ddd:qty;ddd:unit;ddd:full_text/.should match inhalt.first
/^7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;30;Ferrum(ii);105.0;mg;0.2;g;O Fe2+;Fe2+/.should match inhalt.join("\n")
end

context 'when 20273 41803 (Pharmacodes) is given' do
Expand Down Expand Up @@ -101,8 +101,8 @@ def check_csv(filename)
check_csv(CSV_NAME)
inhalt = IO.readlines(CSV_NAME)
inhalt.size.should eq 2+1 # one header lines + two items
inhalt[1].chomp.should eq '7680147690482;N07BC02;41803;KETALGIN Inj Lös 10 mg/ml;25 mg O,P;'
inhalt[2].chomp.should eq '7680353660163;B03AE10;20273;KENDURAL Depottabl;;'
inhalt[1].chomp.should eq '7680147690482;N07BC02;41803;KETALGIN Inj Lös 10 mg/ml;;;;;;;25 mg O,P'
inhalt[2].chomp.should eq '7680353660163;B03AE10;20273;KENDURAL Depottabl;;;;;;;'
end
end

Expand Down Expand Up @@ -210,8 +210,8 @@ def check_csv(filename)
FileUtils.cp(oddb_calc_xml, Gtin2atc::WorkDir, :verbose => false)
@res = buildr_capture(:stdout){ cli.run() }
check_csv(CSV_NAME)
inhalt = IO.readlines(CSV_NAME)
inhalt.index("7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;0,2 g O Fe2+;30;Ferrum(ii);105.0;mg\n").should_not == nil
inhalt = IO.read(CSV_NAME)
inhalt.index("\n7680316440115;B03AA07;20244;FERRO-GRADUMET Depottabl;;;30;Ferrum(ii);105.0;mg;0,2 g O Fe2+\n").should_not == nil
end
end

Expand Down

0 comments on commit 56f304d

Please sign in to comment.