Skip to content

Commit

Permalink
Using cmut field from Zur Rose for oddb.dat, too. Added spec tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Aug 4, 2014
1 parent 80da18b commit adae56c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
oddb2xml (1.8.5)
oddb2xml (1.8.6)
archive-tar-minitar (~> 0.5.2)
mechanize (~> 2.5.1)
nokogiri (~> 1.5.10)
Expand Down Expand Up @@ -31,7 +31,7 @@ GEM
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.2)
diff-lcs (1.2.5)
domain_name (0.5.18)
domain_name (0.5.19)
unf (>= 0.0.5, < 1.0.0)
gyoku (1.1.1)
builder (>= 2.1.2)
Expand Down Expand Up @@ -78,7 +78,7 @@ GEM
nokogiri (>= 1.4.4)
rubyzip (>= 1.0.0)
rubyntlm (0.3.4)
rubyzip (1.1.3)
rubyzip (1.1.6)
safe_yaml (1.0.3)
savon (2.4.0)
akami (~> 1.2.0)
Expand Down
7 changes: 6 additions & 1 deletion lib/oddb2xml/builder.rb
Expand Up @@ -1010,7 +1010,12 @@ def build_dat
pac = ppac if ppac
end
row << "%#{DAT_LEN[:RECA]}s" % '11'
row << "%#{DAT_LEN[:CMUT]}s" % idx[:cmut]
info_zur_rose = @infos_zur_rose[ean] # zurrose
if info_zur_rose && info_zur_rose[:cmut]
row << info_zur_rose[:cmut]
else
row << '1'
end
row << "%0#{DAT_LEN[:PHAR]}d" % idx[:pharmacode].to_i
abez = ( # de name
idx[:desc].to_s + " " +
Expand Down
4 changes: 1 addition & 3 deletions lib/oddb2xml/cli.rb
Expand Up @@ -58,9 +58,7 @@ def run
if @options[:nonpharma]
threads << download(:migel) # oddb2xml_files
end
if @options[:price] # zurrose
threads << download(@options[:price])
end
threads << download(:zurrose)
threads << download(:package) # swissmedic
threads << download(:bm_update) # oddb2xml_files
threads << download(:lppv) # oddb2xml_files
Expand Down
67 changes: 60 additions & 7 deletions spec/builder_spec.rb
Expand Up @@ -29,11 +29,10 @@ def check_validation_via_xsd
xsd.validate(doc).each do |error| error.message.should be_nil end
}
end

describe Oddb2xml::Builder do
NrExtendedArticles = 70
NrPharmaAndNonPharmaArticles = 61
NrPharmaArticles = 4
NrExtendedArticles = 71
NrPharmaAndNonPharmaArticles = 62
NrPharmaArticles = 5
include ServerMockHelper
before(:each) do
@savedDir = Dir.pwd
Expand Down Expand Up @@ -119,6 +118,28 @@ def check_validation_via_xsd
end
end

context 'when -f dat is given' do
let(:cli) do
opts = {
:format => :dat,
}
Oddb2xml::Cli.new(opts)
end

it 'should contain the correct values fo CMUT from zurrose_transfer.dat' do
puts Oddb2xml::WorkDir
res = buildr_capture(:stdout){ cli.run }
res.should match(/products/)
dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
File.exists?(dat_filename).should be_true
oddb_dat = IO.read(dat_filename)
oddb_dat.should match(/^..2/), "should have a record with '2' in CMUT field"
oddb_dat.should match(/^..3/), "should have a record with '3' in CMUT field"
oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk/), "should have Desitin"
# oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
end
end

context 'when -a nonpharma -f dat is given' do
let(:cli) do
opts = {
Expand All @@ -137,8 +158,17 @@ def check_validation_via_xsd
oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk/), "should have Desitin"
# oddb_dat.should match(/001349002780100B010710076806206900842/), "should match EAN of Desitin"
end
it "pending should match EAN of Desitin. returns 0 at the moment"

it "should match EAN of Desitin. returns 0 at the moment" do
res = buildr_capture(:stdout){ cli.run }
res.should match(/products/)
dat_filename = File.join(Oddb2xml::WorkDir, 'oddb_with_migel.dat')
File.exists?(dat_filename).should be_true
oddb_dat = IO.read(dat_filename)
oddb_dat.should match(/76806206900842/), "should match EAN of Desitin"
end
end

context 'when option -e is given' do
let(:cli) do
opts = {
Expand Down Expand Up @@ -312,9 +342,32 @@ def checkItemForRefdata(doc, pharmacode, isRefdata)
product_xml.should_not match(/ZYVOXID/i)
end
doc = REXML::Document.new File.new(product_filename)
XPath.match( doc, "//PRD" ).find_all{|x| true}.size.should == 3
XPath.match( doc, "//GTIN" ).find_all{|x| true}.size.should == 3
XPath.match( doc, "//PRD" ).find_all{|x| true}.size.should == 4
XPath.match( doc, "//GTIN" ).find_all{|x| true}.size.should == 4
XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should == 1
end

def checkItemForSALECD(doc, pharmacode, expected)
article = XPath.match( doc, "//ART[PHAR=#{pharmacode.to_s}]").first
name = article.elements['DSCRD'].text
salecd = article.elements['SALECD'].text
if $VERBOSE or article.elements['SALECD'].text != expected.to_s
puts "checking doc for pharmacode #{pharmacode} expected #{expected} == #{salecd}. #{name}"
puts article.text
end
article.elements['SALECD'].text.should == expected.to_s
end
it 'should generate the flag SALECD' do
res = buildr_capture(:stdout){ cli.run }
@article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
puts @article_xml
File.exists?(@article_xml).should be_true
FileUtils.cp(@article_xml, '/opt/src/oddb2xml/tst.xml', :verbose => true)
article_xml = IO.read(@article_xml)
doc = REXML::Document.new File.new(@article_xml)
XPath.match( doc, "//REF_DATA" ).size.should > 0
checkItemForSALECD(doc, "0020244", 'A') # FERRO-GRADUMET Depottabl 30 Stk
checkItemForSALECD(doc, "0598003", 'I') # SOFRADEX
end
end
end
16 changes: 15 additions & 1 deletion spec/data/swissindex_pharma.xml
Expand Up @@ -59,7 +59,21 @@
<GLN>7601001010604</GLN>
</COMP>
</ITEM>
<RESULT>
<ITEM DT="2013-12-06T00:00:00">
<GTIN>7680316950157</GTIN>
<PHAR>598003</PHAR>
<STATUS>A</STATUS>
<STDATE>2012-04-13T00:00:00</STDATE>
<LANG>DE</LANG>
<DSCR>SOFRADEX Gtt Auric</DSCR>
<ADDSCR>8 ml</ADDSCR>
<ATC>S02CA06</ATC>
<COMP>
<NAME>Sanofi-Aventis (Suisse) SA</NAME>
<GLN>7601001002340</GLN>
</COMP>
</ITEM>
<RESULT>
<OK_ERROR>OK</OK_ERROR>
<NBR_RECORD>2</NBR_RECORD>
</RESULT>
Expand Down
1 change: 1 addition & 0 deletions spec/data/zurrose_transfer.dat
Expand Up @@ -15,3 +15,4 @@
1122871472CANIPHEDRIN Tabl 50 mg ad us vet. 500 Stk 005443007580400C000000000000000000002
1132867163TOTALIN Plv ad us. vet. 5 kg 000535000900400C000000000000000000002
1138110429Forthyron 400 mcg 50 Tabl (vet) 0081120015800000000000000000000000002
1130598003SOFRADEX Gtt Auric 8 ml 000718001545300B120130076803169501572
27 changes: 16 additions & 11 deletions spec/extractor_spec.rb
Expand Up @@ -17,7 +17,7 @@
dat = File.read(File.join(Oddb2xml::SpecData, 'Preparations.xml'))
Oddb2xml::BagXmlExtractor.new(dat).to_hash
end
it {
it "should handle pub_price for 1699947 correctly" do
@items = subject.to_hash
with_pharma = @items['1699947']
expect(with_pharma).not_to be_nil
Expand All @@ -27,14 +27,17 @@
expect(with_pharma[:packages].first[0]).to eq('1699947')
expect(with_pharma[:packages].first[1][:prices][:pub_price][:price]).to eq('205.3')
expect(@items.size).to eq(5)
end
it "should handle pub_price for 7680620690084 correctly" do
@items = subject.to_hash
no_pharma = @items['7680620690084']
expect(no_pharma).not_to be_nil
expect(no_pharma[:atc_code]).not_to be_nil
expect(no_pharma[:pharmacodes]).not_to be_nil
expect(no_pharma[:packages].size).to eq(1)
expect(no_pharma[:packages].first[0]).to eq('7680620690084')
expect(no_pharma[:packages].first[1][:prices][:pub_price][:price]).to eq('27.8')
}
end
end
end

Expand Down Expand Up @@ -172,14 +175,16 @@
it { expect(subject.to_hash.values.first[:price]).to eq("15.76") }
it { expect(subject.to_hash.values.first[:pub_price]).to eq("24.30") }
it { expect(subject.to_hash.values.first[:pharmacode]).to eq("0020652") }

it 'should set the correct SALECD cmut code' do expect(subject.to_hash.values.first[:cmut]).to eq("2") end
end
context 'when SOFRADEX is given' do
subject do
dat = <<-DAT
1130598003SOFRADEX Gtt Auric 8 ml 000718001545300B120130076803169501572\r\n
DAT
Oddb2xml::ZurroseExtractor.new(dat)
end
#it { expect(subject.to_hash.keys.first).to eq("7680316950157") }
it "should set the correct SALECD cmut code" do expect(subject.to_hash.values.first[:cmut]).to eq("3") end
end

x =%(
Record-Art 1 Länge 97
:vat => $2.to_s,
:price => sprintf("%.2f", line[60,6].gsub(/(\d{2})$/, '.\1').to_f),
:pub_price => sprintf("%.2f", line[66,6].gsub(/(\d{2})$/, '.\1').to_f),
=
)
end

0 comments on commit adae56c

Please sign in to comment.