oddb2xml 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,4 +1,8 @@
1
- === 1.0.7 / 20.11.2012
1
+ === 1.0.9 / 11.12.2012
2
+
3
+ * Added Substance Updater via BAG-XML from the Substance Branch.
4
+
5
+ === 1.0.8 / 20.11.2012
2
6
 
3
7
  * Update spec for cli
4
8
  * Add zip compress option
@@ -27,12 +27,53 @@ module Oddb2xml
27
27
  yield self
28
28
  end
29
29
  end
30
- def to_xml
31
- if @subject
30
+ def to_xml(subject=nil)
31
+ if subject
32
+ self.send('build_' + subject)
33
+ elsif @subject
32
34
  self.send('build_' + @subject)
33
35
  end
34
36
  end
35
37
  private
38
+ def build_substance
39
+ @substances = []
40
+ @items.values.uniq.each do |seq|
41
+ seq[:substances].each do |sub|
42
+ @substances << sub[:name]
43
+ end
44
+ end
45
+ @substances.uniq!
46
+ @substances.sort!
47
+ _builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
48
+ xml.doc.tag_suffix = @tag_suffix
49
+ datetime = Time.new.strftime('%FT%T.%7N%z')
50
+ xml.SUBSTANCE(
51
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
52
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
53
+ 'xmlns' => 'http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration',
54
+ 'CREATION_DATETIME' => datetime,
55
+ 'PROD_DATE' => datetime,
56
+ 'VALID_DATE' => datetime,
57
+ ) {
58
+ @substances.each_with_index do |sub_name, i|
59
+ xml.SB('DT' => '') {
60
+ xml.SUBNO (i + 1).to_i
61
+ #xml.NAMD
62
+ #xml.ANAMD
63
+ #xml.NAMF
64
+ xml.NAML sub_name
65
+ }
66
+ end
67
+ xml.RESULT {
68
+ xml.OK_ERROR 'OK'
69
+ xml.NBR_RECORD @substances.length.to_s
70
+ xml.ERROR_CODE ''
71
+ xml.MESSAGE ''
72
+ }
73
+ }
74
+ end
75
+ _builder.to_xml
76
+ end
36
77
  def build_product
37
78
  # merge company info from swissINDEX
38
79
  objects = []
@@ -137,7 +178,7 @@ module Oddb2xml
137
178
  seq[:substances].each do |sub|
138
179
  xml.CPTCMP {
139
180
  xml.LINE sub[:index] unless sub[:index].empty?
140
- #xml.SUBNO
181
+ xml.SUBNO @substances.index(sub[:name]) + 1 if @substances.include?(sub[:name])
141
182
  xml.QTY sub[:quantity] unless sub[:quantity].empty?
142
183
  xml.QTYU sub[:unit] unless sub[:unit].empty?
143
184
  #xml.WHK
data/lib/oddb2xml/cli.rb CHANGED
@@ -12,7 +12,7 @@ module Oddb2xml
12
12
  LANGUAGES = %w[DE FR] # EN does not exist
13
13
  def initialize(args)
14
14
  @options = args
15
- #@mutex = Mutex.new
15
+ @mutex = Mutex.new
16
16
  @items = {} # Items from Preparations.xml in BAG
17
17
  @index = {} # Base index from swissINDEX
18
18
  LANGUAGES.each do |lang|
@@ -20,28 +20,27 @@ module Oddb2xml
20
20
  end
21
21
  end
22
22
  def run
23
- # Sometimes nokogiri crashes with ruby in Threads.
24
- #threads = []
23
+ threads = []
25
24
  # bag_xml
26
- #threads << Thread.new do
25
+ threads << Thread.new do
27
26
  downloader = BagXmlDownloader.new
28
27
  xml = downloader.download
29
28
  @items = BagXmlExtractor.new(xml).to_hash
30
- #end
29
+ end
31
30
  LANGUAGES.each do |lang|
32
31
  # swissindex
33
32
  types.each do |type|
34
- #threads << Thread.new do
33
+ threads << Thread.new do
35
34
  downloader = SwissIndexDownloader.new(type)
36
35
  xml = downloader.download_by(lang)
37
- hsh = SwissIndexExtractor.new(xml, type).to_hash
38
- #@mutex.synchronize do
36
+ @mutex.synchronize do
37
+ hsh = SwissIndexExtractor.new(xml, type).to_hash
39
38
  @index[lang][type] = hsh
40
- #end
41
- #end
39
+ end
40
+ end
42
41
  end
43
42
  end
44
- #threads.map(&:join)
43
+ threads.map(&:join)
45
44
  build
46
45
  report
47
46
  end
@@ -65,12 +64,19 @@ module Oddb2xml
65
64
  builder.items = @items
66
65
  builder.tag_suffix = @options[:tag_suffix]
67
66
  end
67
+ if file =~ /(product)/
68
+ xml = builder.to_xml('substance')
69
+ File.open(file.gsub($1, 'substance'), 'w:utf-8'){ |fh| fh << xml }
70
+ end
68
71
  xml = builder.to_xml
69
72
  File.open(file, 'w:utf-8'){ |fh| fh << xml }
70
73
  end
71
74
  if @options[:compress_ext]
72
75
  compressor = Compressor.new(prefix, @options[:compress_ext])
73
76
  files.values.each do |file|
77
+ if file =~ /(product)/
78
+ compressor.contents << file.gsub($1, 'substance')
79
+ end
74
80
  compressor.contents << file
75
81
  end
76
82
  compressor.finalize!
@@ -14,7 +14,7 @@ module Oddb2xml
14
14
  super()
15
15
  end
16
16
  def finalize!
17
- unless @contents.select{ |file| File.exists?(file) }.length == 2
17
+ unless @contents.select{ |file| File.exists?(file) }.length == 3
18
18
  return false
19
19
  end
20
20
  begin
@@ -11,8 +11,6 @@ module Oddb2xml
11
11
  end
12
12
  class BagXmlExtractor < Extractor
13
13
  def to_hash
14
- #File.open('../bagxml.xml', 'r:ASCII-8BIT') {|f| @xml = f.read }
15
- # pharmacode => sequence
16
14
  data = {}
17
15
  doc = Nokogiri::XML(@xml)
18
16
  doc.xpath('//Preparation').each do |seq|
@@ -38,8 +36,9 @@ module Oddb2xml
38
36
  seq.xpath('.//Substance').each_with_index do |sub, i|
39
37
  item[:substances] << {
40
38
  :index => i.to_s,
41
- :quantity => (qtty = sub.at_xpath('.//Quantity')) ? qtty.text : '',
42
- :unit => (unit = sub.at_xpath('.//QuantityUnit')) ? unit.text : '',
39
+ :name => (name = sub.at_xpath('.//DescriptionLa')) ? name.text : '',
40
+ :quantity => (qtty = sub.at_xpath('.//Quantity')) ? qtty.text : '',
41
+ :unit => (unit = sub.at_xpath('.//QuantityUnit')) ? unit.text : '',
43
42
  }
44
43
  end
45
44
  item[:pharmacodes] = []
@@ -93,8 +92,6 @@ module Oddb2xml
93
92
  super(xml)
94
93
  end
95
94
  def to_hash
96
- #File.open("../swissindex_#{@type.downcase}.xml", 'r:ASCII-8BIT'){|f| @xml = f.read }
97
- # pharmacode => package
98
95
  data = {}
99
96
  doc = Nokogiri::XML(@xml)
100
97
  doc.remove_namespaces!
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
metadata CHANGED
@@ -1,48 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.8
3
+ version: !ruby/object:Gem::Version
4
+ hash: 5
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 9
10
+ version: 1.0.9
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Yasuhiro Asaka, Zeno R.R. Davatz
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-12-11 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rdoc
16
- requirement: &17164840 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
25
+ requirements:
19
26
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.10'
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
22
33
  type: :development
23
- prerelease: false
24
- version_requirements: *17164840
25
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
26
36
  name: hoe
27
- requirement: &17164160 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
28
39
  none: false
29
- requirements:
40
+ requirements:
30
41
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '2.13'
42
+ - !ruby/object:Gem::Version
43
+ hash: 25
44
+ segments:
45
+ - 2
46
+ - 13
47
+ version: "2.13"
33
48
  type: :development
34
- prerelease: false
35
- version_requirements: *17164160
36
- description: ''
37
- email:
49
+ version_requirements: *id002
50
+ description: ""
51
+ email:
38
52
  - yasaka@ywesee.com, zdavatz@ywesee.com
39
- executables:
53
+ executables:
40
54
  - oddb2xml
41
55
  extensions: []
42
- extra_rdoc_files:
56
+
57
+ extra_rdoc_files:
43
58
  - History.txt
44
59
  - Manifest.txt
45
- files:
60
+ files:
46
61
  - .gitignore
47
62
  - .rspec
48
63
  - Gemfile
@@ -73,28 +88,37 @@ files:
73
88
  - spec/spec_helper.rb
74
89
  homepage:
75
90
  licenses: []
91
+
76
92
  post_install_message:
77
- rdoc_options:
93
+ rdoc_options:
78
94
  - --main
79
95
  - README.txt
80
- require_paths:
96
+ require_paths:
81
97
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
98
+ required_ruby_version: !ruby/object:Gem::Requirement
83
99
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
108
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
94
116
  requirements: []
117
+
95
118
  rubyforge_project: oddb2xml
96
119
  rubygems_version: 1.8.15
97
120
  signing_key:
98
121
  specification_version: 3
99
- summary: ''
122
+ summary: ""
100
123
  test_files: []
124
+