Class: Generator::IGResourcesExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/au_ps_inferno/generator/ig_resources_extractor.rb

Overview

Extracts FHIR resources from an Implementation Guide (IG) package archive and optionally from a folder of additional JSON resources.

Reads a .tar.gz (or .tgz) package, parses JSON entries that represent FHIR resources (excluding OpenAPI JSON), and populates #ig_resources with FHIR model instances. If additional_resources_path is set, all .json files from that folder (and subfolders) are loaded after the package, so you can supply missing StructureDefinitions, SearchParameters, etc.

Examples:

extractor = IGResourcesExtractor.new('path/to/package.tar.gz')
extractor.extract
extractor.ig_resources # => [FHIR::Patient, ...]

With additional folder

extractor = IGResourcesExtractor.new('path/to/package.tar.gz', additional_resources_path: 'path/to/extra')
extractor.extract

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ig_path, additional_resources_path: nil) ⇒ IGResourcesExtractor

Returns a new instance of IGResourcesExtractor.

Parameters:

  • ig_path (String)

    Path to the IG package file (.tar.gz or .tgz)

  • additional_resources_path (String, nil) (defaults to: nil)

    Optional path to a folder of JSON FHIR resources (e.g. StructureDefinition, SearchParameter) to load in addition to the package.



32
33
34
35
36
37
# File 'lib/au_ps_inferno/generator/ig_resources_extractor.rb', line 32

def initialize(ig_path, additional_resources_path: nil)
  @ig_path = ig_path
  @additional_resources_path = additional_resources_path
  @ig_resources = []
  @ig_version = nil
end

Instance Attribute Details

#ig_resourcesArray<FHIR::Model> (readonly)

Returns FHIR resources extracted from the IG package and optional folder.

Returns:

  • (Array<FHIR::Model>)

    FHIR resources extracted from the IG package and optional folder



27
28
29
# File 'lib/au_ps_inferno/generator/ig_resources_extractor.rb', line 27

def ig_resources
  @ig_resources
end

#ig_versionArray<FHIR::Model> (readonly)

Returns FHIR resources extracted from the IG package and optional folder.

Returns:

  • (Array<FHIR::Model>)

    FHIR resources extracted from the IG package and optional folder



27
28
29
# File 'lib/au_ps_inferno/generator/ig_resources_extractor.rb', line 27

def ig_version
  @ig_version
end

Instance Method Details

#extractvoid

This method returns an undefined value.

Processes the package archive and optional folder, and populates #ig_resources. Handles gzip/tar errors and prints messages to stdout on failure.



43
44
45
46
# File 'lib/au_ps_inferno/generator/ig_resources_extractor.rb', line 43

def extract
  process_package_archive
  load_additional_resources_from_folder if @additional_resources_path
end