Module: Inferno::DSL::FHIRResourceNavigation

Included in:
Inferno::DSL::FHIREvaluation::Rules::AllMustSupportsPresent
Defined in:
lib/inferno/dsl/fhir_resource_navigation.rb

Overview

The FHIRResourceNavigation module is used to pick values from a FHIR resource, based on a profile. Originally intended for use for verifying the presence of Must Support elements on a resource and finding values to use for search parameters. The methods in this module related to slices expects pre-processed metadata defining the elements of the profile to be present in the attribute metadata in the including class.

Constant Summary collapse

DAR_EXTENSION_URL =
'http://hl7.org/fhir/StructureDefinition/data-absent-reason'.freeze
PRIMITIVE_DATA_TYPES =
FHIR::PRIMITIVES.keys

Instance Method Summary collapse

Instance Method Details

#find_a_value_at(given_element, path, include_dar: false, &block) ⇒ Object

Get a value from the given FHIR element(s), by navigating through the resource to the given path. Fields with a DataAbsentReason extension present will be excluded unless include_dar is true. To filter the resulting elements, a block may be passed in.

Parameters:

Returns:

  • a single matching value (which can include false) or nil if not found



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/inferno/dsl/fhir_resource_navigation.rb', line 46

def find_a_value_at(given_element, path, include_dar: false, &block)
  return nil if given_element.nil?

  elements = Array.wrap(given_element)
  return find_in_elements(elements, include_dar:, &block) if path.empty?

  path_segments = path_segments(path)

  segment = path_segments.shift

  remaining_path = path_segments.join('.')
  elements.each do |element|
    child = get_next_value(element, segment)
    element_found = find_a_value_at(child, remaining_path, include_dar:, &block)
    return element_found if value_not_empty?(element_found)
  end

  nil
end

#resolve_path(elements, path) ⇒ Array<FHIR::Model>

Get a value from the given FHIR element(s) by walking the given path through the element.

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/inferno/dsl/fhir_resource_navigation.rb', line 23

def resolve_path(elements, path)
  elements = Array.wrap(elements)
  return elements if path.blank?

  paths = path_segments(path)
  segment = paths.first
  remaining_path = paths.drop(1).join('.')

  elements.flat_map do |element|
    child = get_next_value(element, segment)
    resolve_path(child, remaining_path)
  end.compact
end