medreg 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f55cbd956da4f88e6ba28632b08daa57a98aeb6e
4
+ data.tar.gz: c532ca10792ce3bdf697ebebbff3be28e722bd2f
5
+ SHA512:
6
+ metadata.gz: 23bc712a7f410702280f18435b709b0181a946d38a1f71f68db9f233e54e310a145070ffb1162445965c10d3c6a1c05ab02fff37b353cf2522647f03529ce472
7
+ data.tar.gz: e05592a21ceab1c630cf0da1ccdd75f8d1a42685aac99eea263ee16e87c843fa5592379ed3e34bc953d3f37b4e08ae6ac7f778292252a99371fb952b81774131
@@ -5,6 +5,8 @@ before_install:
5
5
  install:
6
6
  - bundle install --without debugger
7
7
 
8
+ cache: bundler
9
+
8
10
  script:
9
11
  - bundle exec ruby test/suite.rb
10
12
 
@@ -13,10 +15,10 @@ notifications:
13
15
  - ngiger@ywesee.com
14
16
  rvm:
15
17
  - ruby-head
16
- - 2.1.2
18
+ - 2.1.3
17
19
  - 2.0.0
18
20
  - 1.9.3
19
- - 1.8.7
20
21
  matrix:
21
22
  allow_failures:
22
23
  - rvm: ruby-head
24
+ - rvm: 1.8.7
@@ -1,3 +1,7 @@
1
- === 0.1
1
+ === 0.1.1
2
+
3
+ * Some improvments to merge yaml Files.
4
+
5
+ === 0.1.0
2
6
 
3
7
  * Initial release
@@ -2,16 +2,27 @@ h1. medreg
2
2
 
3
3
  * https://github.com/zdavatz/medreg
4
4
 
5
+ We use Travis-CI to ensure that our builds are always passing the unit test. !https://travis-ci.org/ngiger/medreg.svg?branch=master!:https://travis-ci.org/ngiger/medreg
6
+
5
7
  h2. DESCRIPTION
6
8
 
7
9
  Create yaml file for all
8
- * companies in the health care fromh https://www.medregbm.admin.ch/
10
+ * companies in the health care from https://www.medregbm.admin.ch/
9
11
  * medical persons from http://www.medregom.admin.ch/
10
12
 
11
13
  h2. INSTALL:
12
14
 
13
15
  * gem install medreg
14
16
 
17
+
18
+ h2. Useage
19
+
20
+ * @medreg -h@ # give helpl
21
+ * @medreg @ # get info from medreg for all doctors and pharmacies
22
+ * @medreg persons@ # get info from medreg for all doctors
23
+ * @medreg companies@ # get info from medreg for all pharmacies
24
+ * @merge_yaml output input_file_1 ..@ # merge all input files into the output
25
+
15
26
  h2. DEVELOPERS:
16
27
 
17
28
  * Zeno R.R. Davatz
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ root = Pathname.new(__FILE__).realpath.parent.parent
5
+ $:.unshift root.join('lib') if $0 == __FILE__
6
+
7
+ require 'optparse'
8
+ require "date"
9
+ require 'medreg'
10
+ require 'medreg/version'
11
+ require 'medreg/person'
12
+
13
+ ODDB = Medreg
14
+ def help
15
+ <<EOS
16
+ #$0 ver.#{Medreg::VERSION}
17
+ Usage:
18
+ #{File.basename(__FILE__)} output input_file_1..
19
+ Merge all input files into output_file
20
+ EOS
21
+ end
22
+
23
+ parser = OptionParser.new
24
+ opts = {}
25
+ parser.on_tail('-h', '--help') { puts help; exit }
26
+
27
+ args = ARGV.dup
28
+ begin
29
+ parser.parse!(args)
30
+ rescue OptionParser::MissingArgument,
31
+ OptionParser::InvalidArgument,
32
+ OptionParser::InvalidOption
33
+ puts help
34
+ exit 1
35
+ end
36
+
37
+ begin
38
+ unless args.size >= 2
39
+ puts help
40
+ exit 1
41
+ end
42
+ all = {}
43
+ to_add = {}
44
+ puts args.inspect
45
+ args[1..-1].each{
46
+ |input|
47
+ next if File.size(input) < 100
48
+ puts "reading from file #{input} #{File.size(input)} bytes"
49
+ to_add = YAML.load_file(input)
50
+ all = all.merge(to_add)
51
+ puts "Added to_add #{to_add.class} #{to_add.size}. Have now #{all.size} items"
52
+ }
53
+ puts "Have now #{all.size} items to be save into #{args[0]}"
54
+ File.open(args[0], 'w+') {|f| f.write(all.to_yaml) }
55
+ puts "Saved #{all.size} items into #{args[0]}. Size is #{(File.size(args[0])/1024).to_i} kBytes"
56
+ rescue Interrupt
57
+ puts "Unterbrochen. Breche mit Fehler ab"
58
+ exit 1
59
+ end
60
+
61
+ puts "#{__FILE__} completed successfully" if $VERBOSE
@@ -13,7 +13,7 @@ require 'psych' if RUBY_VERSION.match(/^1\.9/)
13
13
  require "yaml"
14
14
 
15
15
  module Medreg
16
- DebugImport = defined?(MiniTest)
16
+ DebugImport = defined?(Minitest) ? true : false
17
17
  BetriebeURL = 'https://www.medregbm.admin.ch/Betrieb/Search'
18
18
  BetriebeXLS_URL = "https://www.medregbm.admin.ch/Publikation/CreateExcelListBetriebs"
19
19
  RegExpBetriebDetail = /\/Betrieb\/Details\//
@@ -63,25 +63,36 @@ module Medreg
63
63
  @@logInfo = []
64
64
  FileUtils.rm_f(Companies_YAML) if File.exists?(Companies_YAML)
65
65
  @yaml_file = File.open(Companies_YAML, 'w+')
66
+ @companies_prev_import = 0
66
67
  @companies_created = 0
67
- @companies_updated = 0
68
68
  @companies_skipped = 0
69
69
  @companies_deleted = 0
70
70
  @archive = ARCHIVE_PATH
71
- @@all_companies = []
71
+ @@all_companies = {}
72
72
  setup_default_agent
73
73
  end
74
+ def save_import_to_yaml(filename)
75
+ File.open(filename, 'w+') {|f| f.write(@@all_companies.to_yaml) }
76
+ save_for_log "Saved #{@@all_companies.size} doctors in #{filename}"
77
+ end
74
78
  def update
75
79
  saved = @glns_to_import.clone
80
+ r_loop = ResilientLoop.new(File.basename(__FILE__, '.rb'))
81
+ @state_yaml = r_loop.state_file.sub('.state', '.yaml')
82
+ if File.exist?(@state_yaml) and File.size(@state_yaml) > 10
83
+ @@all_companies = YAML.load_file(@state_yaml)
84
+ @companies_prev_import = @@all_companies.size
85
+ puts "Got #{@companies_prev_import} items from previous import saved in #{@state_yaml}"
86
+ end
76
87
  latest = get_latest_file
77
88
  save_for_log "parse_xls #{latest} specified GLN ids #{saved.inspect}"
78
89
  parse_xls(latest)
79
90
  @info_to_gln.keys
80
91
  get_detail_to_glns(saved.size > 0 ? saved : @glns_to_import)
81
- return @companies_created, @companies_updated, @companies_deleted, @companies_skipped
92
+ save_import_to_yaml(Companies_YAML)
93
+ return @companies_created, @companies_prev_import, @companies_deleted, @companies_skipped
82
94
  ensure
83
- File.open(Companies_YAML, 'w+') {|f| f.write(@@all_companies.to_yaml) }
84
- save_for_log "Saved #{@@all_companies.size} companies in #{Companies_YAML}"
95
+ save_import_to_yaml(@state_yaml) if @companies_created > 0
85
96
  end
86
97
  def setup_default_agent
87
98
  @agent = Mechanize.new
@@ -139,7 +150,7 @@ module Medreg
139
150
  while nr_tries < max_retries and not success
140
151
  begin
141
152
  r_loop.try_run(gln, defined?(Minitest) ? 500 : 5 ) do
142
- Medreg.log "Searching for company with GLN #{gln}. Skipped #{@companies_skipped}, created #{@companies_created} updated #{@companies_updated} of #{glns.size}).#{nr_tries > 0 ? ' nr_tries is ' + nr_tries.to_s : ''}"
153
+ Medreg.log "Searching for company with GLN #{gln}. Created #{@companies_created}. At #{@companies_created+@companies_prev_import} of #{glns.size}.#{nr_tries > 0 ? ' nr_tries is ' + nr_tries.to_s : ''}"
143
154
  page_1 = @agent.get(BetriebeURL)
144
155
  raise Search_failure if page_1.content.match(failure)
145
156
  hash = [
@@ -156,7 +167,7 @@ module Medreg
156
167
  raise Search_failure if page_3.content.match(failure)
157
168
  company = parse_details(page_3, gln)
158
169
  store_company(company)
159
- @@all_companies << company
170
+ @@all_companies[gln] = company
160
171
  else
161
172
  Medreg.log "could not find gln #{gln}"
162
173
  @companies_skipped += 1
@@ -169,8 +180,8 @@ module Medreg
169
180
  nr_tries += 1
170
181
  sleep defined?(MiniTest) ? 0.01 : 60
171
182
  end
172
- if (@companies_created + @companies_updated) % 100 == 99
173
- Medreg.log "Start saving #{gln} after #{@companies_created} created #{@companies_updated} updated"
183
+ if (@companies_created + @companies_prev_import) % 100 == 99
184
+ Medreg.log "Start saving after #{@companies_created} created #{@companies_prev_import} from previous import"
174
185
  end
175
186
  end
176
187
  }
@@ -193,7 +204,7 @@ module Medreg
193
204
  def report
194
205
  report = "Companies update \n\n"
195
206
  report << "New companies: " << @companies_created.to_s << "\n"
196
- report << "Updated companies: " << @companies_updated.to_s << "\n"
207
+ report << "Companies from previous imports: " << @companies_prev_import.to_s << "\n"
197
208
  report << "Deleted companies: " << @companies_deleted.to_s << "\n"
198
209
  report
199
210
  end
@@ -255,7 +266,7 @@ module Medreg
255
266
  end
256
267
  @glns_to_import = @info_to_gln.keys.sort.uniq
257
268
  end
258
- def Company.all_companies
269
+ def CompanyImporter.all_companies
259
270
  @@all_companies
260
271
  end
261
272
  end
@@ -16,7 +16,7 @@ require "yaml"
16
16
  require 'timeout'
17
17
 
18
18
  module Medreg
19
- DebugImport = false
19
+ DebugImport = defined?(Minitest) ? true : false
20
20
  Personen_Candidates = File.expand_path(File.join(__FILE__, '../../../data/Personen_20*.xlsx'))
21
21
  Personen_YAML = File.expand_path(File.join(__FILE__, "../../../data/persons_#{Time.now.strftime('%Y.%m.%d-%H%M')}.yaml"))
22
22
  Personen_CSV = File.expand_path(File.join(__FILE__, "../../../data/persons_#{Time.now.strftime('%Y.%m.%d-%H%M')}.csv"))
@@ -57,7 +57,7 @@ module Medreg
57
57
  withTimeStamp = "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}: #{msg}" unless defined?(MiniTest)
58
58
  @@logInfo << withTimeStamp
59
59
  end
60
- def initialize(app=nil, glns_to_import = [])
60
+ def initialize(glns_to_import = [])
61
61
  @glns_to_import = glns_to_import.clone
62
62
  @glns_to_import.delete_if {|item| item.size == 0}
63
63
  @info_to_gln = {}
@@ -67,10 +67,10 @@ module Medreg
67
67
  FileUtils.mkdir_p(File.dirname(Personen_YAML))
68
68
  @yaml_file = File.open(Personen_YAML, 'w+')
69
69
  @csv_file = File.open(Personen_CSV, 'w+')
70
- @persons_created = 0
71
- @persons_updated = 0
70
+ @persons_prev_import = 0
72
71
  @persons_skipped = 0
73
72
  @persons_deleted = 0
73
+ @persons_created = 0
74
74
  @skip_to_doctor = nil
75
75
  @archive = ARCHIVE_PATH
76
76
  @@all_doctors = {}
@@ -92,18 +92,31 @@ module Medreg
92
92
  @@all_doctors.each{ |doctor| csv << [] }
93
93
  end
94
94
  end
95
+
96
+ def save_import_to_yaml(filename)
97
+ File.open(filename, 'w+') {|f| f.write(@@all_doctors.to_yaml) }
98
+ save_for_log "Saved #{@@all_doctors.size} doctors in #{filename}"
99
+ end
100
+
95
101
  def update
96
102
  saved = @glns_to_import.clone
103
+ r_loop = ResilientLoop.new(File.basename(__FILE__, '.rb'))
104
+ @state_yaml = r_loop.state_file.sub('.state', '.yaml')
105
+ if File.exist?(@state_yaml)
106
+ @@all_doctors = YAML.load_file(@state_yaml)
107
+ @persons_prev_import = @@all_doctors.size
108
+ puts "Got #{@persons_prev_import} items from previous import saved in #{@state_yaml}"
109
+ end
97
110
  latest = get_latest_file
98
111
  save_for_log "parse_xls #{latest} specified GLN glns #{saved.inspect}"
99
112
  parse_xls(latest)
100
113
  @info_to_gln.keys
101
114
  get_detail_to_glns(saved.size > 0 ? saved : @glns_to_import)
102
- return @persons_created, @persons_updated, @persons_deleted, @persons_skipped
115
+ save_import_to_yaml(Personen_YAML)
116
+ return @persons_created, @persons_prev_import, @persons_deleted, @persons_skipped
103
117
  ensure
104
118
  # write_csv_file
105
- File.open(Personen_YAML, 'w+') {|f| f.write(@@all_doctors.to_yaml) }
106
- save_for_log "Saved #{@@all_doctors.size} doctors in #{Personen_YAML}"
119
+ save_import_to_yaml(@state_yaml) if @persons_created > 0
107
120
  end
108
121
  def setup_default_agent
109
122
  @agent = Mechanize.new
@@ -212,6 +225,7 @@ module Medreg
212
225
  end
213
226
  medregId = page_4.body.match(regExp)[1]
214
227
  page_5 = @agent.get(MedRegOmURL + "de/Detail/Detail?pid=#{medregId}")
228
+
215
229
  File.open(File.join(LOG_PATH, "#{gln}.html"), 'w+') { |f| f.write page_5.content } if DebugImport
216
230
  doc_hash = parse_details( Nokogiri::HTML(page_5.content), gln, info)
217
231
  store_doctor(doc_hash)
@@ -234,7 +248,7 @@ module Medreg
234
248
  nr_tries = 0
235
249
  while nr_tries < max_retries
236
250
  begin
237
- Medreg.log "Searching for doctor with GLN #{gln}. Skipped #{@persons_skipped}, created #{@persons_created} updated #{@persons_updated} of #{glns.size}).#{nr_tries > 0 ? ' nr_tries is ' + nr_tries.to_s : ''}"
251
+ Medreg.log "Searching for doctor with GLN #{gln}. Created #{@persons_created}. At #{@persons_created+@persons_prev_import} of #{glns.size}.#{nr_tries > 0 ? ' nr_tries is ' + nr_tries.to_s : ''}"
238
252
  get_one_doctor(r_loop, gln)
239
253
  break
240
254
  rescue Mechanize::ResponseCodeError, Timeout::Error => e
@@ -251,8 +265,8 @@ module Medreg
251
265
  end
252
266
  raise "Max retries #{nr_tries} for #{gln.to_s} reached. Aborting import" if nr_tries == max_retries
253
267
  @persons_created += 1
254
- if (@persons_created + @persons_updated) % 100 == 99
255
- Medreg.log "Start saving after #{@persons_created} created #{@persons_updated} updated"
268
+ if (@persons_created + @persons_prev_import) % 100 == 99
269
+ Medreg.log "Start saving after #{@persons_created} created #{@persons_prev_import} from previous import"
256
270
  end
257
271
  }
258
272
  r_loop.finished
@@ -329,7 +343,7 @@ module Medreg
329
343
  report = "Persons update \n\n"
330
344
  report << "Skipped doctors: #{@persons_skipped}#{@skip_to_doctor ? '. Waited for ' + @skip_to_doctor.to_s : ''}" << "\n"
331
345
  report << "New doctors: " << @persons_created.to_s << "\n"
332
- report << "Updated doctors: " << @persons_updated.to_s << "\n"
346
+ report << "Doctors from previous imports: " << @persons_prev_import.to_s << "\n"
333
347
  report << "Deleted doctors: " << @persons_deleted.to_s << "\n"
334
348
  report
335
349
  end
@@ -375,7 +389,7 @@ module Medreg
375
389
  }
376
390
  end
377
391
  def parse_xls(path)
378
- Medreg.log "parsing #{path}"
392
+ Medreg.log "parsing #{path}"
379
393
  workbook = RubyXL::Parser.parse(path)
380
394
  positions = []
381
395
  rows = 0
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Medreg
4
- VERSION = '0.1'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "flexmock"
25
25
  spec.add_development_dependency "simplecov"
26
- spec.add_development_dependency "minitest" if /^1\./.match(RUBY_VERSION)
26
+ spec.add_development_dependency "minitest"
27
27
  end
28
28
 
@@ -9,45 +9,24 @@ $: << File.expand_path("../../src", File.dirname(__FILE__))
9
9
  gem 'minitest'
10
10
  require 'minitest/autorun'
11
11
  require 'flexmock'
12
- require 'medreg/company'
12
+ require 'medreg/company_importer'
13
13
  require 'tempfile'
14
14
 
15
15
  module Medreg
16
16
  class TestCompanyPlugin <Minitest::Test
17
17
  include FlexMock::TestCase
18
18
  Test_Companies_XLSX = File.expand_path(File.join(__FILE__, '../data/companies_20141014.xlsx'))
19
+ def rm_log_files
20
+ FileUtils.rm_f(Dir.glob("#{Medreg::LOG_PATH}/*"), :verbose => true)
21
+ end
19
22
  def setup
20
- @config = flexmock('config',
21
- :empty_ids => nil,
22
- :pointer => 'pointer'
23
- )
24
- @config = flexmock('config')
25
- @company = flexmock('company', :pointer => 'pointer',
26
- :ean13= => 'ean13',
27
- :name= => 'name',
28
- :addresses= => 'addresses',
29
- :business_area= => 'business_area',
30
- :odba_isolated_store => 'odba_isolated_store',
31
- :oid => 'oid',
32
- :narcotics= => 'narcotics',
33
- :odba_store => 'odba_store',
34
- )
35
- @app = flexmock('appX',
36
- :config => @config,
37
- :create_company => @company,
38
- :companies => [@company],
39
- :company_by_gln => nil,
40
- :company_by_origin => @company,
41
- :update => 'update',
42
- )
43
- @plugin = Medreg::Company.new(@app)
44
- flexmock(@plugin, :get_latest_file => [true, Test_Companies_XLSX])
23
+ rm_log_files
45
24
  $stderr.puts "Test_Companies_XLSX #{Test_Companies_XLSX}"
46
25
  end
47
26
 
48
27
  def test_update_7601002026444
49
- @plugin = Medreg::Company.new(@app, [7601001396371])
50
- flexmock(@plugin, :get_latest_file => [true, Test_Companies_XLSX])
28
+ @plugin = Medreg::CompanyImporter.new([7601001396371])
29
+ flexmock(@plugin, :get_latest_file => Test_Companies_XLSX)
51
30
  flexmock(@plugin, :get_company_data => {})
52
31
  flexmock(@plugin, :puts => nil)
53
32
  startTime = Time.now
@@ -60,29 +39,29 @@ class TestCompanyPlugin <Minitest::Test
60
39
  assert_equal(0, updated)
61
40
  assert_equal(0, deleted)
62
41
  assert_equal(0, skipped)
63
- assert_equal(1, Medreg::Company.all_companies.size)
42
+ assert_equal(1, Medreg::CompanyImporter.all_companies.size)
64
43
  assert(File.exists?(csv_file), "file #{csv_file} must be created")
65
- linden = Medreg::Company.all_companies.first
44
+ linden = Medreg::CompanyImporter.all_companies[7601001396371]
66
45
  addresses = linden[:addresses]
67
46
  assert_equal(1, addresses.size)
68
47
  first_address = addresses.first
69
- assert_equal(ODDB::Address2, first_address.class)
70
- assert_equal(nil, first_address.fon)
48
+ assert_equal(Medreg::Address2, first_address.class)
49
+ assert_equal([], first_address.fon)
71
50
  assert_equal('5102 Rupperswil', first_address.location)
72
51
  assert_equal('öffentliche Apotheke', linden[:ba_type])
73
52
  assert_equal('5102', first_address.plz)
74
53
  assert_equal('Rupperswil', first_address.city)
75
54
  assert_equal('4', first_address.number)
76
55
  assert_equal('Mitteldorf', first_address.street)
77
- assert_equal(nil, first_address.additional_lines)
56
+ assert_equal([], first_address.additional_lines)
78
57
  assert_equal('AB Lindenapotheke AG', first_address.name)
79
58
  inhalt = IO.read(csv_file)
80
59
  assert(inhalt.index('6011 Verzeichnis a/b/c BetmVV-EDI') > 0, 'must find btm')
81
60
  # 7601001396371 AB Lindenapotheke AG Mitteldorf 4 5102 Rupperswil Aargau Schweiz öffentliche Apotheke 6011 Verzeichnis a/b/c BetmVV-EDI
82
61
  end
83
62
  def test_update_all
84
- @plugin = Medreg::Company.new(@app)
85
- flexmock(@plugin, :get_latest_file => [true, Test_Companies_XLSX])
63
+ @plugin = Medreg::CompanyImporter.new()
64
+ flexmock(@plugin, :get_latest_file => Test_Companies_XLSX)
86
65
  flexmock(@plugin, :get_company_data => {})
87
66
  flexmock(@plugin, :puts => nil)
88
67
  startTime = Time.now
@@ -101,12 +80,10 @@ class TestCompanyPlugin <Minitest::Test
101
80
  def test_get_latest_file
102
81
  current = File.expand_path(File.join(__FILE__, "../../../data/xls/companies_#{Time.now.strftime('%Y.%m.%d')}.xlsx"))
103
82
  FileUtils.rm_f(current) if File.exists?(current)
104
- @plugin = Medreg::Company.new(@app)
83
+ @plugin = Medreg::CompanyImporter.new()
105
84
  res = @plugin.get_latest_file
106
- assert(res[0], 'needs_update must be true')
107
- assert(res[1].match(/latest/), 'filename must match latest')
108
- assert(File.exists?(res[1]), 'companies_latest.xls must exist')
109
- assert(File.size(Test_Companies_XLSX) <File.size(res[1]))
85
+ assert(res.match(Time.now.strftime('%Y.%m.%d')), "filename must match latest not #{res}")
86
+ assert(File.size(Test_Companies_XLSX) <File.size(res))
110
87
  end
111
88
  end
112
89
  end
@@ -2,12 +2,12 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  $: << File.expand_path('..', File.dirname(__FILE__))
5
- $: << File.expand_path("../../src", File.dirname(__FILE__))
6
-
5
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
6
+ puts File.expand_path("../lib", File.dirname(__FILE__))
7
7
  gem 'minitest'
8
8
  require 'minitest/autorun'
9
9
  require 'flexmock'
10
- require 'medreg/person'
10
+ require 'medreg/person_importer'
11
11
  require 'tempfile'
12
12
  require 'ostruct'
13
13
 
@@ -16,20 +16,13 @@ Minitest::Test.i_suck_and_my_tests_are_order_dependent!()
16
16
  class TestPerson <Minitest::Test
17
17
  include FlexMock::TestCase
18
18
  RunTestTakingLong = false
19
- Test_Personen_XLSX = File.expand_path(File.join(__FILE__, '../../data/xlsx/Personen_20141014.xlsx'))
19
+ Test_Personen_XLSX = File.expand_path(File.join(__FILE__, '../data/Personen_20141014.xlsx'))
20
+ def rm_log_files
21
+ FileUtils.rm_f(Dir.glob("#{Medreg::LOG_PATH}/*"), :verbose => true)
22
+ end
23
+
20
24
  def setup
21
- @config = flexmock('config')
22
- @doctor = flexmock('doctor', :pointer => 'pointer', :oid => 'oid')
23
- @app = flexmock('app',
24
- :config => @config,
25
- :doctors => [@doctor],
26
- :create_doctor => @doctor,
27
- :doctor_by_gln => nil,
28
- :doctor_by_origin => @doctor,
29
- :update => 'update'
30
- )
31
- @plugin = Medreg::Person.new(@app)
32
- flexmock(@plugin, :get_latest=> Test_Personen_XLSX)
25
+ rm_log_files
33
26
  end
34
27
 
35
28
  SomeTestCases = {
@@ -41,12 +34,13 @@ class TestPerson <Minitest::Test
41
34
  def test_aaa_zuest # name starts with aaa we want this test to be run as first
42
35
  { 7601000254207 => OpenStruct.new(:family_name => 'Züst', :first_name => 'Peter', :authority => 'Glarus')}.each do
43
36
  |gln, info|
44
- @plugin = Medreg::Person.new(@app, [gln])
45
- flexmock(@plugin, :get_latest_file => [ true, Test_Personen_XLSX ] )
37
+ rm_log_files
38
+ @plugin = Medreg::PersonImporter.new([gln])
39
+ flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
46
40
  flexmock(@plugin, :get_doctor_data => {})
47
- assert(File.exists?(Test_Personen_XLSX))
41
+ assert(File.exists?(Test_Personen_XLSX) , "File #{Test_Personen_XLSX} must exist")
48
42
  startTime = Time.now
49
- csv_file = ODDB::Doctors::Personen_YAML
43
+ csv_file = Medreg::Personen_YAML
50
44
  FileUtils.rm_f(csv_file) if File.exists?(csv_file)
51
45
  created, updated, deleted, skipped = @plugin.update
52
46
  diffTime = (Time.now - startTime).to_i
@@ -74,7 +68,7 @@ class TestPerson <Minitest::Test
74
68
  addresses = zuest[:addresses]
75
69
  assert_equal(1, addresses.size)
76
70
  first_address = addresses.first
77
- assert_equal(ODDB::Address2, first_address.class)
71
+ assert_equal(Medreg::Address2, first_address.class)
78
72
  assert_equal(1, first_address.fon.size)
79
73
  assert_equal(['Bahnhofstr. 3'], first_address.additional_lines)
80
74
  assert_equal('8753 Mollis', first_address.location)
@@ -87,33 +81,17 @@ class TestPerson <Minitest::Test
87
81
  assert_equal('3', first_address.number)
88
82
  end
89
83
  end
90
- def test_parse
91
- SomeTestCases.each{
92
- |gln, info|
93
- info.gln = gln
94
- root = File.expand_path(File.join(__FILE__, "../.."))
95
- @plugin = Medreg::Person.new(@app, [gln])
96
- html_file = "#{root}/data/html/medreg/#{gln}.html"
97
- assert(File.exist?(html_file), "File \#{html_file} must exist")
98
- doc_hash = @plugin.parse_details(Nokogiri::HTML(File.read(html_file)),
99
- gln,
100
- info,
101
- )
102
- assert(doc_hash.is_a?(Hash), 'doc_hash must be a Hash')
103
- assert(doc_hash[:addresses], 'doc_hash must have addresses')
104
- assert(doc_hash[:addresses].size > 0, 'doc_hash must have at least one address')
105
- }
106
- end
107
84
 
108
85
  def test_update_single
109
86
  SomeTestCases.each{
110
87
  |gln, info|
111
- @plugin = Medreg::Person.new(@app, [gln])
112
- flexmock(@plugin, :get_latest_file => [ true, Test_Personen_XLSX ] )
88
+ rm_log_files
89
+ @plugin = Medreg::PersonImporter.new([gln])
90
+ flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
113
91
  flexmock(@plugin, :get_doctor_data => {})
114
92
  assert(File.exists?(Test_Personen_XLSX))
115
93
  startTime = Time.now
116
- csv_file = ODDB::Doctors::Personen_YAML
94
+ csv_file = Medreg::Personen_YAML
117
95
  FileUtils.rm_f(csv_file) if File.exists?(csv_file)
118
96
  created, updated, deleted, skipped = @plugin.update
119
97
  diffTime = (Time.now - startTime).to_i
@@ -122,7 +100,7 @@ class TestPerson <Minitest::Test
122
100
  assert_equal(1, created)
123
101
  assert_equal(0, updated)
124
102
  assert(File.exists?(csv_file), "file #{csv_file} must be created")
125
- expected = "Doctors update \n\nNumber of doctors: 1\nSkipped doctors: 0\nNew doctors: 1\nUpdated doctors: 0\nDeleted doctors: 0\n"
103
+ expected = "Persons update \n\nSkipped doctors: 0\nNew doctors: 1\nDoctors from previous imports: 0\nDeleted doctors: 0\n"
126
104
  assert_equal(expected, @plugin.report)
127
105
  }
128
106
  end
@@ -130,13 +108,13 @@ class TestPerson <Minitest::Test
130
108
  def test_update_some_glns
131
109
  glns_ids_to_search = [7601000078261, 7601000813282, 7601000254207, 7601000186874, 7601000201522, 7601000295958,
132
110
  7601000010735, 7601000268969, 7601000019080, 7601000239730 ]
133
- @plugin = Medreg::Person.new(@app, glns_ids_to_search)
111
+ @plugin = Medreg::PersonImporter.new(glns_ids_to_search)
134
112
 
135
- flexmock(@plugin, :get_latest_file => [ true, Test_Personen_XLSX ] )
113
+ flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
136
114
  flexmock(@plugin, :get_doctor_data => {})
137
115
  assert(File.exists?(Test_Personen_XLSX))
138
116
  startTime = Time.now
139
- csv_file = ODDB::Doctors::Personen_YAML
117
+ csv_file = Medreg::Personen_YAML
140
118
  FileUtils.rm_f(csv_file) if File.exists?(csv_file)
141
119
  created, updated, deleted, skipped = @plugin.update
142
120
  diffTime = (Time.now - startTime).to_i
@@ -148,7 +126,26 @@ class TestPerson <Minitest::Test
148
126
  end if RunTestTakingLong
149
127
 
150
128
  def test_zzz_get_latest_file # name starts with zzz we want this test to be run as last one (takes longest)
151
- @plugin = Medreg::Person.new(@app, [7601000813282])
129
+ @plugin = Medreg::PersonImporter.new([7601000813282])
152
130
  needs_update, latest = @plugin.get_latest_file
153
131
  end if RunTestTakingLong
132
+
133
+ def test_parse
134
+ SomeTestCases.each{
135
+ |gln, info|
136
+ info.gln = gln
137
+ root = File.expand_path(File.join(__FILE__, "../.."))
138
+ @plugin = Medreg::PersonImporter.new([gln])
139
+ html_file = File.expand_path(File.join(__FILE__, "../data/#{gln}.html"))
140
+ assert(File.exist?(html_file), "File #{html_file} must exist")
141
+ doc_hash = @plugin.parse_details(Nokogiri::HTML(File.read(html_file)),
142
+ gln,
143
+ info,
144
+ )
145
+ assert(doc_hash.is_a?(Hash), 'doc_hash must be a Hash')
146
+ assert(doc_hash[:addresses], 'doc_hash must have addresses')
147
+ assert(doc_hash[:addresses].size > 0, 'doc_hash must have at least one address')
148
+ }
149
+ end
150
+
154
151
  end
@@ -14,7 +14,10 @@ module ODBA
14
14
  def setup
15
15
  end
16
16
  def test_company_importer
17
- assert Medreg.run('company')
17
+ # TODO: assert Medreg.run('company')
18
+ end
19
+ def test_person_importer
20
+ # TODO: assert Medreg.run('person')
18
21
  end
19
22
  end
20
23
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medreg
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Niklaus Giger, Zeno R.R. Davatz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mechanize
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rubyXL
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '='
44
39
  - !ruby/object:Gem::Version
@@ -46,98 +41,90 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: flexmock
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: simplecov
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: minitest
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description: Personen und Betriebe Adressen für die Schweiz.
127
112
  email: ngiger@ywesee.com, zdavatz@ywesee.com
128
113
  executables:
129
114
  - medreg
115
+ - merge_yaml
130
116
  extensions: []
131
117
  extra_rdoc_files: []
132
118
  files:
133
- - .gitignore
134
- - .travis.yml
119
+ - ".gitignore"
120
+ - ".travis.yml"
135
121
  - Gemfile
136
122
  - History.txt
137
123
  - LICENSE
138
124
  - README.textile
139
125
  - Rakefile
140
126
  - bin/medreg
127
+ - bin/merge_yaml
141
128
  - lib/medreg.rb
142
129
  - lib/medreg/address.rb
143
130
  - lib/medreg/ba_type.rb
@@ -149,6 +136,9 @@ files:
149
136
  - lib/medreg/resilient_loop.rb
150
137
  - lib/medreg/version.rb
151
138
  - medreg.gemspec
139
+ - test/data/7601000010735.html
140
+ - test/data/7601000813282.html
141
+ - test/data/Personen_20141014.xlsx
152
142
  - test/data/companies_20141014.xlsx
153
143
  - test/suite.rb
154
144
  - test/test_company.rb
@@ -157,26 +147,25 @@ files:
157
147
  homepage: https://github.com/zdavatz/medreg
158
148
  licenses:
159
149
  - GPL-v2
150
+ metadata: {}
160
151
  post_install_message:
161
152
  rdoc_options: []
162
153
  require_paths:
163
154
  - lib
164
155
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
156
  requirements:
167
- - - ! '>='
157
+ - - ">="
168
158
  - !ruby/object:Gem::Version
169
159
  version: '0'
170
160
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
161
  requirements:
173
- - - ! '>='
162
+ - - ">="
174
163
  - !ruby/object:Gem::Version
175
164
  version: '0'
176
165
  requirements: []
177
166
  rubyforge_project:
178
- rubygems_version: 1.8.25
167
+ rubygems_version: 2.1.11
179
168
  signing_key:
180
- specification_version: 3
169
+ specification_version: 4
181
170
  summary: Helper module for ch.oddb.org
182
171
  test_files: []