Skip to content

Commit

Permalink
Used attr_accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
jhlee-mitre committed Jan 14, 2025
1 parent 808828b commit 1872d88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
35 changes: 18 additions & 17 deletions lib/inferno/dsl/fhir_evaluation/reference_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Inferno
module DSL
module FHIREvaluation
class ReferenceExtractor
attr_accessor :resource_path_ids, :references

def extract_resource_path_ids(resources)
resource_path_ids = Hash.new { |resource_path, id| resource_path[id] = [] }
@resource_path_ids = Hash.new { |resource_path, id| resource_path[id] = [] }

resources.each do |resource|
resource.each_element do |value, metadata, path|
Expand All @@ -18,15 +20,14 @@ def extract_resource_path_ids(resources)
resource_path_ids
end

def extract_references(resources, resource_path_ids)
def extract_references(resources)
@references = Hash.new { |reference, id| reference[id] = [] }
@resource_path_ids = resource_path_ids

resources.each do |resource|
extract_references_from_resource(resource)
end

@references
references
end

def extract_references_from_resource(resource)
Expand All @@ -44,7 +45,7 @@ def extract_references_from_resource(resource)
# assumes this is a unique uuid
reference = value.reference
reference = reference[9..] if reference.start_with? 'urn:uuid:'
@references[resource.id] << [path, '', reference]
references[resource.id] << [path, '', reference]
end
end
end
Expand All @@ -54,23 +55,23 @@ def add_parsed_reference(resource, value, path)
type = value.reference.split('/')[-2].downcase
id = value.reference.split('/')[-1]
# assumes all profiles are represented
@references[resource.id] << if @resource_path_ids.key?(type)
[path, type, id]
else
# could include a warning here
[path, '', value.reference]
end
references[resource.id] << if resource_path_ids.key?(type)
[path, type, id]
else
# could include a warning here
[path, '', value.reference]
end
end

def add_reference_typed_path(resource, value, path)
type = path.split('Reference', 2).downcase
# assumes all profiles are represented
@references[resource.id] << if @resource_path_ids.key?(type)
[path, type, value.reference]
else
# could include a warning here
[path, '', value.reference]
end
references[resource.id] << if resource_path_ids.key?(type)
[path, type, value.reference]
else
# could include a warning here
[path, '', value.reference]
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def check(context)
extractor = Inferno::DSL::FHIREvaluation::ReferenceExtractor.new
resource_path_ids = extractor.extract_resource_path_ids(context.data)
resource_ids = Set.new(resource_path_ids.values.flatten.uniq)
reference_map = extractor.extract_references(context.data, resource_path_ids)
reference_map = extractor.extract_references(context.data)

unresolved_references = Hash.new { |reference, id| reference[id] = [] }
reference_map.each do |id, references|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def check(context)
extractor = Inferno::DSL::FHIREvaluation::ReferenceExtractor.new
@resource_path_ids = extractor.extract_resource_path_ids(context.data)
@resource_ids = Set.new(resource_path_ids.values.flatten.uniq)
reference_map = extractor.extract_references(context.data, resource_path_ids)
reference_map = extractor.extract_references(context.data)

reference_map.each do |id, references|
assess_reachability(id, references)
Expand Down

0 comments on commit 1872d88

Please sign in to comment.