-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d4662d
commit bd9aaa1
Showing
6 changed files
with
148 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
module Inferno | ||
module DSL | ||
module FHIREvaluation | ||
class Config | ||
DEFAULT_FILE = File.join(__dir__, 'config', 'default.yml') | ||
attr_accessor :data | ||
class Config | ||
DEFAULT_FILE = File.join(__dir__, 'config', 'default.yml') | ||
attr_accessor :data | ||
|
||
# To-do: add config_file as arguments | ||
def initialize(config_file = nil) | ||
@data = if config_file.nil? | ||
YAML.load_file(File.absolute_path(DEFAULT_FILE)) | ||
else | ||
YAML.load_file(File.absolute_path(config_file)) | ||
end | ||
# To-do: add config_file as arguments | ||
def initialize(config_file = nil) | ||
@data = if config_file.nil? | ||
YAML.load_file(File.absolute_path(DEFAULT_FILE)) | ||
else | ||
YAML.load_file(File.absolute_path(config_file)) | ||
end | ||
|
||
raise(TypeError, 'Malformed configuration') unless @data.is_a?(Hash) | ||
raise(TypeError, 'Malformed configuration') unless @data.is_a?(Hash) | ||
|
||
def method_missing(name, *args, &) | ||
section = @data[name.to_s] | ||
if section | ||
Section.new(section) | ||
else | ||
super | ||
def method_missing(name, *args, &) | ||
section = @data[name.to_s] | ||
if section | ||
Section.new(section) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def respond_to_missing?(name, include_private = false) | ||
@data.key?(name.to_s) || super | ||
end | ||
end | ||
end | ||
|
||
def respond_to_missing?(name, include_private = false) | ||
@data.key?(name.to_s) || super | ||
end | ||
end | ||
class Section | ||
def initialize(details) | ||
@details = details | ||
end | ||
|
||
class Section | ||
def initialize(details) | ||
@details = details | ||
end | ||
def method_missing(name, *_args) | ||
attribute = @details[name.to_s] | ||
if attribute.is_a?(Hash) | ||
Section.new(attribute) | ||
else | ||
attribute | ||
end | ||
end | ||
|
||
def method_missing(name, *_args) | ||
attribute = @details[name.to_s] | ||
if attribute.is_a?(Hash) | ||
Section.new(attribute) | ||
else | ||
attribute | ||
def respond_to_missing?(name, include_private = false) | ||
@details.key?(name.to_s) || super | ||
end | ||
end | ||
end | ||
|
||
def respond_to_missing?(name, include_private = false) | ||
@details.key?(name.to_s) || super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,95 @@ | ||
module FhirEvaluator | ||
# DataSummary represents the results of performing data characterization. | ||
# At this point DataSummary isn't actually used by the evaluator. | ||
# We will bring back when we need it. | ||
|
||
# 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 | ||
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 | ||
|
||
# def initialize(data) | ||
# @root_resource_ids = [] | ||
# @root_bundle_resource_ids = [] | ||
# @domain_resource_ids = [] | ||
# @resource_profile_map = [] | ||
# @resource_patient_map = [] | ||
# @resource_subject_map = [] | ||
def initialize(_data) | ||
@root_resource_ids = [] | ||
@root_bundle_resource_ids = [] | ||
@domain_resource_ids = [] | ||
@resource_profile_map = [] | ||
@resource_patient_map = [] | ||
@resource_subject_map = [] | ||
end | ||
|
||
# validate(data) | ||
# summarize(data) | ||
# end | ||
def validate(data) | ||
resource_ids = data.map { |r| extract_resources_ids(r) }.flatten | ||
|
||
# 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 | ||
if resource_ids.uniq == resource_ids | ||
puts 'No duplicate Ids found. Proceed to evaluate..' | ||
else | ||
dup = resource_ids.detect { |r| resource_ids.count(r) > 1 } | ||
puts "Warning: Found duplicate resource Ids: #{dup}. Please validate Examples before running FHIR Evaluator." | ||
end | ||
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 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' } | ||
|
||
# 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' } | ||
# 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 | ||
|
||
# # 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 | ||
# @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 | ||
|
||
# # @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 extract_resources_ids(resource) | ||
if resource.resourceType == 'Bundle' | ||
resource.entry.map { |e| extract_resources_ids(e.resource) }.flatten | ||
else | ||
"#{resource.resourceType}/#{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(resource) | ||
if resource.resourceType == 'Bundle' | ||
resource.entry.map { |e| resources(e.resource) }.flatten | ||
else | ||
{ type: resource.resourceType, id: resource.id } | ||
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 extract_resources_profiles(resource) | ||
if resource.resourceType == 'Bundle' | ||
resource.entry.map { |e| extract_resources_profiles(e.resource) }.flatten.uniq | ||
elsif resource.meta&.profile | ||
{ resource_id: resource.id, profile: resource.meta&.profile } | ||
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 extract_resources_patients(resource) | ||
if resource.resourceType == 'Bundle' | ||
resource.entry.map { |e| extract_resources_patients(e.resource) }.flatten.uniq | ||
elsif defined? resource.patient.reference | ||
{ resource_id: resource.id, patient: resource.patient.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 extract_resources_subjects(resource) | ||
if resource.resourceType == 'Bundle' | ||
resource.entry.map { |e| extract_resources_subjects(e.resource) }.flatten.uniq | ||
elsif defined? resource.subject.reference | ||
{ resource_id: resource.id, subject: resource.subject.reference } | ||
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 | ||
def to_json(*_args) | ||
{ | ||
'Resources' => domain_resource_ids.length, | ||
'Root Resources' => root_resource_ids.length | ||
} | ||
end | ||
end | ||
end |
Oops, something went wrong.