Class: Oddb2xml::FhirDownloader

Inherits:
Downloader show all
Includes:
DownloadMethod
Defined in:
lib/oddb2xml/fhir_support.rb

Overview

FHIR Downloader - Downloads NDJSON from FOPH/BAG

Constant Summary collapse

BASE_URL =
"https://epl.bag.admin.ch"
STATIC_FHIR_PATH =
"/static/fhir"
LANGUAGES =
%w[de fr it].freeze

Instance Attribute Summary

Attributes inherited from Downloader

#agent, #file2save, #type, #url

Instance Method Summary collapse

Methods inherited from Downloader

#init, #report_download

Constructor Details

#initialize(options = {}) ⇒ FhirDownloader

Returns a new instance of FhirDownloader.



20
21
22
23
# File 'lib/oddb2xml/fhir_support.rb', line 20

def initialize(options = {})
  @options = options
  super(options, BASE_URL)
end

Instance Method Details

#downloadObject

Returns either a single file path String (when –fhir_url is used) or a Hash of { “de” => path, “fr” => path, “it” => path } for per-language NDJSON files.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/oddb2xml/fhir_support.rb', line 28

def download
  if @options[:fhir_url]
    @url = @options[:fhir_url]
    download_one(@url)
  else
    files = {}
    LANGUAGES.each do |lang|
      url = "#{BASE_URL}#{STATIC_FHIR_PATH}/foph-sl-export-latest-#{lang}.ndjson"
      path = download_one(url)
      files[lang] = path if path
    end
    raise "FhirDownloader: no FHIR files downloaded successfully" if files.empty?
    files
  end
end