From be8db9fc65e60a9af26649991d8bc904337ad676 Mon Sep 17 00:00:00 2001 From: Jaehoon Lee Date: Wed, 20 Nov 2024 08:18:53 -0500 Subject: [PATCH] Leave out DataSummary --- lib/inferno/dsl/fhir_evaluator/cli.rb | 4 +- .../dsl/fhir_evaluator/data_summary.rb | 165 +++++++++--------- .../dsl/fhir_evaluator/evaluation_context.rb | 5 +- lib/inferno/dsl/fhir_evaluator/evaluator.rb | 5 +- 4 files changed, 89 insertions(+), 90 deletions(-) diff --git a/lib/inferno/dsl/fhir_evaluator/cli.rb b/lib/inferno/dsl/fhir_evaluator/cli.rb index 8bf32078e..9898b1666 100644 --- a/lib/inferno/dsl/fhir_evaluator/cli.rb +++ b/lib/inferno/dsl/fhir_evaluator/cli.rb @@ -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 diff --git a/lib/inferno/dsl/fhir_evaluator/data_summary.rb b/lib/inferno/dsl/fhir_evaluator/data_summary.rb index 772ab0421..7a1831a91 100644 --- a/lib/inferno/dsl/fhir_evaluator/data_summary.rb +++ b/lib/inferno/dsl/fhir_evaluator/data_summary.rb @@ -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 diff --git a/lib/inferno/dsl/fhir_evaluator/evaluation_context.rb b/lib/inferno/dsl/fhir_evaluator/evaluation_context.rb index 82d62b006..2867012bc 100644 --- a/lib/inferno/dsl/fhir_evaluator/evaluation_context.rb +++ b/lib/inferno/dsl/fhir_evaluator/evaluation_context.rb @@ -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 diff --git a/lib/inferno/dsl/fhir_evaluator/evaluator.rb b/lib/inferno/dsl/fhir_evaluator/evaluator.rb index 68b5ea214..5cf85ab49 100644 --- a/lib/inferno/dsl/fhir_evaluator/evaluator.rb +++ b/lib/inferno/dsl/fhir_evaluator/evaluator.rb @@ -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|