oddb2xml 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.0.10 / 25.12.2012
2
+
3
+ * Add ORPH and COOL from swissmedic xls
4
+
1
5
  === 1.0.9 / 11.12.2012
2
6
 
3
7
  * Added Substance Updater via BAG-XML from the Substance Branch.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # oddb2xml
2
2
 
3
- oddb2xml, creates xml files using swissINDEX, BAG-XML and Swissmedic XLS.
3
+ oddb2xml, creates xml files using swissINDEX and BAG-XML.
4
4
 
5
5
 
6
6
  ## usage
@@ -25,8 +25,8 @@ Usage:
25
25
  option examples.
26
26
 
27
27
  ```
28
- $ oddb2xml # => oddb_article.xml, oddb_product.xml
29
- $ oddb2xml -t md # => md_article.xml, md_product.xml
28
+ $ oddb2xml # => oddb_article.xml, oddb_product.xml, oddb_substance.xml
29
+ $ oddb2xml -t md # => md_article.xml, md_product.xml, md_substance.xml
30
30
  $ oddb2xml -a nonpharma -t md -c tar.gz # => md_xml_dd.mm.yyyy_hh.mm.tar.gz
31
31
  ```
32
32
 
@@ -104,11 +104,13 @@ For example, if `-t _swiss` is given then oddb2xml creates product.xml as swiss_
104
104
  <CPT_SWISS>
105
105
  <CPTCMP_SWISS>
106
106
  <LINE_SWISS>0</LINE_SWISS>
107
+ <SUBNO_SWISS>100</SUBNO_SWISS>
107
108
  <QTY_SWISS>1000</QTY_SWISS>
108
109
  <QTYU_SWISS>U.</QTYU_SWISS>
109
110
  </CPTCMP_SWISS>
110
111
  <CPTCMP_SWISS>
111
112
  <LINE_SWISS>1</LINE_SWISS>
113
+ <SUBNO_SWISS>105</SUBNO_SWISS>
112
114
  <QTY_SWISS>10000</QTY_SWISS>
113
115
  <QTYU_SWISS>U.</QTYU_SWISS>
114
116
  </CPTCMP_SWISS>
@@ -123,3 +125,28 @@ For example, if `-t _swiss` is given then oddb2xml creates product.xml as swiss_
123
125
  </RESULT_SWISS>
124
126
  </PRODUCT_SWISS>
125
127
  ```
128
+
129
+ ### substance.xml
130
+
131
+ product.xml has relation to substance as `<SUBNO>`.
132
+
133
+ ```
134
+ <?xml version="1.0" encoding="utf-8"?>
135
+ <SUBSTANCE xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration" CREATION_DATETIME="2012-12-11T14:27:17.4444763+0900" PROD_DATE="2012-12-11T14:27:17.4444763+0900" VALID_DATE="2012-12-11T14:27:17.4444763+0900">
136
+ <SB DT="">
137
+ <SUBNO>1</SUBNO>
138
+ <NAML>3-Methoxy-butylis acetas</NAML>
139
+ </SB>
140
+ <SB DT="">
141
+ <SUBNO>2</SUBNO>
142
+ <NAML>4-Methylbenzylidene camphor</NAML>
143
+ </SB>
144
+ ...
145
+ <RESULT>
146
+ <OK_ERROR>OK</OK_ERROR>
147
+ <NBR_RECORD>1441</NBR_RECORD>
148
+ <ERROR_CODE/>
149
+ <MESSAGE/>
150
+ </RESULT>
151
+ </SUBSTANCE>
152
+ ```
@@ -17,11 +17,14 @@ end
17
17
 
18
18
  module Oddb2xml
19
19
  class Builder
20
- attr_accessor :subject, :index, :items, :tag_suffix
20
+ attr_accessor :subject, :index, :items, :orphans, :fridges,
21
+ :tag_suffix
21
22
  def initialize
22
23
  @subject = nil
23
24
  @index = {}
24
25
  @items = {}
26
+ @orphans = []
27
+ @fridges = []
25
28
  @tag_suffix = nil
26
29
  if block_given?
27
30
  yield self
@@ -138,7 +141,8 @@ module Oddb2xml
138
141
  #xml.DOSEU
139
142
  #xml.DRGFD
140
143
  #xml.DRGFF
141
- #xml.ORPH
144
+ seq[:packages].values.first[:swissmedic_number] =~ /(\d{5})(\d{3})/
145
+ xml.ORPH @orphans.include?($1.to_s) ? true : false
142
146
  #xml.BIOPHA
143
147
  #xml.BIOSIM
144
148
  #xml.BFS
@@ -267,7 +271,12 @@ module Oddb2xml
267
271
  xml.LIMPTS bg_pac[:limitation_points] unless bg_pac[:limitation_points].empty?
268
272
  end
269
273
  #xml.GRDFR
270
- #xml.COOL
274
+ if bg_pac
275
+ if !bg_pac[:swissmedic_number].empty? and
276
+ bg_pac[:swissmedic_number].to_s =~ /(\d{5})(\d{3})/
277
+ xml.COOL 1 if @fridges.include?($1.to_s)
278
+ end
279
+ end
271
280
  #xml.TEMP
272
281
  #xml.CDBG
273
282
  #xml.BG
data/lib/oddb2xml/cli.rb CHANGED
@@ -15,13 +15,23 @@ module Oddb2xml
15
15
  @mutex = Mutex.new
16
16
  @items = {} # Items from Preparations.xml in BAG
17
17
  @index = {} # Base index from swissINDEX
18
+ @orphans = [] # Orphaned drugs from Swissmedic xls
19
+ @fridges = [] # ReFridge drugs from Swissmedic xls
18
20
  LANGUAGES.each do |lang|
19
21
  @index[lang] = {}
20
22
  end
21
23
  end
22
24
  def run
23
25
  threads = []
24
- # bag_xml
26
+ # swissmedic
27
+ [:orphans, :fridges].each do |type|
28
+ threads << Thread.new do
29
+ downloader = SwissmedicDownloader.new
30
+ io = downloader.download_by(type)
31
+ self.instance_variable_set("@#{type.to_s}", SwissmedicExtractor.new(io, type).to_arry)
32
+ end
33
+ end
34
+ # bag
25
35
  threads << Thread.new do
26
36
  downloader = BagXmlDownloader.new
27
37
  xml = downloader.download
@@ -62,6 +72,8 @@ module Oddb2xml
62
72
  builder.subject = sbj
63
73
  builder.index = index
64
74
  builder.items = @items
75
+ builder.orphans = @orphans
76
+ builder.fridges = @fridges
65
77
  builder.tag_suffix = @options[:tag_suffix]
66
78
  end
67
79
  if file =~ /(product)/
@@ -96,4 +96,36 @@ XML
96
96
  end
97
97
  end
98
98
  end
99
+ class SwissmedicDownloader < Downloader
100
+ HOST = 'http://www.swissmedic.ch'
101
+ def init
102
+ end
103
+ def download_by(index=:orphans)
104
+ case index
105
+ when :orphans
106
+ @url ||= "#{HOST}/daten/00081/index.html?lang=de"
107
+ xpath = "//div[@id='sprungmarke0_4']//a[@title='Humanarzneimittel']"
108
+ when :fridges
109
+ @url ||= "#{HOST}/daten/00080/00254/index.html?lang=de"
110
+ xpath = "//table[@class='swmTableFlex']//a[@title='B3.1.35-d.xls']"
111
+ end
112
+ file = "swissmedic_#{index}.xls"
113
+ begin
114
+ agent = Mechanize.new
115
+ page = agent.get(@url)
116
+ if link = page.search(xpath).first
117
+ url = HOST + link['href']
118
+ response = agent.get(url)
119
+ response.save_as file
120
+ end
121
+ return File.open(file, 'rb')
122
+ rescue Timeout::Error
123
+ retrievable? ? retry : raise
124
+ ensure
125
+ if File.exists? file
126
+ File.unlink file
127
+ end
128
+ end
129
+ end
130
+ end
99
131
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'nokogiri'
4
+ require 'spreadsheet'
4
5
 
5
6
  module Oddb2xml
6
7
  class Extractor
@@ -117,4 +118,43 @@ module Oddb2xml
117
118
  data
118
119
  end
119
120
  end
121
+ class SwissmedicExtractor < Extractor
122
+ def initialize(io, type)
123
+ book = Spreadsheet.open(io)
124
+ @sheet = book.worksheet(0)
125
+ @type = type
126
+ end
127
+ def to_arry
128
+ data = []
129
+ case @type
130
+ when :orphans
131
+ i = 1
132
+ @sheet.each do |row|
133
+ if number = extract_number(row, i)
134
+ data << number
135
+ end
136
+ end
137
+ when :fridges
138
+ i,c = 1,7
139
+ @sheet.each do |row|
140
+ if number = extract_number(row, i) and row[c] and row[c].to_s == 'x'
141
+ data << row[i].to_i.to_s
142
+ end
143
+ end
144
+ end
145
+ data.uniq
146
+ end
147
+ private
148
+ def extract_number(row, i)
149
+ begin
150
+ if (row[i] and number = row[i].to_i.to_s and number =~ /^\d{5}$/)
151
+ return number
152
+ else
153
+ nil
154
+ end
155
+ rescue NoMethodError
156
+ nil
157
+ end
158
+ end
159
+ end
120
160
  end
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.0.9"
2
+ VERSION = "1.0.10"
3
3
  end
data/oddb2xml.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'mechanize'
23
23
  gem.add_dependency 'nokogiri'
24
24
  gem.add_dependency 'savon'
25
+ gem.add_dependency 'spreadsheet'
25
26
 
26
27
  gem.add_development_dependency 'rspec'
27
28
  gem.add_development_dependency 'webmock'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 9
10
- version: 1.0.9
9
+ - 10
10
+ version: 1.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yasuhiro Asaka, Zeno R.R. Davatz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-11 00:00:00 Z
18
+ date: 2012-12-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rdoc
@@ -86,6 +86,7 @@ files:
86
86
  - spec/downloader_spec.rb
87
87
  - spec/extractor_spec.rb
88
88
  - spec/spec_helper.rb
89
+ - .gemtest
89
90
  homepage:
90
91
  licenses: []
91
92