Skip to content

Commit

Permalink
Remove BM_update from ywesee. Use drug information from Packungen.xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Sep 9, 2015
1 parent 2ba7cc0 commit 042e78a
Show file tree
Hide file tree
Showing 11 changed files with 991 additions and 985 deletions.
26 changes: 15 additions & 11 deletions lib/oddb2xml/builder.rb
Expand Up @@ -703,11 +703,12 @@ def emit_substance(xml, substance, emit_active=false)
ean13 = (ean12 + Oddb2xml.calc_checksum(ean12))
items[ean13] = info
xml.ARTICLE {
xml.GTIN ean13
xml.NAME info.column_c
xml.PKG_SIZE info.pkg_size
xml.SELLING_UNITS info.selling_units
xml.MEASURE info.measure # Nur wenn Lösung wen Spalte M ml, Spritze
xml.GTIN ean13
xml.NAME info.column_c
xml.PKG_SIZE info.pkg_size
xml.SELLING_UNITS info.selling_units
xml.MEASURE info.measure # Nur wenn Lösung wen Spalte M ml, Spritze

if info.galenic_form.is_a?(String)
xml.GALENIC_FORM info.galenic_form
xml.GALENIC_GROUP "Unknown"
Expand Down Expand Up @@ -764,7 +765,6 @@ def build_article
ean = obj[:ean]
next if pack_info and /Tierarzneimittel/.match(pack_info[:list_code])
next if obj[:desc_de] and /ad us vet/i.match(obj[:desc_de])

pharma_code = obj[:pharmacode]
ean = 0 if sprintf('%013d', ean).match(/^000000/)
if obj[:seq]
Expand All @@ -787,7 +787,10 @@ def build_article
#xml.CDS01
#xml.CDS02
if ppac
xml.SMCAT ppac[:swissmedic_category] unless ppac[:swissmedic_category].empty?
xml.SMCAT ppac[:swissmedic_category] unless ppac[:swissmedic_category].empty?
xml.GEN_PRODUCTION ppac[:gen_production] unless ppac[:gen_production].empty?
xml.INSULIN_CATEGORY ppac[:insulin_category] unless ppac[:insulin_category].empty?
xml.DRUG_INDEX ppac[:drug_index] unless ppac[:drug_index].empty?
end
if no8 and !no8.to_s.empty?
if ean and ean.to_s[0..3] == "7680"
Expand Down Expand Up @@ -817,7 +820,7 @@ def build_article
end
#xml.TEMP
if ean
flag = @flags[ean.to_s]
flag = (ppac && !ppac[:drug_index].empty?) ? true : false
# as same flag
xml.CDBG(flag ? 'Y' : 'N')
xml.BG(flag ? 'Y' : 'N')
Expand Down Expand Up @@ -1180,6 +1183,9 @@ def build_dat
next if obj[:type] == :nonpharma
row = ''
pack_info = nil
if (x = @packs.find{|k,v| v[:ean].to_i == ean})
pack_info = x[1]
end
# Oddb2tdat.parse
pac,no8 = nil,nil
if obj[:seq] and obj[:seq][:packages]
Expand All @@ -1191,7 +1197,6 @@ 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 = pack_info and ppac[:is_tier]) ? ppac : nil)
Expand Down Expand Up @@ -1236,8 +1241,7 @@ def build_dat
else
'0'
end
row << "%#{DAT_LEN[:CBGG]}s" % if ((pac && pac[:narcosis_flag] == 'Y') or # BAGXml
(@flags[ean])) # ywesee BM_update
row << "%#{DAT_LEN[:CBGG]}s" % if (pack_info && pack_info[:drug_index])
'3'
else
'0'
Expand Down
13 changes: 0 additions & 13 deletions lib/oddb2xml/cli.rb
Expand Up @@ -24,7 +24,6 @@ def initialize(args)
# product
@items = {} # Items from Preparations.xml in BAG, using GTINs as key
@refdata_types = {} # Base index from refdata
@flags = {} # narcotics flag files repo
@lppvs = {} # lppv.txt from files repo
@infos = {} # [option] FI from SwissmedicInfo
@packs = {} # [option] Packungen from Swissmedic for dat
Expand Down Expand Up @@ -63,7 +62,6 @@ def run
end
threads << download(:zurrose)
threads << download(:package) # swissmedic
threads << download(:bm_update) # oddb2xml_files
threads << download(:lppv) # oddb2xml_files
threads << download(:bag) # bag.e-mediat
types.each do |type|
Expand Down Expand Up @@ -228,17 +226,6 @@ def download(what, type=nil)
@packs
end
end
when :bm_update
begin # instead of Thread.new do
downloader = BMUpdateDownloader.new
str = downloader.download
Oddb2xml.log("BMUpdateDownloader str #{str.size} bytes")
@mutex.synchronize do
@flags = BMUpdateExtractor.new(str).to_hash
Oddb2xml.log("BMUpdateExtractor added #{@flags.size} flags")
@flags
end
end
when :lppv
begin # instead of Thread.new do
downloader = LppvDownloader.new
Expand Down
7 changes: 0 additions & 7 deletions lib/oddb2xml/downloader.rb
Expand Up @@ -133,13 +133,6 @@ def download
download_as('epha_interactions.csv', 'r')
end
end
class BMUpdateDownloader < Downloader
include DownloadMethod
def download
@url ||= 'https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
download_as('oddb2xml_files_bm_update.txt', 'r')
end
end
class LppvDownloader < Downloader
include DownloadMethod
def download
Expand Down
7 changes: 3 additions & 4 deletions lib/oddb2xml/extractor.rb
Expand Up @@ -28,9 +28,6 @@ def initialize(xml)
@xml = xml
end
end
class BMUpdateExtractor < Extractor
include TxtExtractorMethods
end
class LppvExtractor < Extractor
include TxtExtractorMethods
end
Expand Down Expand Up @@ -96,7 +93,6 @@ def to_hash
:ean => (ean) ? ean : '',
:swissmedic_category => (cat = pac.SwissmedicCategory) ? cat : '',
:swissmedic_number8 => (num = pac.SwissmedicNo8) ? num.rjust(8, '0') : '',
:narcosis_flag => (flg = pac.FlagNarcosis) ? flg : '',
:prices => { :exf_price => exf, :pub_price => pub },
}
# related all limitations
Expand Down Expand Up @@ -294,6 +290,9 @@ def to_hash # Packungen.xlsx COLUMNS_JULY_2015
:composition_swissmedic => row[comp] ? row[comp].value.to_s : '',
:sequence_name => row[seq_name] ? row[seq_name].value.to_s : '',
:is_tier => (row[list_code] == 'Tierarzneimittel' ? true : false),
:gen_production => row[COLUMNS_JULY_2015.keys.index(:gen_production)].value.to_s,
:insulin_category => row[COLUMNS_JULY_2015.keys.index(:insulin_category)].value.to_s,
:drug_index => row[COLUMNS_JULY_2015.keys.index(:drug_index)].value.to_s,
}
end
end
Expand Down
3 changes: 3 additions & 0 deletions oddb2xml.xsd
Expand Up @@ -109,6 +109,9 @@
</xs:element>
<xs:element ref="ns1:PHAR"/>
<xs:element minOccurs="0" ref="ns1:SMCAT"/>
<xs:element minOccurs="0" name="GEN_PRODUCTION" type="xs:string" />
<xs:element minOccurs="0" name="INSULIN_CATEGORY" type="xs:string" />
<xs:element minOccurs="0" name="DRUG_INDEX" type="xs:string" />
<xs:element minOccurs="0" ref="ns1:SMNO"/>
<xs:element minOccurs="0" ref="ns1:PRODNO"/>
<xs:element minOccurs="0" ref="ns1:VAT"/>
Expand Down
50 changes: 39 additions & 11 deletions spec/builder_spec.rb
Expand Up @@ -187,7 +187,7 @@ def checkProductXml
desitin.elements['CompositionSwissmedic'].text.should eq 'levetiracetamum 250 mg, excipiens pro compressi obducti pro charta.'

desitin.elements['CPT/CPTCMP/LINE'].text.should eq '0'
desitin.elements['CPT/CPTCMP/SUBNO'].text.should eq '8'
desitin.elements['CPT/CPTCMP/SUBNO'].text.should eq '9'
desitin.elements['CPT/CPTCMP/QTY'].text.should eq '250'
desitin.elements['CPT/CPTCMP/QTYU'].text.should eq 'mg'

Expand All @@ -210,8 +210,8 @@ def checkProductXml
describe Oddb2xml::Builder do
NrExtendedArticles = 86
NrSubstances = 12
NrProdno = 19
NrPackages = 20
NrProdno = 21
NrPackages = 22
RegExpDesitin = /1125819012LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk/
include ServerMockHelper
def common_run_init
Expand All @@ -229,30 +229,53 @@ def common_run_init
common_run_init
options = Oddb2xml::Options.new
@res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
# Oddb2xml::Cli.new(options.opts).run # to debug
@article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
@doc = Nokogiri::XML(File.open(@article_xml))
@rexml = REXML::Document.new File.read(@article_xml)
end

it 'should return produce a oddb_article.xml' do
@article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
File.exists?(@article_xml).should eq true
end

it 'oddb_article.xml should contain a SHA256' do
@article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
content = IO.read(@article_xml)
doc = REXML::Document.new File.new(@article_xml)
expect( XPath.match( doc, "//ART").first.attributes['DT']).to match /\d{4}-\d{2}-\d{2}/
expect( XPath.match( doc, "//ART").first.attributes['SHA256'].size).to eq 64
expect(XPath.match(@rexml, "//ART" ).first.attributes['SHA256'].size).to eq 64
expect(XPath.match(@rexml, "//ART" ).size).to eq XPath.match(@rexml, "//ART" ).size
end

it 'should be possible to verify the oddb_article.xml' do
@article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
result = Oddb2xml.verify_sha256(@article_xml)
expect(result)
end

it 'should be possible to verify all xml files against our XSD' do
check_validation_via_xsd
end

it 'should have a correct insulin (gentechnik) for 7680532900196' do
expect(XPath.match( @rexml, "//ART/[BC='7680532900196']").size).to eq 1
expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").size).to eq 1
expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").first.text).to eq 'X'
expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").size).to eq 1
expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").first.text).to eq 'Insulinanalog: schnell wirkend'
end

it 'should have a correct drug information for 7680555610041' do
expect(XPath.match( @rexml, "//ART/[BC='7680555610041']").size).to eq 1
expect(XPath.match( @rexml, "//ART//DRUG_INDEX").size).to eq 1
expect(XPath.match( @rexml, "//ART//DRUG_INDEX").first.text).to eq 'd'
found = false
XPath.match( @rexml, "//ART//CDBG").each{
|flag|
if flag.text.eql?('Y')
found = true
break
end
}
expect(found)
end

end

context 'when -o for fachinfo is given' do
Expand Down Expand Up @@ -296,6 +319,7 @@ def common_run_init
options = Oddb2xml::Options.new
options.parser.parse!('-f dat --log'.split(' '))
@res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
# Oddb2xml::Cli.new(options.opts).run # to debug
end

it 'should contain the correct values fo CMUT from zurrose_transfer.dat' do
Expand All @@ -307,6 +331,9 @@ def common_run_init
oddb_dat.should match(/^..3/), "should have a record with '3' in CMUT field"
oddb_dat.should match(RegExpDesitin), "should have Desitin"
IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line) }
m = /.+DIAPHIN Trocke.*7680555610041.+/.match(oddb_dat)
expect(m[0].size).to eq 97 # size of IGM 1 record
expect(m[0][74]).to eq '3'
end
end

Expand Down Expand Up @@ -340,7 +367,8 @@ def common_run_init
common_run_init
options = Oddb2xml::Options.new
options.parser.parse!('--append -I 80 -e'.split(' '))
@res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
Oddb2xml::Cli.new(options.opts).run
# @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
end

it "oddb_article with stuf from ZurRose", :skip => "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
Expand Down
Binary file modified spec/data/swissmedic_package.xlsx
Binary file not shown.
30 changes: 1 addition & 29 deletions spec/downloader_spec.rb
Expand Up @@ -79,7 +79,7 @@ def common_after
Dir.chdir(@savedDir) if @savedDir and File.directory?(@savedDir)
VCR.eject_cassette
vcr_file = File.expand_path(File.join(Oddb2xml::SpecData, '..', 'fixtures', 'vcr_cassettes', 'oddb2xml.json'))
puts "Pretty-printing #{vcr_file} exists? #{File.exists?(vcr_file)}"
puts "Pretty-printing #{vcr_file} exists? #{File.exists?(vcr_file)}" if $VERBOSE
vcr_file_new = vcr_file.sub('.json', '.new')
cmd = "cat #{vcr_file} | python -mjson.tool > #{vcr_file_new}"
res = system(cmd)
Expand Down Expand Up @@ -343,34 +343,6 @@ def unzip_files(zipfile_name, directory=Dir.pwd)
end
end

describe Oddb2xml::BMUpdateDownloader do
include ServerMockHelper
before(:all) do VCR.eject_cassette end
before(:each) do
@downloader = Oddb2xml::BMUpdateDownloader.new
VCR.insert_cassette('oddb2xml', :tag => :BMUpdate)
common_before
end
after(:each) do
common_after
end

it_behaves_like 'any downloader'
context 'when download is called' do
let(:txt) {
@downloader.download
}
it 'should read txt as String' do
txt.should be_a String
txt.bytes.should_not nil
end
it 'should clean up current directory' do
expect { txt }.not_to raise_error
# File.exist?('oddb2xml_files_bm_update.txt').should eq(false)
end
end
end

describe Oddb2xml::BagXmlDownloader do
include ServerMockHelper
before(:all) do VCR.eject_cassette end
Expand Down

0 comments on commit 042e78a

Please sign in to comment.