Skip to content

Commit

Permalink
Leave out DataSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
jhlee-mitre committed Nov 20, 2024
1 parent f363efc commit be8db9f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 90 deletions.
4 changes: 1 addition & 3 deletions lib/inferno/dsl/fhir_evaluator/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ def evaluate(ig_path, examples_path = nil, config_file = nil)
ig.examples
end

data_summary = FhirEvaluator::DataSummary.new(data)

print(data_summary.to_json, 'Data Summary')

results = FhirEvaluator::Evaluator.new(ig).evaluate(data, data_summary, config)
results = FhirEvaluator::Evaluator.new(ig).evaluate(data, config)

output_results(results, options[:output])
end
Expand Down
165 changes: 84 additions & 81 deletions lib/inferno/dsl/fhir_evaluator/data_summary.rb
Original file line number Diff line number Diff line change
@@ -1,97 +1,100 @@
module FhirEvaluator
# DataSummary represents the results of performing data characterization.
class DataSummary
attr_accessor :root_resource_ids, # All Example (root resource) Ids
:root_bundle_resource_ids, # All Example (root resource) Ids that are Bundle
:domain_resource_ids, # Domain resource Ids from root and child resources (exclude Bundle)
:resource_profile_map, # Resources and corresponding profiles
:resource_patient_map, # Resources and corresponding Patient Ids as subject
:resource_subject_map # Resources and corresponding subject
# At this point DataSummary isn't actually used by the evaluator.
# We will bring back when we need it.

def initialize(data)
@root_resource_ids = []
@root_bundle_resource_ids = []
@domain_resource_ids = []
@resource_profile_map = []
@resource_patient_map = []
@resource_subject_map = []
# class DataSummary
# attr_accessor :root_resource_ids, # All Example (root resource) Ids
# :root_bundle_resource_ids, # All Example (root resource) Ids that are Bundle
# :domain_resource_ids, # Domain resource Ids from root and child resources (exclude Bundle)
# :resource_profile_map, # Resources and corresponding profiles
# :resource_patient_map, # Resources and corresponding Patient Ids as subject
# :resource_subject_map # Resources and corresponding subject

validate(data)
summarize(data)
end
# def initialize(data)
# @root_resource_ids = []
# @root_bundle_resource_ids = []
# @domain_resource_ids = []
# @resource_profile_map = []
# @resource_patient_map = []
# @resource_subject_map = []

def validate(data)
# Check if duplicate Ids exist for same Resource Type in a data set
r_ids = data.map { |r| resources_ids(r) }.flatten
# validate(data)
# summarize(data)
# end

if r_ids.uniq == r_ids
puts 'No duplicate Ids found. Proceed to evaluate..'
else
dup = r_ids.detect { |r| r_ids.count(r) > 1 }
puts "Warning: Found duplicate resource Ids: #{dup}. Please validate Examples before running FHIR Evaluator."
end
end
# def validate(data)
# # Check if duplicate Ids exist for same Resource Type in a data set
# r_ids = data.map { |r| resources_ids(r) }.flatten

def summarize(data)
# @root_resource_ids = data.map { |r| { type: r.resourceType, id: r.id } }
# @root_bundle_resource_ids = data.map { |r| { type: r.resourceType, id: r.id } if r.resourceType == 'Bundle' }
# if r_ids.uniq == r_ids
# puts 'No duplicate Ids found. Proceed to evaluate..'
# else
# dup = r_ids.detect { |r| r_ids.count(r) > 1 }
# puts "Warning: Found duplicate resource Ids: #{dup}. Please validate Examples before running FHIR Evaluator."
# end
# end

# id_hash = Hash.new { |hash, key| hash[key] = [] }
# data.map { |e| resources(e) }.flatten.each do |item|
# id_hash[item[:type]] << item[:id]
# end
# @domain_resource_ids = id_hash.to_a
# def summarize(data)
# # @root_resource_ids = data.map { |r| { type: r.resourceType, id: r.id } }
# # @root_bundle_resource_ids = data.map { |r| { type: r.resourceType, id: r.id } if r.resourceType == 'Bundle' }

# @resource_profile_map = data.map { |e| resources_profiles(e) }.flatten.uniq
# @resource_patient_map = data.map { |e| resources_patients(e) }.flatten.uniq
# @resource_subject_map = data.map { |e| resources_subjects(e) }.flatten.uniq
end
# # id_hash = Hash.new { |hash, key| hash[key] = [] }
# # data.map { |e| resources(e) }.flatten.each do |item|
# # id_hash[item[:type]] << item[:id]
# # end
# # @domain_resource_ids = id_hash.to_a

def resources_ids(resource)
if resource.resourceType == 'Bundle'
resource.entry.map { |e| resources_ids(e.resource) }.flatten
else
"#{resource.resourceType}/#{resource.id}"
end
end
# # @resource_profile_map = data.map { |e| resources_profiles(e) }.flatten.uniq
# # @resource_patient_map = data.map { |e| resources_patients(e) }.flatten.uniq
# # @resource_subject_map = data.map { |e| resources_subjects(e) }.flatten.uniq
# end

def resources(resource)
if resource.resourceType == 'Bundle'
resource.entry.map { |e| resources(e.resource) }.flatten
else
{ type: resource.resourceType, id: resource.id }
end
end
# def resources_ids(resource)
# if resource.resourceType == 'Bundle'
# resource.entry.map { |e| resources_ids(e.resource) }.flatten
# else
# "#{resource.resourceType}/#{resource.id}"
# end
# end

def resources_profiles(resource)
if resource.resourceType == 'Bundle'
resource.entry.map { |e| resources_profiles(e.resource) }.flatten.uniq
elsif resource.meta&.profile
{ resource_id: resource.id, profile: resource.meta&.profile }
end
end
# def resources(resource)
# if resource.resourceType == 'Bundle'
# resource.entry.map { |e| resources(e.resource) }.flatten
# else
# { type: resource.resourceType, id: resource.id }
# end
# end

def resources_patients(resource)
if resource.resourceType == 'Bundle'
resource.entry.map { |e| resources_patients(e.resource) }.flatten.uniq
elsif defined? resource.patient.reference
{ resource_id: resource.id, patient: resource.patient.reference }
end
end
# def resources_profiles(resource)
# if resource.resourceType == 'Bundle'
# resource.entry.map { |e| resources_profiles(e.resource) }.flatten.uniq
# elsif resource.meta&.profile
# { resource_id: resource.id, profile: resource.meta&.profile }
# end
# end

def resources_subjects(resource)
if resource.resourceType == 'Bundle'
resource.entry.map { |e| resources_subjects(e.resource) }.flatten.uniq
elsif defined? resource.subject.reference
{ resource_id: resource.id, subject: resource.subject.reference }
end
end
# def resources_patients(resource)
# if resource.resourceType == 'Bundle'
# resource.entry.map { |e| resources_patients(e.resource) }.flatten.uniq
# elsif defined? resource.patient.reference
# { resource_id: resource.id, patient: resource.patient.reference }
# end
# end

def to_json(*_args)
{
'Resources' => domain_resource_ids.length,
'Root Resources' => root_resource_ids.length
}
end
end
# def resources_subjects(resource)
# if resource.resourceType == 'Bundle'
# resource.entry.map { |e| resources_subjects(e.resource) }.flatten.uniq
# elsif defined? resource.subject.reference
# { resource_id: resource.id, subject: resource.subject.reference }
# end
# end

# def to_json(*_args)
# {
# 'Resources' => domain_resource_ids.length,
# 'Root Resources' => root_resource_ids.length
# }
# end
# end
end
5 changes: 2 additions & 3 deletions lib/inferno/dsl/fhir_evaluator/evaluation_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ module FhirEvaluator
# - A summary/characterization of the data
# - Evaluation results
class EvaluationContext
attr_reader :ig, :data, :summary, :results, :config
attr_reader :ig, :data, :results, :config

def initialize(the_ig, data, summary, config)
def initialize(the_ig, data, config)
@ig = the_ig
@data = data
@summary = summary
@results = []
@config = config
end
Expand Down
5 changes: 2 additions & 3 deletions lib/inferno/dsl/fhir_evaluator/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ def initialize(the_ig)
@ig = the_ig
end

def evaluate(data, summary = nil, config = Config.new)
summary ||= DataSummary.new(data)
context = EvaluationContext.new(@ig, data, summary, config)
def evaluate(data, config = Config.new)
context = EvaluationContext.new(@ig, data, config)

active_rules = []
config.data['Rule'].each_key do |rulename|
Expand Down

0 comments on commit be8db9f

Please sign in to comment.