lib/oddb2xml/cli.rb in oddb2xml-1.1.2 vs lib/oddb2xml/cli.rb in oddb2xml-1.1.3
- old
+ new
@@ -7,43 +7,55 @@
require 'oddb2xml/compressor'
module Oddb2xml
class Cli
SUBJECTS = %w[product article]
- ADDITIONS = %w[substance limitation]
- OPTIONALS = %w[fi]
+ ADDITIONS = %w[substance limitation interaction code]
+ OPTIONALS = %w[fi fi_product]
LANGUAGES = %w[DE FR] # EN does not exist
def initialize(args)
@options = args
@mutex = Mutex.new
@items = {} # Items from Preparations.xml in BAG
@index = {} # Base index from swissINDEX
- @infos = {} # FI from SwissmedicInfo
- @orphans = [] # Orphaned drugs from Swissmedic xls
- @fridges = [] # ReFridge drugs from Swissmedic xls
+ @infos = {} # [option] FI from SwissmedicInfo
+ @actions = [] # [addition] interactions from epha
+ @orphans = [] # [addition] Orphaned drugs from Swissmedic xls
+ @fridges = [] # [addition] ReFridge drugs from Swissmedic xls
LANGUAGES.each do |lang|
@index[lang] = {}
end
end
def run
threads = []
- # swissmedic
- threads << Thread.new do
- downloader = SwissmedicInfoDownloader.new
- xml = downloader.download
- @mutex.synchronize do
- hsh = SwissmedicInfoExtractor.new(xml).to_hash
- @infos = hsh
+ # swissmedic-info
+ if @options[:fi]
+ threads << Thread.new do
+ downloader = SwissmedicInfoDownloader.new
+ xml = downloader.download
+ @mutex.synchronize do
+ hsh = SwissmedicInfoExtractor.new(xml).to_hash
+ @infos = hsh
+ end
end
end
+ # swissmedic
[:orphans, :fridges].each do |type|
threads << Thread.new do
- downloader = SwissmedicDownloader.new
- io = downloader.download_by(type)
+ downloader = SwissmedicDownloader.new(type)
+ io = downloader.download
self.instance_variable_set("@#{type.to_s}", SwissmedicExtractor.new(io, type).to_arry)
end
end
+ # epha
+ threads << Thread.new do
+ downloader = EphaDownloader.new
+ io = downloader.download
+ @mutex.synchronize do
+ @actions = EphaExtractor.new(io).to_hash
+ end
+ end
# bag
threads << Thread.new do
downloader = BagXmlDownloader.new
xml = downloader.download
@mutex.synchronize do
@@ -53,12 +65,12 @@
end
LANGUAGES.each do |lang|
# swissindex
types.each do |type|
threads << Thread.new do
- downloader = SwissIndexDownloader.new(type)
- xml = downloader.download_by(lang)
+ downloader = SwissIndexDownloader.new(type, lang)
+ xml = downloader.download
@mutex.synchronize do
hsh = SwissIndexExtractor.new(xml, type).to_hash
@index[lang][type] = hsh
end
end
@@ -83,12 +95,16 @@
end
builder.subject = sbj
builder.index = index
builder.items = @items
# additions
- builder.orphans = @orphans
- builder.fridges = @fridges
+ %w[actions orphans fridges].each do |addition|
+ builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
+ end
+ #builder.actions = @actions
+ #builder.orphans = @orphans
+ #builder.fridges = @fridges
# optionals
builder.infos = @infos
builder.tag_suffix = @options[:tag_suffix]
end
xml = builder.to_xml
@@ -113,9 +129,14 @@
compressor.finalize!
end
def files
unless @_files
@_files = {}
+ ##
+ # building order
+ # 1. addtions
+ # 2. subjects
+ # 3. optionals
_files = (ADDITIONS + SUBJECTS)
_files += OPTIONALS if @options[:fi]
_files.each do|sbj|
@_files[sbj] = "#{prefix}_#{sbj.to_s}.xml"
end