medreg 0.1.1 → 0.1.2

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: f55cbd956da4f88e6ba28632b08daa57a98aeb6e
4
- data.tar.gz: c532ca10792ce3bdf697ebebbff3be28e722bd2f
3
+ metadata.gz: d25cb8e681c57b123e6d8e4628fec0289aa0e19e
4
+ data.tar.gz: 580e12546b39fb98a9dabb396a7378064a89ea24
5
5
  SHA512:
6
- metadata.gz: 23bc712a7f410702280f18435b709b0181a946d38a1f71f68db9f233e54e310a145070ffb1162445965c10d3c6a1c05ab02fff37b353cf2522647f03529ce472
7
- data.tar.gz: e05592a21ceab1c630cf0da1ccdd75f8d1a42685aac99eea263ee16e87c843fa5592379ed3e34bc953d3f37b4e08ae6ac7f778292252a99371fb952b81774131
6
+ metadata.gz: 67ca799028f8e04c38042a292a579be85bc77874e2f0c49b68934822ab6fad22d88cb49fcf627522b8ae3b8e936b42bd95982f5836afaf9806bb500398bbdb88
7
+ data.tar.gz: 6a8915caa4888ba4e906085b86fed545a018a358dcbc8dde1c1d30fb8c7b2cff15a9b364a644066433a957e311ca40693a2c496fa989aebd9cf12a2c1ebc37d8
@@ -1,3 +1,7 @@
1
+ === 0.1.2
2
+
3
+ * Create csv-files, too
4
+
1
5
  === 0.1.1
2
6
 
3
7
  * Some improvments to merge yaml Files.
@@ -18,7 +18,7 @@ h2. INSTALL:
18
18
  h2. Useage
19
19
 
20
20
  * @medreg -h@ # give helpl
21
- * @medreg @ # get info from medreg for all doctors and pharmacies
21
+ * @medreg@ # get info from medreg for all doctors and pharmacies
22
22
  * @medreg persons@ # get info from medreg for all doctors
23
23
  * @medreg companies@ # get info from medreg for all pharmacies
24
24
  * @merge_yaml output input_file_1 ..@ # merge all input files into the output
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
+ require 'medreg'
4
5
  require 'medreg/address'
5
6
  require 'medreg/ba_type'
6
7
  require 'medreg/company'
@@ -13,13 +14,13 @@ require 'psych' if RUBY_VERSION.match(/^1\.9/)
13
14
  require "yaml"
14
15
 
15
16
  module Medreg
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\//
20
- Companies_curr = File.expand_path(File.join(__FILE__, "../../../data/companies_#{Time.now.strftime('%Y.%m.%d')}.xlsx"))
21
- Companies_YAML = File.expand_path(File.join(__FILE__, "../../../data/companies_#{Time.now.strftime('%Y.%m.%d')}.yaml"))
22
- # MedRegURL = 'http://www.medreg.admin.ch/'
20
+ TimeStamp = Time.now.strftime('%Y.%m.%d')
21
+ Companies_curr = File.join(ARCHIVE_PATH, "companies_#{TimeStamp}.xlsx")
22
+ Companies_YAML = File.join(ARCHIVE_PATH, "companies_#{TimeStamp}.yaml")
23
+ Companies_CSV = File.join(ARCHIVE_PATH, "companies_#{TimeStamp}.csv")
23
24
  CompanyInfo = Struct.new("CompanyInfo",
24
25
  :gln,
25
26
  :exam,
@@ -71,9 +72,44 @@ module Medreg
71
72
  @@all_companies = {}
72
73
  setup_default_agent
73
74
  end
75
+ def save_import_to_csv(filename)
76
+ def add_item(info, item)
77
+ info << item.to_s.gsub(',',' ')
78
+ end
79
+ field_names = ["ean13",
80
+ "name",
81
+ "plz",
82
+ "location",
83
+ "address",
84
+ "ba_type",
85
+ "narcotics",
86
+ "address_additional_lines",
87
+ "address_canton",
88
+ "address_fax",
89
+ "address_fon",
90
+ "address_location",
91
+ "address_type",
92
+ ]
93
+ CSV.open(filename, "wb") do |csv|
94
+ csv << field_names
95
+ @@all_companies.each{ |gln, person|
96
+ maxlines = 1
97
+ maxlines = person[:addresses].size if person[:addresses].size > maxlines
98
+ 0.upto(maxlines-1).
99
+ each{
100
+ |idx|
101
+ info = []
102
+ field_names[0..6].each{ |name| add_item(info, eval("person[:#{name}]")) }
103
+ address = person[:addresses][idx]
104
+ field_names[7..-1].each{ |name| add_item(info, eval("x = address.#{name.sub('address_','')}; x.is_a?(Array) ? x.join(\"\n\") : x")) } if address
105
+ csv << info
106
+ }
107
+ }
108
+ end
109
+ end
74
110
  def save_import_to_yaml(filename)
75
111
  File.open(filename, 'w+') {|f| f.write(@@all_companies.to_yaml) }
76
- save_for_log "Saved #{@@all_companies.size} doctors in #{filename}"
112
+ save_for_log "Saved #{@@all_companies.size} companies in #{filename}"
77
113
  end
78
114
  def update
79
115
  saved = @glns_to_import.clone
@@ -90,9 +126,13 @@ module Medreg
90
126
  @info_to_gln.keys
91
127
  get_detail_to_glns(saved.size > 0 ? saved : @glns_to_import)
92
128
  save_import_to_yaml(Companies_YAML)
129
+ save_import_to_csv(Companies_CSV)
93
130
  return @companies_created, @companies_prev_import, @companies_deleted, @companies_skipped
94
131
  ensure
95
- save_import_to_yaml(@state_yaml) if @companies_created > 0
132
+ if @companies_created > 0
133
+ save_import_to_yaml(@state_yaml)
134
+ save_import_to_csv(@state_yaml.sub('.yaml','.csv'))
135
+ end
96
136
  end
97
137
  def setup_default_agent
98
138
  @agent = Mechanize.new
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
  require 'fileutils'
4
- require 'medreg/company_importer'
5
- require 'medreg/person_importer'
6
4
 
7
5
  module Medreg
8
- ARCHIVE_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../../data'))
9
- LOG_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../../log'))
10
- Mechanize_Log = File.join(LOG_PATH, File.basename(__FILE__).sub('.rb', '.log'))
6
+ DebugImport ||= defined?(Minitest) ? true : false
7
+ ARCHIVE_PATH = File.expand_path(File.join(Dir.pwd, 'data'))
8
+ LOG_PATH = File.expand_path(File.join(Dir.pwd, 'log'))
9
+ Mechanize_Log = File.join(LOG_PATH, File.basename(__FILE__).sub('.rb', '.log'))
11
10
  FileUtils.mkdir_p(LOG_PATH)
12
11
  FileUtils.mkdir_p(ARCHIVE_PATH)
13
12
  FileUtils.mkdir_p(File.dirname(Mechanize_Log))
@@ -35,3 +34,6 @@ module Medreg
35
34
  Medreg.log("Finished.")
36
35
  end
37
36
  end
37
+
38
+ require 'medreg/company_importer'
39
+ require 'medreg/person_importer'
@@ -14,9 +14,9 @@ require 'cgi'
14
14
  require 'psych' if RUBY_VERSION.match(/^1\.9/)
15
15
  require "yaml"
16
16
  require 'timeout'
17
+ require 'csv'
17
18
 
18
19
  module Medreg
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"))
@@ -74,22 +74,52 @@ module Medreg
74
74
  @skip_to_doctor = nil
75
75
  @archive = ARCHIVE_PATH
76
76
  @@all_doctors = {}
77
+ @@errors = []
77
78
  setup_default_agent unless setup_default_agent
78
79
  end
79
- def write_csv_file
80
- CSV.open(Personen_CSV, "wb") do |csv|
81
- csv << ["ean13", "name", "firstname", "may_dispense_narcotics", "remark_sell_drugs", "specialities", "capabilities",
80
+ def save_import_to_yaml(filename)
81
+ File.open(filename, 'w+') {|f| f.write(@@all_doctors.to_yaml) }
82
+ save_for_log "Saved #{@@all_doctors.size} doctors in #{filename}"
83
+ end
84
+ def save_import_to_csv(filename)
85
+ def add_item(info, item)
86
+ info << item.to_s.gsub(',',' ')
87
+ end
88
+ field_names = ["ean13",
89
+ "name",
90
+ "firstname",
91
+ "specialities",
92
+ "capabilities",
93
+ "may_dispense_narcotics",
94
+ "remark_sell_drugs",
82
95
  "address_additional_lines",
83
96
  "address_canton",
84
97
  "address_fax",
85
98
  "address_fon",
86
99
  "address_location",
87
- "address_revision",
88
100
  "address_type",
89
- "address_revision",
90
101
  ]
91
- csv << ["another", "row"]
92
- @@all_doctors.each{ |doctor| csv << [] }
102
+ CSV.open(filename, "wb") do |csv|
103
+ csv << field_names
104
+ @@all_doctors.each{ |gln, doctor|
105
+ maxlines = 1
106
+ maxlines = doctor[:specialities].size if doctor[:specialities].size > maxlines
107
+ maxlines = doctor[:capabilities].size if doctor[:capabilities].size > maxlines
108
+ maxlines = doctor[:addresses].size if doctor[:addresses].size > maxlines
109
+ 0.upto(maxlines-1).
110
+ each{
111
+ |idx|
112
+ info = []
113
+ field_names[0..2].each{ |name| add_item(info, eval("doctor[:#{name}]")) }
114
+ add_item(info, doctor[:specialities][idx])
115
+ add_item(info, doctor[:capabilities][idx])
116
+ add_item(info, doctor[:may_dispense_narcotics] ? 1 : 0)
117
+ add_item(info, doctor[:remark_sell_drugs])
118
+ address = doctor[:addresses][idx]
119
+ field_names[7..-1].each{ |name| add_item(info, eval("x = address.#{name.sub('address_','')}; x.is_a?(Array) ? x.join(\"\n\") : x")) } if address
120
+ csv << info
121
+ }
122
+ }
93
123
  end
94
124
  end
95
125
 
@@ -113,10 +143,13 @@ module Medreg
113
143
  @info_to_gln.keys
114
144
  get_detail_to_glns(saved.size > 0 ? saved : @glns_to_import)
115
145
  save_import_to_yaml(Personen_YAML)
146
+ save_import_to_csv(Personen_CSV)
116
147
  return @persons_created, @persons_prev_import, @persons_deleted, @persons_skipped
117
148
  ensure
118
- # write_csv_file
119
- save_import_to_yaml(@state_yaml) if @persons_created > 0
149
+ if @persons_created > 0
150
+ save_import_to_yaml(@state_yaml)
151
+ save_import_to_csv(@state_yaml.sub('.yaml','.csv'))
152
+ end
120
153
  end
121
154
  def setup_default_agent
122
155
  @agent = Mechanize.new
@@ -133,7 +166,7 @@ module Medreg
133
166
 
134
167
  def parse_details(doc, gln, info)
135
168
  unless doc.xpath("//tr") and doc.xpath("//tr").size > 3
136
- Medreg.log "ERROR: Could not find a table with info for #{gln}"
169
+ Medreg.log "ERROR: Could not find a table with info for #{gln}"
137
170
  return nil
138
171
  end
139
172
  doc_hash = Hash.new
@@ -182,7 +215,9 @@ module Medreg
182
215
  end
183
216
  info = @info_to_gln[gln.to_s]
184
217
  unless info
185
- Medreg.log "ERROR: could not find info for GLN #{gln}"
218
+ msg = "ERROR: could not find info for GLN #{gln}"
219
+ @@errors << msg
220
+ Medreg.log msg
186
221
  next
187
222
  end
188
223
  url = MedRegOmURL + "de/Suche/Detail/?gln=#{gln}&vorname=#{info.first_name.gsub(/ /, '+')}&name=#{info.family_name.gsub(/ /, '+')}"
@@ -220,7 +255,9 @@ module Medreg
220
255
  regExp = /id"\:(\d\d+)/i
221
256
  unless page_4.body.match(regExp)
222
257
  File.open(File.join(LOG_PATH, 'page_4.body'), 'w+') { |f| f.write page_4.body }
223
- Medreg.log "ERROR: Could not find an gln #{gln} via url #{url}"
258
+ msg = "ERROR: Could not find an gln #{gln} via url #{url}"
259
+ @@errors << msg
260
+ Medreg.log msg
224
261
  next
225
262
  end
226
263
  medregId = page_4.body.match(regExp)[1]
@@ -229,6 +266,7 @@ module Medreg
229
266
  File.open(File.join(LOG_PATH, "#{gln}.html"), 'w+') { |f| f.write page_5.content } if DebugImport
230
267
  doc_hash = parse_details( Nokogiri::HTML(page_5.content), gln, info)
231
268
  store_doctor(doc_hash)
269
+ @persons_created += 1
232
270
  @@all_doctors[gln.to_s] = doc_hash
233
271
  end
234
272
  end
@@ -264,10 +302,6 @@ module Medreg
264
302
  end
265
303
  end
266
304
  raise "Max retries #{nr_tries} for #{gln.to_s} reached. Aborting import" if nr_tries == max_retries
267
- @persons_created += 1
268
- if (@persons_created + @persons_prev_import) % 100 == 99
269
- Medreg.log "Start saving after #{@persons_created} created #{@persons_prev_import} from previous import"
270
- end
271
305
  }
272
306
  r_loop.finished
273
307
  end
@@ -301,7 +335,7 @@ module Medreg
301
335
  address.fax << line.split('Fax: ')[1].gsub(/\-/, ' ')
302
336
  next
303
337
  else
304
- next if line.length == 0
338
+ next if line.length <= 1
305
339
  if m = line.match(/(|\w\w[-\. ])(\d{4})\s+(\S+)/)
306
340
  address.location = line
307
341
  else
@@ -340,11 +374,16 @@ module Medreg
340
374
  target
341
375
  end
342
376
  def report
343
- report = "Persons update \n\n"
377
+ report = "Persons update\n\n"
344
378
  report << "Skipped doctors: #{@persons_skipped}#{@skip_to_doctor ? '. Waited for ' + @skip_to_doctor.to_s : ''}" << "\n"
345
379
  report << "New doctors: " << @persons_created.to_s << "\n"
346
380
  report << "Doctors from previous imports: " << @persons_prev_import.to_s << "\n"
347
381
  report << "Deleted doctors: " << @persons_deleted.to_s << "\n"
382
+ if @@errors.size > 0
383
+ report << "\n\nFound following errors/warnings:\n\n"
384
+ report << @@errors.join("\n")
385
+ report << "\n"
386
+ end
348
387
  report
349
388
  end
350
389
  def store_doctor(hash)
@@ -423,7 +462,9 @@ private
423
462
  # infos[1] = infos[1].to_i # transform year into an integer
424
463
  return infos.join(', ')
425
464
  else
426
- Medreg.log "PROBLEM: could not find speciality for GLN #{gln} in line '#{line}'"
465
+ msg = "PROBLEM: could not find speciality for GLN #{gln} in line '#{line}'"
466
+ @@errors << msg
467
+ Medreg.log msg
427
468
  end
428
469
  nil
429
470
  end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Medreg
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -30,8 +30,10 @@ class TestCompanyPlugin <Minitest::Test
30
30
  flexmock(@plugin, :get_company_data => {})
31
31
  flexmock(@plugin, :puts => nil)
32
32
  startTime = Time.now
33
- csv_file = Medreg::Companies_YAML
33
+ csv_file = Medreg::Companies_CSV
34
34
  FileUtils.rm_f(csv_file) if File.exists?(csv_file)
35
+ yaml_file = Medreg::Companies_YAML
36
+ FileUtils.rm_f(yaml_file) if File.exists?(yaml_file)
35
37
  created, updated, deleted, skipped = @plugin.update
36
38
  diffTime = (Time.now - startTime).to_i
37
39
  # $stdout.puts "result: created #{created} deleted #{deleted} skipped #{skipped} in #{diffTime} seconds"
@@ -41,6 +43,7 @@ class TestCompanyPlugin <Minitest::Test
41
43
  assert_equal(0, skipped)
42
44
  assert_equal(1, Medreg::CompanyImporter.all_companies.size)
43
45
  assert(File.exists?(csv_file), "file #{csv_file} must be created")
46
+ assert(File.exists?(yaml_file), "file #{yaml_file} must be created")
44
47
  linden = Medreg::CompanyImporter.all_companies[7601001396371]
45
48
  addresses = linden[:addresses]
46
49
  assert_equal(1, addresses.size)
@@ -55,9 +58,12 @@ class TestCompanyPlugin <Minitest::Test
55
58
  assert_equal('Mitteldorf', first_address.street)
56
59
  assert_equal([], first_address.additional_lines)
57
60
  assert_equal('AB Lindenapotheke AG', first_address.name)
61
+ inhalt = IO.read(yaml_file)
62
+ assert(inhalt.index('6011 Verzeichnis a/b/c BetmVV-EDI'), 'must find btm')
58
63
  inhalt = IO.read(csv_file)
59
- assert(inhalt.index('6011 Verzeichnis a/b/c BetmVV-EDI') > 0, 'must find btm')
60
- # 7601001396371 AB Lindenapotheke AG Mitteldorf 4 5102 Rupperswil Aargau Schweiz öffentliche Apotheke 6011 Verzeichnis a/b/c BetmVV-EDI
64
+ assert(inhalt.index('6011 Verzeichnis a/b/c BetmVV-EDI'), 'must find btm')
65
+ csv = IO.readlines(csv_file)
66
+ assert(csv.size > 1, "csv_file #{csv_file} must have more than 1 line. Currently #{csv.size}.")
61
67
  end
62
68
  def test_update_all
63
69
  @plugin = Medreg::CompanyImporter.new()
@@ -29,7 +29,6 @@ class TestPerson <Minitest::Test
29
29
  7601000010735 => OpenStruct.new(:family_name => 'Cevey', :first_name => 'Philippe Marc', :authority => 'Waadt'),
30
30
  7601000813282 => OpenStruct.new(:family_name => 'ABANTO PAYER', :first_name => 'Dora Carmela', :authority => 'Waadt'),
31
31
  }
32
-
33
32
  # Anita Hensel 7601000972620
34
33
  def test_aaa_zuest # name starts with aaa we want this test to be run as first
35
34
  { 7601000254207 => OpenStruct.new(:family_name => 'Züst', :first_name => 'Peter', :authority => 'Glarus')}.each do
@@ -81,28 +80,57 @@ class TestPerson <Minitest::Test
81
80
  assert_equal('3', first_address.number)
82
81
  end
83
82
  end
84
-
83
+ def test_update_with_error
84
+ gln = 9999
85
+ info = OpenStruct.new(:family_name => 'NoName', :first_name => 'NoFirstName', :authority => 'NoSuchCanton')
86
+ @plugin = Medreg::PersonImporter.new([gln])
87
+ flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
88
+ flexmock(@plugin, :get_doctor_data => {})
89
+ assert(File.exists?(Test_Personen_XLSX))
90
+ startTime = Time.now
91
+ yaml_file = Medreg::Personen_YAML
92
+ csv_file = yaml_file.sub('.yaml', '.csv')
93
+ FileUtils.rm_f(csv_file) if File.exists?(csv_file)
94
+ FileUtils.rm_f(yaml_file) if File.exists?(yaml_file)
95
+ created, updated, deleted, skipped = @plugin.update
96
+ diffTime = (Time.now - startTime).to_i
97
+ assert_equal(0, deleted)
98
+ assert_equal(0, skipped)
99
+ assert_equal(0, created)
100
+ assert_equal(0, updated)
101
+ assert(File.exists?(yaml_file), "file #{csv_file} must be created")
102
+ assert(/ERROR: could not find info for GLN/.match(@plugin.report), 'Should find error')
103
+ assert(/New doctors: 0/.match(@plugin.report), 'Should find 0 new doctor')
104
+ end
85
105
  def test_update_single
86
- SomeTestCases.each{
87
- |gln, info|
88
- rm_log_files
89
- @plugin = Medreg::PersonImporter.new([gln])
90
- flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
91
- flexmock(@plugin, :get_doctor_data => {})
92
- assert(File.exists?(Test_Personen_XLSX))
93
- startTime = Time.now
94
- csv_file = Medreg::Personen_YAML
95
- FileUtils.rm_f(csv_file) if File.exists?(csv_file)
96
- created, updated, deleted, skipped = @plugin.update
97
- diffTime = (Time.now - startTime).to_i
98
- assert_equal(0, deleted)
99
- assert_equal(0, skipped)
100
- assert_equal(1, created)
101
- assert_equal(0, updated)
102
- assert(File.exists?(csv_file), "file #{csv_file} must be created")
103
- expected = "Persons update \n\nSkipped doctors: 0\nNew doctors: 1\nDoctors from previous imports: 0\nDeleted doctors: 0\n"
104
- assert_equal(expected, @plugin.report)
105
- }
106
+ gln = 7601000254207
107
+ info = OpenStruct.new(:family_name => 'Züst', :first_name => 'Peter', :authority => 'Glarus')
108
+ rm_log_files
109
+ @plugin = Medreg::PersonImporter.new([gln])
110
+ flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
111
+ flexmock(@plugin, :get_doctor_data => {})
112
+ assert(File.exists?(Test_Personen_XLSX))
113
+ startTime = Time.now
114
+ yaml_file = Medreg::Personen_YAML
115
+ csv_file = yaml_file.sub('.yaml', '.csv')
116
+ FileUtils.rm_f(csv_file) if File.exists?(csv_file)
117
+ FileUtils.rm_f(yaml_file) if File.exists?(yaml_file)
118
+ created, updated, deleted, skipped = @plugin.update
119
+ diffTime = (Time.now - startTime).to_i
120
+ assert_equal(0, deleted)
121
+ assert_equal(0, skipped)
122
+ assert_equal(1, created)
123
+ assert_equal(0, updated)
124
+ assert(File.exists?(yaml_file), "file #{csv_file} must be created")
125
+ assert_equal(nil, /ERROR: could not find info for GLN/.match(@plugin.report), 'Should not find an error')
126
+ assert(/New doctors: 1/.match(@plugin.report), 'Should find 1 new doctor')
127
+ yaml_inhalt = IO.read(yaml_file)
128
+ assert(yaml_inhalt.size > 50, "yaml file #{yaml_file} should be bigger than 50 char, but is #{yaml_inhalt.size}")
129
+ assert(File.exists?(csv_file), "file #{csv_file} must be created")
130
+ csv = IO.readlines(csv_file)
131
+ assert(csv.size > 1, "csv file #{csv_file} should have more than 1 line. Has #{csv.size}")
132
+ csv_inhalt = IO.read(csv_file)
133
+ assert(csv_inhalt.size > 50, "csv file #{csv_file} should be bigger than 50 char, but is #{csv_inhalt.size}")
106
134
  end
107
135
 
108
136
  def test_update_some_glns
@@ -147,5 +175,38 @@ class TestPerson <Minitest::Test
147
175
  assert(doc_hash[:addresses].size > 0, 'doc_hash must have at least one address')
148
176
  }
149
177
  end
150
-
178
+ def test_empty_address_lines
179
+ gln = 7601000264015
180
+ info = OpenStruct.new(:family_name => 'Togninalli', :first_name => 'Danilo', :authority => 'Tessin')
181
+ rm_log_files
182
+ @plugin = Medreg::PersonImporter.new([gln])
183
+ flexmock(@plugin, :get_latest_file => Test_Personen_XLSX )
184
+ flexmock(@plugin, :get_doctor_data => {})
185
+ assert(File.exists?(Test_Personen_XLSX))
186
+ startTime = Time.now
187
+ yaml_file = Medreg::Personen_YAML
188
+ csv_file = yaml_file.sub('.yaml', '.csv')
189
+ FileUtils.rm_f(csv_file) if File.exists?(csv_file)
190
+ FileUtils.rm_f(yaml_file) if File.exists?(yaml_file)
191
+ created, updated, deleted, skipped = @plugin.update
192
+ diffTime = (Time.now - startTime).to_i
193
+ assert_equal(0, deleted)
194
+ assert_equal(0, skipped)
195
+ assert_equal(1, created)
196
+ assert_equal(0, updated)
197
+ assert(File.exists?(yaml_file), "file #{csv_file} must be created")
198
+ assert_equal(nil, /ERROR: could not find info for GLN/.match(@plugin.report), 'Should not find an error')
199
+ assert(/New doctors: 1/.match(@plugin.report), 'Should find 1 new doctor')
200
+ yaml_inhalt = IO.read(yaml_file)
201
+ assert(yaml_inhalt.size > 50, "yaml file #{yaml_file} should be bigger than 50 char, but is #{yaml_inhalt.size}")
202
+ assert(File.exists?(csv_file), "file #{csv_file} must be created")
203
+ csv = IO.readlines(csv_file)
204
+ assert(csv.size > 1, "csv file #{csv_file} should have more than 1 line. Has #{csv.size}")
205
+ csv_inhalt = IO.read(csv_file)
206
+ assert(csv_inhalt.size > 50, "csv file #{csv_file} should be bigger than 50 char, but is #{csv_inhalt.size}")
207
+ csv.each{
208
+ |line|
209
+ assert_equal(0, line.index(/^(ean13|7601)/), "All lines must start with ean13 or 7601. But not #{line}")
210
+ }
211
+ end
151
212
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medreg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklaus Giger, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -164,8 +164,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  requirements: []
166
166
  rubyforge_project:
167
- rubygems_version: 2.1.11
167
+ rubygems_version: 2.4.5
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Helper module for ch.oddb.org
171
171
  test_files: []
172
+ has_rdoc: