Skip to content

Commit

Permalink
Added test for veterinary medical
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed May 20, 2014
1 parent 7ad2bd4 commit 81b6f68
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
18 changes: 12 additions & 6 deletions lib/oddb2xml/builder.rb
Expand Up @@ -579,6 +579,7 @@ def build_product
def build_article
prepare_limitations
prepare_articles

idx = 0
Oddb2xml.log "build_article #{idx} of #{@articles.size} articles"
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
Expand All @@ -591,6 +592,9 @@ def build_article
obj[:de].each_with_index do |de_idx, i|
fr_idx = obj[:fr][i] # swissindex FR
pac,no8 = nil,de_idx[:ean][4..11] # BAG-XML(SL/LS)
pack_info = nil
pack_info = @packs[no8.intern] if no8 # info from Packungen.xlsx from swissmedic_info
next if pack_info and pack_info[:list_code].match(/Tierarzneimittel/) if no8 and no8.match(/47066/)
ppac = nil # Packungen
ean = de_idx[:ean]
pharma_code = de_idx[:pharmacode]
Expand All @@ -602,7 +606,7 @@ def build_article
pac = @items[ean][:packages][ean] if @items and ean and @items[ean] and @items[ean][:packages]
end
if no8
ppac = ((_ppac = @packs[no8.intern] and !_ppac[:is_tier]) ? _ppac : nil)
ppac = ((_ppac = pack_info and !_ppac[:is_tier]) ? _ppac : nil)
end
price = nil
if !@prices.empty? && ean && @prices[ean]
Expand Down Expand Up @@ -992,6 +996,7 @@ def build_dat
next if ((ean.to_s.length != 13) and !ean14)
next if idx[:type] == :nonpharma
row = ''
pack_info = nil
# Oddb2tdat.parse
if idx[:status] =~ /A|I/
pac,no8 = nil,nil
Expand All @@ -1004,9 +1009,10 @@ def build_dat
# :swissmedic_numbers
if pac
no8 = pac[:swissmedic_number8].intern
pack_info = @packs[no8.intern] if no8
end
if pac and pac[:prices] == nil and no8
ppac = ((ppac = @packs[no8.intern] and ppac[:is_tier]) ? ppac : nil)
ppac = ((ppac = pack_info and ppac[:is_tier]) ? ppac : nil)
pac = ppac if ppac
end
row << "%#{DAT_LEN[:RECA]}s" % '11'
Expand Down Expand Up @@ -1043,13 +1049,13 @@ def build_dat
else
'0'
end
row << "%#{DAT_LEN[:CIKS]}s" % if (no8 && @packs[no8] && !@packs[no8][:is_tier]) # Packungen.xls
@packs[no8][:swissmedic_category]
row << "%#{DAT_LEN[:CIKS]}s" % if (no8 && pack_info && !pack_info[:is_tier]) # Packungen.xls
pack_info[:swissmedic_category]
else
'0'
end.gsub(/(\+|\s)/, '')
row << "%0#{DAT_LEN[:ITHE]}d" % if (no8 && @packs[no8] && !@packs[no8][:is_tier])
format_date(@packs[no8][:ith_swissmedic])
row << "%0#{DAT_LEN[:ITHE]}d" % if (no8 && pack_info && !pack_info[:is_tier])
format_date(pack_info[:ith_swissmedic])
else
('0' * DAT_LEN[:ITHE])
end.to_i
Expand Down
18 changes: 18 additions & 0 deletions lib/oddb2xml/extractor.rb
Expand Up @@ -255,6 +255,23 @@ def to_hash # Packungen.xls
cat = 13 # :swissmedic_category
ith = 4 # :ith_swissmedic IT-Code (swissmedic-diff)
atc = 5 # :atc_code
list_code = 6 # Heilmittelcode, possible values are
# Allergene
# Anthroposophika
# ayurvedische Arzneimittel
# Bakterien- und Hefepräparate
# Biotechnologika
# Blutprodukte
# Generator
# Heilmittelcode
# Homöopathika
# Impfstoffe
# Phytotherapeutika
# Radiopharmazeutika
# Synthetika human
# tibetische Arzneimittel
# Tierarzneimittel
# Transplantat: Gewebeprodukt
siz = 11 # :package_size
eht = 12 # :einheit_swissmedic
sub = 14 # :substance_swissmedic
Expand All @@ -272,6 +289,7 @@ def to_hash # Packungen.xls
:ith_swissmedic => row[ith] ? row[ith].value.to_s : '',
:swissmedic_category => row[cat].value.to_s,
:atc_code => row[atc] ? row[atc].value.to_s : '',
:list_code => row[list_code] ? row[list_code].value.to_s : '',
:package_size => row[siz] ? row[siz].value.to_s : '',
:einheit_swissmedic => row[eht] ? row[eht].value.to_s : '',
:substance_swissmedic => row[sub] ? row[sub].value.to_s : '',
Expand Down
15 changes: 14 additions & 1 deletion spec/builder_spec.rb
Expand Up @@ -139,6 +139,7 @@ def check_validation_via_xsd
end
it "pending should match EAN of Desitin. returns 0 at the moment"
end

context 'when option -e is given' do
let(:cli) do
opts = {
Expand All @@ -155,6 +156,18 @@ def check_validation_via_xsd
check_validation_via_xsd
end

it 'should not contain veterinary iksnr 47066' do
res = buildr_capture(:stdout){ cli.run }
res.should match(/NonPharma/i)
res.should match(/NonPharma products: #{NrPharmaAndNonPharmaArticles}/)
@article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
File.exists?(@article_xml).should be_true
article_xml = IO.read(@article_xml)
doc = REXML::Document.new File.new(@article_xml)
dscrds = XPath.match( doc, "//ART" )
XPath.match( doc, "//BC" ).find_all{|x| x.text.match('47066') }.size.should == 0
end

it 'should handle not duplicate pharmacode 5366964' do
res = buildr_capture(:stdout){ cli.run }
res.should match(/NonPharma/i)
Expand All @@ -166,7 +179,7 @@ def check_validation_via_xsd
dscrds = XPath.match( doc, "//ART" )
XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('5366964') }.size.should == 1
dscrds.size.should == NrExtendedArticles
XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should == 1
XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should >= 1
XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('620691') }.size.should == 1
end

Expand Down
Binary file modified spec/data/swissmedic_package.xlsx
Binary file not shown.
2 changes: 2 additions & 0 deletions spec/data/zurrose_transfer.dat
Expand Up @@ -10,3 +10,5 @@
1130027447ARTHROSENEX2519120 Salbe 100 g 0012930024300000000000000000000000002
1130028470COMPLAMIN RETARD Tabl 500 mg 60 Stk 001817003110300C020430000000000000002
11353669641-DAY ACUVUE Moist Tag -2.00dpt BC 8.5 30 Stk 0021170037501000000000000000000000001
1122871437CANIPHEDRIN Tabl 20 mg ad us vet. 100 Stk 001266001550400C000000076804706601832
1122871466CANIPHEDRIN Tabl 50 mg ad us vet. 100 Stk 001424001750400C000000076804706604282

0 comments on commit 81b6f68

Please sign in to comment.