oddb2xml 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 548c524682d20936d0b0dbc19734159021f14b1f
4
- data.tar.gz: 296253b38b02e80c06874f12eae3c8cdc48a3fdc
3
+ metadata.gz: 899a0f8501e70e79d800f160bfd50b4fbf370100
4
+ data.tar.gz: 54f75e31226c4676ee2b7f1a4c7c893c104dba27
5
5
  SHA512:
6
- metadata.gz: 0199e288fd594f3f084c78b08289ffe7495ac7ec4ce239f79a797faa90f606b5ebc26e6990892cfa147200f87b0a40bc532ce47fb4826c06581f3a193de14024
7
- data.tar.gz: 68104c147630445ab5c2a1a493bacab6c1a53c8bfae15f8f3a3903a865026164bfce8f1704812959450869bb522eeb82cc89a89cb3c1c6408ced64babf50e134
6
+ metadata.gz: 56dd104a5a3363d62de7ba797a1d5a20634365cf5282331a1c8c061561cdf4e0dedef81081af7c0c408522a0cf321ac240087dbd4031540da9e51c1964609e03
7
+ data.tar.gz: 370cdc20ba9bea205d03f97a44898c05ca46394eba0ded6003444f91ab2d8803be664ae1e55d9f6026f9271415ca22c2b4aed4246585a319a777b37882bd449c
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oddb2xml (2.1.6)
4
+ oddb2xml (2.1.7)
5
5
  archive-tar-minitar (~> 0.5.2)
6
6
  mechanize (~> 2.5.1)
7
- nokogiri (~> 1.5.10)
7
+ nokogiri
8
8
  parslet (~> 1.7.0)
9
9
  rubyXL (~> 3.3.1)
10
10
  rubyzip (~> 1.1.3)
@@ -51,9 +51,11 @@ GEM
51
51
  webrobots (~> 0.0, >= 0.0.9)
52
52
  method_source (0.8.2)
53
53
  mime-types (1.25.1)
54
+ mini_portile (0.6.2)
54
55
  net-http-digest_auth (1.4)
55
56
  net-http-persistent (2.9.4)
56
- nokogiri (1.5.11)
57
+ nokogiri (1.6.6.2)
58
+ mini_portile (~> 0.6.0)
57
59
  nori (2.3.0)
58
60
  ntlm-http (0.1.1)
59
61
  parslet (1.7.0)
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 2.1.7 / 15.06.2015
2
+
3
+ * Fixed option -o which did not produce any meaningful oddb_fi.xml
4
+ * Added KOMPENDIUM_PRODUCT to xsd file
5
+ * Added style for each KOMPENDIUM_PRODUCT
6
+
1
7
  === 2.1.6 / 10.06.2015
2
8
 
3
9
  * Avoid error when Packungen.xlsx does not contain a name for a product (upstream error, missing Combizym, Dragées)
@@ -965,13 +965,14 @@ module Oddb2xml
965
965
  'DT' => ''
966
966
  ) {
967
967
  unless info[:name].empty?
968
- xml.name { xml.p(info[:name]) }
968
+ xml.name info[:name]
969
969
  end
970
970
  unless info[:owner].empty?
971
- xml.owner { xml.p(info[:owner]) }
971
+ xml.owner info[:owner]
972
972
  end
973
973
  xml.monid info[:monid] unless info[:monid].empty?
974
- xml.paragraph { xml.cdata(info[:paragraph]) } unless info[:paragraph].empty?
974
+ xml.style { xml.cdata(info[:style]) } if info[:style]
975
+ xml.paragraph { xml.cdata(Nokogiri::HTML.fragment(info[:paragraph].to_html).to_html(:encoding => 'UTF-8')) } if info[:paragraph]
975
976
  }
976
977
  end
977
978
  end
@@ -997,21 +998,27 @@ module Oddb2xml
997
998
  @infos[lang].each_with_index do |info, i|
998
999
  info_index[info[:monid]] = i
999
1000
  end
1000
- end
1001
- @products.group_by{|obj| obj[:ean]
1002
- }.each_pair do |monid, products|
1003
- if info_index[monid]
1004
- xml.KP('DT' => '') {
1005
- xml.MONID monid
1006
- products.each do |obj|
1007
- xml.GTIN obj[:ean]
1008
- length += 1
1009
- end
1010
- # as orphans ?
1011
- xml.DEL(@orphans.include?(monid) ? true : false)
1012
- }
1001
+ # prod
1002
+ @products.each do |prod|
1003
+ next unless prod[:seq] and prod[:seq][:packages]
1004
+ seq = prod[:seq]
1005
+ prod[:seq][:packages].each {
1006
+ |phar, package|
1007
+ next unless package[:swissmedic_number8]
1008
+ m = /(\d{5})(\d{3})/.match(package[:swissmedic_number8])
1009
+ next unless m
1010
+ number = m[1].to_s
1011
+ idx = info_index[number]
1012
+ next unless idx
1013
+ xml.KP('DT' => '') {
1014
+ xml.MONID @infos[lang][idx][:monid]
1015
+ xml.PRDNO seq[:product_key] unless seq[:product_key].empty?
1016
+ # as orphans ?
1017
+ xml.DEL @orphans.include?(number) ? true : false
1018
+ }
1019
+ }
1020
+ end
1013
1021
  end
1014
- end
1015
1022
  xml.RESULT {
1016
1023
  xml.OK_ERROR 'OK'
1017
1024
  xml.NBR_RECORD length
@@ -354,25 +354,21 @@ module Oddb2xml
354
354
  item[:refdata] = true,
355
355
  item[:name] = (name = pac.title) ? name : ''
356
356
  item[:owner] = (ownr = pac.authHolder) ? ownr : ''
357
- if content = /cdata/.match(pac.content)
358
- html = Nokogiri::HTML(content.to_s)
359
- # all HTML contents without MonTitle and ownerCompany
360
- item[:paragraph] = "<title><p>#{item[:name]}</p></title>" +
361
- ((paragraph = html.xpath("///div[@class='paragraph']")) ? paragraph.to_s : '')
362
- if text = html.xpath("///div[@id='Section7750']/p").text
363
- # 1 ~ 3 swissmedic number
364
- if text =~ /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/
357
+ item[:style] = Nokogiri::HTML.fragment(pac.style).to_html(:encoding => 'UTF-8')
358
+ html = Nokogiri::HTML.fragment(pac.content.force_encoding('UTF-8'))
359
+ item[:paragraph] = html
360
+ numbers = /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/.match(html)
361
+ if numbers
365
362
  [$1, $2, $3].compact.each do |n| # plural
366
363
  item[:monid] = n
367
364
  data[lang] << item
368
365
  end
369
- end
370
- end
371
366
  end
372
367
  end
373
368
  data
374
369
  end
375
370
  end
371
+
376
372
  class EphaExtractor < Extractor
377
373
  def initialize(str)
378
374
  @io = StringIO.new(str)
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "2.1.6"
2
+ VERSION = "2.1.7"
3
3
  end
@@ -229,6 +229,7 @@ class MedicalInformationContent
229
229
  attribute :lang
230
230
  element :title
231
231
  element :authHolder
232
+ element :authNrs
232
233
  element :style
233
234
  element :content
234
235
  end
data/oddb2xml.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'rubyzip', '~> 1.1.3'
24
24
  spec.add_dependency 'archive-tar-minitar', '~> 0.5.2'
25
25
  spec.add_dependency 'mechanize', '~> 2.5.1'
26
- spec.add_dependency 'nokogiri', '~> 1.5.10'
26
+ spec.add_dependency 'nokogiri'
27
27
  spec.add_dependency 'savon', '~> 2.4.0'
28
28
  spec.add_dependency 'spreadsheet', '~> 1.0.0'
29
29
  spec.add_dependency 'rubyXL', '~> 3.3.1'
data/oddb2xml.xsd CHANGED
@@ -1113,4 +1113,51 @@
1113
1113
  </xs:restriction>
1114
1114
  </xs:simpleType>
1115
1115
  </xs:element>
1116
+ <xs:element name="KP">
1117
+ <xs:complexType>
1118
+ <xs:sequence>
1119
+ <xs:element name="MONID" type="xs:string" />
1120
+ <xs:element name="PRDNO" type="xs:string" />
1121
+ <xs:element name="DEL" type="xs:boolean" />
1122
+ </xs:sequence>
1123
+ <xs:attribute name="DT" use="required"/>
1124
+ </xs:complexType>
1125
+ </xs:element>
1126
+ <xs:element name="KOMPENDIUM_PRODUCT">
1127
+ <xs:complexType>
1128
+ <xs:sequence>
1129
+ <xs:element maxOccurs="unbounded" ref="ns1:KP"/>
1130
+ <xs:element ref="ns1:RESULT"/>
1131
+ </xs:sequence>
1132
+ <xs:attribute name="CREATION_DATETIME" use="required"/>
1133
+ <xs:attribute name="PROD_DATE" use="required"/>
1134
+ <xs:attribute name="VALID_DATE" use="required"/>
1135
+ </xs:complexType>
1136
+ </xs:element>
1137
+
1138
+ <xs:element name="KMP">
1139
+ <xs:complexType>
1140
+ <xs:sequence>
1141
+ <xs:element name="name" type="xs:string" />
1142
+ <xs:element name="owner" type="xs:string" />
1143
+ <xs:element name="monid" type="xs:string" />
1144
+ <xs:element name="style" type="xs:string" />
1145
+ <xs:element name="paragraph" type="xs:string" />
1146
+ </xs:sequence>
1147
+ <xs:attribute name="MONTYPE" use="required"/>
1148
+ <xs:attribute name="LANG" use="required"/>
1149
+ <xs:attribute name="DT" use="required"/>
1150
+ </xs:complexType>
1151
+ </xs:element>
1152
+ <xs:element name="KOMPENDIUM">
1153
+ <xs:complexType>
1154
+ <xs:sequence>
1155
+ <xs:element maxOccurs="unbounded" ref="ns1:KMP"/>
1156
+ <xs:element ref="ns1:RESULT"/>
1157
+ </xs:sequence>
1158
+ <xs:attribute name="CREATION_DATETIME" use="required"/>
1159
+ <xs:attribute name="PROD_DATE" use="required"/>
1160
+ <xs:attribute name="VALID_DATE" use="required"/>
1161
+ </xs:complexType>
1162
+ </xs:element>
1116
1163
  </xs:schema>
data/spec/builder_spec.rb CHANGED
@@ -32,7 +32,7 @@ def check_validation_via_xsd
32
32
  @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb2xml.xsd'))
33
33
  File.exists?(@oddb2xml_xsd).should eq true
34
34
  files = Dir.glob('*.xml')
35
- xsd = Nokogiri::XML::Schema(File.read(@oddb2xml_xsd))
35
+ xsd = Nokogiri::XML::Schema(File.read(@oddb2xml_xsd))
36
36
  files.each{
37
37
  |file|
38
38
  $stderr.puts "Validating file #{file} with #{File.size(file)} bytes" if $VERBOSE
@@ -55,6 +55,34 @@ describe Oddb2xml::Builder do
55
55
  after(:each) do
56
56
  Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
57
57
  end
58
+ context 'fachinfo' do
59
+ let(:cli) do
60
+ opts = {}
61
+ @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi.xml'))
62
+ @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi_product.xml'))
63
+ options = Oddb2xml::Options.new
64
+ options.parser.parse!(['-o'])
65
+ Oddb2xml::Cli.new(options.opts)
66
+ end
67
+
68
+ it 'should return produce a correct oddb_fi.xml' do
69
+ # res = buildr_capture(:stdout){ cli.run }
70
+ cli.run
71
+ File.exists?(@oddb_fi_xml).should eq true
72
+ inhalt = IO.read(@oddb_fi_xml)
73
+ /<KMP/.match(inhalt.to_s).to_s.should eq '<KMP'
74
+ /<style><!\[CDATA\[p{margin-top/.match(inhalt.to_s).to_s.should eq '<style><![CDATA[p{margin-top'
75
+ m = /<paragraph><!\[CDATA\[(.+)\n(.*)/.match(inhalt.to_s)
76
+ m[1].should eq '<?xml version="1.0" encoding="utf-8"?><div xmlns="http://www.w3.org/1999/xhtml">'
77
+ expected = '<p class="s2"> </p>'
78
+ m[2].should eq '<p class="s2"> </p>'
79
+ File.exists?(@oddb_fi_product_xml).should eq true
80
+ inhalt = IO.read(@oddb_fi_product_xml)
81
+ skip "Niklaus does not know how to create a valid oddb_fi_product.xml"
82
+ check_validation_via_xsd
83
+ end
84
+ end
85
+
58
86
  context 'XSD-generation: ' do
59
87
  let(:cli) do
60
88
  opts = {}
Binary file
@@ -62,10 +62,32 @@ describe Oddb2xml::MigelExtractor do
62
62
  end
63
63
 
64
64
  describe Oddb2xml::SwissmedicInfoExtractor do
65
+ include ServerMockHelper
65
66
  before(:each) do
66
- setup_epha_atc_csv_mock
67
+ setup_swissmedic_info_server_mock
68
+ @downloader = Oddb2xml::SwissmedicInfoDownloader.new
67
69
  end
70
+ context 'builds fachfinfo' do
71
+ it {
72
+ xml = @downloader.download
73
+ @infos = Oddb2xml::SwissmedicInfoExtractor.new(xml).to_hash
74
+ expect(@infos.size).to eq(1)
75
+ erbiumcitrat = nil
76
+ @infos['de'].each{|info|
77
+ erbiumcitrat = info if /Erbiumcitrat/.match(info[:name])
78
+ }
79
+ expect(erbiumcitrat[:owner]).to eq('CBI Medical Products Vertriebs GmbH')
80
+ expect(erbiumcitrat[:paragraph].to_s).to match(/Packungen/)
81
+ expect(erbiumcitrat[:paragraph].to_s).to match(/Stand der Information/)
82
+ expect(erbiumcitrat[:paragraph].to_s).to match(/Zulassungsinhaberin/)
83
+ }
84
+ end
85
+ end
68
86
 
87
+ describe Oddb2xml::SwissmedicExtractor do
88
+ before(:each) do
89
+ setup_epha_atc_csv_mock
90
+ end
69
91
  context 'when transfer.dat is empty' do
70
92
  subject { Oddb2xml::SwissmedicInfoExtractor.new("") }
71
93
  it { expect(subject.to_hash).to be_empty }
@@ -123,7 +145,6 @@ describe Oddb2xml::MedregbmExtractor do
123
145
  end
124
146
 
125
147
  describe Oddb2xml::ZurroseExtractor do
126
- if false
127
148
  context 'when transfer.dat is empty' do
128
149
  subject { Oddb2xml::ZurroseExtractor.new("") }
129
150
  it { expect(subject.to_hash).to be_empty }
@@ -200,11 +221,10 @@ if false
200
221
  DAT
201
222
  Oddb2xml::ZurroseExtractor.new(dat, true)
202
223
  end
203
- #it { expect(subject.to_hash.keys.first).to eq("7680316950157") }
224
+ it { expect(subject.to_hash.keys.first).to eq("0000008807890") }
204
225
  it "should set the correct SALECD cmut code" do expect(subject.to_hash.values.first[:cmut]).to eq("2") end
205
- it "should set the correct SALECD description" do expect(subject.to_hash.values.first[:description]).to eq("Ethacridin lactat 1‰ 100ml") end
206
- end if false
207
- end
226
+ it "should set the correct SALECD description" do expect(subject.to_hash.values.first[:description]).to match(/Ethacridin lactat 1.+ 100ml/) end
227
+ end
208
228
  context 'when parsing examples' do
209
229
  subject do
210
230
  filename = File.expand_path(File.join(__FILE__, '..', 'data', 'zurrose_transfer.dat'))
@@ -228,6 +248,4 @@ end
228
248
 
229
249
  end
230
250
 
231
-
232
-
233
251
  end
data/test_options.rb CHANGED
@@ -56,6 +56,7 @@ unless 'localhost.localdomain'.eql?(Socket.gethostbyname(Socket.gethostname).fir
56
56
  test_one_call('oddb2xml --append')
57
57
  end
58
58
  test_one_call('oddb2xml -t md -c tar.gz')
59
+ test_one_call('oddb2xml -o')
59
60
  test_one_call('oddb2xml -f xml')
60
61
  test_one_call('oddb2xml -f dat')
61
62
  test_one_call('oddb2xml -t md')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhiro Asaka, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.5.10
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.5.10
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: savon
71
71
  requirement: !ruby/object:Gem::Requirement