Module: Medreg
- Defined in:
- lib/medreg/medreg.rb,
lib/medreg/person.rb,
lib/medreg/address.rb,
lib/medreg/ba_type.rb,
lib/medreg/company.rb,
lib/medreg/version.rb,
lib/medreg/resilient_loop.rb,
lib/medreg/person_importer.rb,
lib/medreg/company_importer.rb
Defined Under Namespace
Classes: Address2, BA_type, Company, CompanyImporter, CompanyInfo, Person, PersonImporter, PersonInfo, ResilientLoop
Constant Summary collapse
- ARCHIVE_PATH =
File.(File.join(Dir.pwd, 'data'))
- LOG_PATH =
File.(File.join(Dir.pwd, 'log'))
- Mechanize_Log =
File.join(LOG_PATH, File.basename(__FILE__).sub('.rb', '.log'))
- ID =
File.basename($0, '.rb')
- BA_types =
Set[ nil, BA_type::BA_cantonal_authority, BA_type::BA_doctor, BA_type::BA_health, BA_type::BA_hospital, BA_type::BA_hospital_pharmacy, BA_type::BA_info, BA_type::BA_insurance, BA_type::BA_pharma, BA_type::BA_public_pharmacy, BA_type::BA_research_institute, ]
- VERSION =
'0.1.2'
- ExampleUsage =
ResilientLoop is a helper class for running long lasting jobs like imports It has the following characterstics
-
Possible to restart a failed job at the failing id
-
Retry an import after a timeout (e.g. of 10 seconds)
requirements:
Needed is state-id (e.g. an EAN13 code) which allows to distingish whether a loop item was already processed or not
implementation:
the state is saved in a text file
-
%( r_loop = ResilientLoop.new(LoopName) loop_entries.each{ |entry| next if r_loop.must_skip?(entry) r_loop.try_run(entry, TimeoutValue) { /* do your work */ } } r_loop.finished )
- Personen_Candidates =
File.(File.join(__FILE__, '../../../data/Personen_20*.xlsx'))
- Personen_YAML =
File.(File.join(__FILE__, "../../../data/persons_#{Time.now.strftime('%Y.%m.%d-%H%M')}.yaml"))
- Personen_CSV =
File.(File.join(__FILE__, "../../../data/persons_#{Time.now.strftime('%Y.%m.%d-%H%M')}.csv"))
- MedRegOmURL =
'http://www.medregom.admin.ch/'
- MedRegPerson_XLS_URL =
"https://www.medregbm.admin.ch/Publikation/CreateExcelListMedizinalPersons"
- COL =
GLN Person Name Vorname PLZ Ort Bewilligungskanton Land Diplom BTM Berechtigung Bewilligung Selbstdispensation Bemerkung Selbstdispensation
{ :gln => 0, # A :family_name => 1, # B :first_name => 2, # C :zip_code => 3, # D :place => 4, # E :authority => 5, # F :country => 6, # G :diploma => 7, # H :may_dispense_narcotics => 8, # I :may_sell_drugs => 9, # J :remark_sell_drugs => 10, # K }
- BetriebeURL =
'https://www.medregbm.admin.ch/Betrieb/Search'
- BetriebeXLS_URL =
"https://www.medregbm.admin.ch/Publikation/CreateExcelListBetriebs"
- RegExpBetriebDetail =
/\/Betrieb\/Details\//
- TimeStamp =
Time.now.strftime('%Y.%m.%d')
- Companies_curr =
File.join(ARCHIVE_PATH, "companies_#{TimeStamp}.xlsx")
- Companies_YAML =
File.join(ARCHIVE_PATH, "companies_#{TimeStamp}.yaml")
- Companies_CSV =
File.join(ARCHIVE_PATH, "companies_#{TimeStamp}.csv")
- COMPANY_COL =
GLN Person Name Vorname PLZ Ort Bewilligungskanton Land Diplom BTM Berechtigung Bewilligung Selbstdispensation Bemerkung Selbstdispensation
{ :gln => 0, # A :name_1 => 1, # B :name_2 => 2, # C :street => 3, # D :street_number => 4, # E :plz => 5, # F :locality => 6, # G :canton_giving_permit => 7, # H :country => 8, # I :company_type => 9, # J :drug_permit => 10, # K }
Class Method Summary collapse
Class Method Details
.log(msg) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/medreg/medreg.rb', line 15 def Medreg.log(msg) $stdout.puts "#{Time.now}: #{ID} #{msg}" # unless defined?(Minitest) $stdout.flush @@logfile ||= File.open(File.join(LOG_PATH, "#{ID}.log"), 'a+') @@logfile.puts "#{Time.now}: #{msg}" end |
.run(only_run = false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/medreg/medreg.rb', line 22 def Medreg.run(only_run=false) Medreg.log("Starting with only_run #{only_run}") import_company = (not only_run or only_run.match(/compan/i)) import_person = (not only_run or only_run.match(/person/i)) if import_company importer = Medreg::CompanyImporter.new importer.update end if import_person importer = Medreg::PersonImporter.new importer.update end Medreg.log("Finished.") end |