Skip to content

Commit

Permalink
Data set loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jhlee-mitre committed Nov 26, 2024
1 parent bd9aaa1 commit d1f2e83
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
15 changes: 8 additions & 7 deletions lib/inferno/dsl/fhir_evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Inferno
module DSL
module FHIREvaluation
class Evaluator
def initialize(ig_path, examples_path)
def initialize(ig_path, data_path)
Dotenv.load
Dir.glob(File.join(__dir__, 'fhir_evaluator', 'rules', '*.rb')).each do |file|
require_relative file
Expand All @@ -28,11 +28,12 @@ def initialize(ig_path, examples_path)
Config.new

ig_path = File.join(__dir__, 'fhir_evaluator', 'ig', 'uscore7.0.0.tgz')
validate_args(ig_path, examples_path)
data_path = File.join(__dir__, 'fhir_evaluator', 'data')
validate_args(ig_path, data_path)
ig = FhirEvaluator::IG.new(ig_path)

if examples_path
Dataset.from_path(examples_path)
if data_path
DatasetLoader.from_path(data_path)
else
ig.examples
end
Expand All @@ -44,12 +45,12 @@ def initialize(ig_path, examples_path)
# output_results(results, options[:output])
end

def validate_args(ig_path, examples_path)
def validate_args(ig_path, data_path)
raise 'A path to an IG is required!' unless ig_path

return unless examples_path && (!File.directory? examples_path)
return unless data_path && (!File.directory? data_path)

raise "Provided path '#{examples_path}' is not a directory"
raise "Provided path '#{data_path}' is not a directory"
end

def output_results(results, output)
Expand Down
52 changes: 28 additions & 24 deletions lib/inferno/dsl/fhir_evaluator/dataset.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
module FhirEvaluator
# A Dataset is an Array of FHIR data to be summarized or evaluated,
# with convenience methods for loading from a file path or from an
# Array of FHIR JSON strings.
class Dataset < Array
def self.from_contents(source_array)
dataset = Dataset.new
module Inferno
module DSL
module FHIREvaluation
# A Dataset returns an Array of FHIR data to be summarized or evaluated,
# with convenience methods for loading from a file path or from an
# Array of FHIR JSON strings.
module DatasetLoader
def self.from_contents(source_array)
dataset = []

source_array.each do |json|
resource = FHIR::Json.from_json(json)
next if resource.nil?
source_array.each do |json|
resource = FHIR::Json.from_json(json)
next if resource.nil?

dataset.push resource
end
dataset.push resource
end

puts "Loaded #{dataset.length} resources"
dataset
end
puts "Loaded #{dataset.length} resources"
dataset
end

def self.from_path(path)
dataset = Dataset.new
def self.from_path(path)
dataset = []

Dir["#{path}/*.json"].each do |f|
resource = FHIR::Json.from_json(File.read(f))
next if resource.nil?
Dir["#{path}/*.json"].each do |f|
resource = FHIR::Json.from_json(File.read(f))
next if resource.nil?

dataset.push resource
end
dataset.push resource
end

puts "Loaded #{dataset.length} resources"
dataset
puts "Loaded #{dataset.length} resources"
dataset
end
end
end
end
end

0 comments on commit d1f2e83

Please sign in to comment.