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 =

BAG moved the export on 24.08.2026 and announced it the next evening: /static/fhir/foph-sl-export-* became /static/sl/publication/fhir/foph-sl-publication-*.

The old -latest- alias answers 404 while the old dated snapshots stay in place, so this fails by downloading nothing rather than by crashing. There is no language-less default any more; per BAG each URL must name de, fr or it. A preliminary publication now exists in parallel under /static/sl/preliminary/fhir/foph-sl-preliminary-*, which this does not use.

"/static/sl/publication/fhir"
FILE_PREFIX =
"foph-sl-publication"
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.



30
31
32
33
# File 'lib/oddb2xml/fhir_support.rb', line 30

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.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/oddb2xml/fhir_support.rb', line 38

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}/#{FILE_PREFIX}-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