Class: Inferno::DSL::FHIREvaluation::ReferenceExtractor
- Inherits:
-
Object
- Object
- Inferno::DSL::FHIREvaluation::ReferenceExtractor
- Defined in:
- lib/inferno/dsl/fhir_evaluation/reference_extractor.rb
Instance Attribute Summary collapse
-
#references ⇒ Object
Returns the value of attribute references.
-
#resource_type_ids ⇒ Object
Returns the value of attribute resource_type_ids.
Instance Method Summary collapse
-
#add_parsed_reference(resource, value, path) ⇒ Object
-
#extract_references(resources) ⇒ Object
-
#extract_references_from_resource(resource) ⇒ Object
-
#extract_resource_type_ids(resources) ⇒ Object
Instance Attribute Details
#references ⇒ Object
Returns the value of attribute references.
5 6 7 |
# File 'lib/inferno/dsl/fhir_evaluation/reference_extractor.rb', line 5 def references @references end |
#resource_type_ids ⇒ Object
Returns the value of attribute resource_type_ids.
5 6 7 |
# File 'lib/inferno/dsl/fhir_evaluation/reference_extractor.rb', line 5 def resource_type_ids @resource_type_ids end |
Instance Method Details
#add_parsed_reference(resource, value, path) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/inferno/dsl/fhir_evaluation/reference_extractor.rb', line 49 def add_parsed_reference(resource, value, path) type = value.reference.split('/')[-2].downcase id = value.reference.split('/')[-1] references[resource.id] << if resource_type_ids.key?(type) { path: path, type: type, id: id } else { path: path, type: '', id: value.reference } end end |
#extract_references(resources) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/inferno/dsl/fhir_evaluation/reference_extractor.rb', line 23 def extract_references(resources) @references = Hash.new { |reference, id| reference[id] = [] } resources.each do |resource| extract_references_from_resource(resource) end references end |
#extract_references_from_resource(resource) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/inferno/dsl/fhir_evaluation/reference_extractor.rb', line 33 def extract_references_from_resource(resource) resource.each_element do |value, , path| if ['type'] == 'Reference' && !value.reference.nil? if value.reference.start_with?('#') next elsif value.reference.include? '/' add_parsed_reference(resource, value, path) elsif value.reference.start_with? 'urn:uuid:' references[resource.id] << { path: path, type: '', id: value.reference[9..] } else references[resource.id] << { path: path, type: '', id: value.reference } end end end end |
#extract_resource_type_ids(resources) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/inferno/dsl/fhir_evaluation/reference_extractor.rb', line 7 def extract_resource_type_ids(resources) @resource_type_ids = Hash.new { |type, id| type[id] = [] } resources.each do |resource| resource.each_element do |value, , path| next unless ['type'] == 'id' next if path.include?('contained') type = ['path'].partition('.').first.downcase resource_type_ids[type] << value end end resource_type_ids end |