Module: IpaTestKit::FHIRResourceNavigation
- Included in:
- MustSupportTest, ProvenanceValidator, ReferenceResolutionTest, SearchTest
- Defined in:
- lib/ipa_test_kit/fhir_resource_navigation.rb
Constant Summary collapse
- DAR_EXTENSION_URL =
'http://hl7.org/fhir/StructureDefinition/data-absent-reason'.freeze
Instance Method Summary collapse
- #find_a_value_at(element, path, include_dar: false) ⇒ Object
- #get_next_value(element, property) ⇒ Object
- #resolve_path(elements, path) ⇒ Object
Instance Method Details
#find_a_value_at(element, path, include_dar: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ipa_test_kit/fhir_resource_navigation.rb', line 20 def find_a_value_at(element, path, include_dar: false) return nil if element.nil? elements = Array.wrap(element) if path.empty? unless include_dar elements = elements.reject do |el| el.respond_to?(:extension) && el.extension.any? { |ext| ext.url == DAR_EXTENSION_URL} end end return elements.find { |el| yield(el) } if block_given? return elements.first end path_segments = path.split('.') segment = path_segments.shift.delete_suffix('[x]').to_sym no_elements_present = elements.none? do |element| child = get_next_value(element, segment) child.present? || child == false end return nil if no_elements_present remaining_path = path_segments.join('.') elements.each do |element| child = get_next_value(element, segment) element_found = if block_given? find_a_value_at(child, remaining_path, include_dar: include_dar) { |value_found| yield(value_found) } else find_a_value_at(child, remaining_path, include_dar: include_dar) end return element_found if element_found.present? || element_found == false end nil end |
#get_next_value(element, property) ⇒ Object
66 67 68 69 70 |
# File 'lib/ipa_test_kit/fhir_resource_navigation.rb', line 66 def get_next_value(element, property) element.send(property) rescue NoMethodError nil end |
#resolve_path(elements, path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ipa_test_kit/fhir_resource_navigation.rb', line 5 def resolve_path(elements, path) elements = Array.wrap(elements) return elements if path.blank? paths = path.split('.') segment = paths.first segment.delete_suffix! '[x]' 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 |