Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ end

group :development do
gem "fasterer", "~> 0.11.0"
gem "flay", "~> 2.13.3"
gem "flog", "~> 4.8.0"
gem "reek", "~> 6.1.0"
gem "rubocop", "~> 1.59.0"
gem "rubocop-erb", require: false
Expand All @@ -25,6 +27,4 @@ group :development do
gem "rubocop-performance", require: false
gem "rubocop-rake", require: false
gem "steep", "~> 1.10"
gem "flay", "~> 2.13.3"
gem "flog", "~> 4.8.0"
end
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ docker-typecheck: docker-build
docker-lint: docker-build
$(DOCKER_RUN) bundle exec rubocop .

docker-lint-fix: docker-build
$(DOCKER_RUN) bundle exec rubocop . -A

docker-tests: docker-build
$(DOCKER_RUN) bundle exec rake test

Expand All @@ -68,4 +71,4 @@ docker-check: docker-build
$(MAKE) docker-fasterer
$(MAKE) docker-reek
$(MAKE) docker-typecheck
$(MAKE) docker-tests
$(MAKE) docker-tests
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def must_support_extensions
must_support_extension_elements.map do |element|
{
id: element.id,
url: element.type.first.profile.first.split('|').first
url: element.type.first.profile.first.split("|").first
}.tap do |metadata|
metadata[:uscdi_only] = true if is_uscdi_requirement_element?(element)
end
Expand All @@ -70,12 +70,13 @@ def must_support_pattern_slice_elements
must_support_slice_elements.select do |element|
discriminator_list = discriminators(sliced_element(element))
next if discriminator_list.nil?

discriminator_list.first.type == "pattern"
end
end

def pattern_slices
must_support_pattern_slice_elements.map do |current_element|
must_support_pattern_slice_elements.filter_map do |current_element|
next if current_element.id.include? ":"

{
Expand Down Expand Up @@ -132,13 +133,14 @@ def pattern_slices

metadata[:uscdi_only] = true if is_uscdi_requirement_element?(current_element)
end
end.compact
end
end

def must_support_type_slice_elements
must_support_slice_elements.select do |element|
discriminator_list = discriminators(sliced_element(element))
next if discriminator_list.nil?

discriminator_list.first.type == "type"
end
end
Expand Down Expand Up @@ -175,6 +177,7 @@ def must_support_value_slice_elements
must_support_slice_elements.select do |element|
discriminator_list = discriminators(sliced_element(element))
next if discriminator_list.nil?

discriminator_list.first.type == "value"
end
end
Expand Down Expand Up @@ -246,7 +249,7 @@ def save_type_code?(type)
end

def get_type_must_support_metadata(current_metadata, current_element)
current_element.type.map do |type|
current_element.type.filter_map do |type|
next unless type_must_support_extension?(type.extension)

metadata =
Expand All @@ -258,7 +261,7 @@ def get_type_must_support_metadata(current_metadata, current_element)
handle_type_must_support_target_profiles(type, metadata) if type.code == "Reference"

metadata
end.compact
end
end

def handle_type_must_support_target_profiles(type, metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def full_paths
@full_paths ||=
begin
full_paths = param.expression.split("|").map do |expr|
expr.strip.gsub(/.where\(resolve\((.*)/, "").gsub(/url = '/,
expr.strip.gsub(/.where\(resolve\((.*)/, "").gsub("url = '",
"url='").gsub(/\.ofType\(([^)]+)\)/) do |_match|
type_name = ::Regexp.last_match(1)
"#{type_name[0].upcase}#{type_name[1..]}"
Expand Down Expand Up @@ -234,7 +234,7 @@ def values_from_must_support_slices(profile_element, short_path, mandatory_slice

group_metadata[:must_supports][:slices]
.select { |slice| [short_path, "#{short_path}.coding"].include?(slice[:path]) }
.map do |slice|
.filter_map do |slice|
slice_element = profile_elements.find { |element| slice[:slice_id] == element.id }
next if profile_element.min.positive? && slice_element.min.zero? && mandatory_slice_only

Expand All @@ -249,7 +249,7 @@ def values_from_must_support_slices(profile_element, short_path, mandatory_slice
.map { |value| value[:value] }
end
end
.compact.flatten
.flatten
end

def values_from_must_support_elements(short_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ def remove_excluded_search_params(search_params)
def remove_params_to_ignore(combo_search_params)
# Remove combo search params if they are should be ignored, like _count, _sort, etc.
combo_search_params.each do |combo_search_param|
if combo_search_param[:names].any? { |sp| config.search_params_to_ignore.include? sp }
current_search_params = combo_search_param[:names].filter { |sp| !config.search_params_to_ignore.include? sp }
combo_search_param[:names] = current_search_params
next unless combo_search_param[:names].any? { |sp| config.search_params_to_ignore.include? sp }

current_search_params = combo_search_param[:names].filter do |sp|
!config.search_params_to_ignore.include? sp
end
combo_search_param[:names] = current_search_params
end

# In some cases when we remove param to ignore, as the result we have duplicated combo params
Expand All @@ -124,7 +126,10 @@ def remove_combo_search_params_duplicates(combo_search_params)
result = []
combo_search_params.each do |combo_search_param|
next if result.any? { |r| r[:names] == combo_search_param[:names] }
expectation = use_the_high_expectation_search_param(combo_search_params.select { |sp| sp[:names] == combo_search_param[:names] })

expectation = use_the_high_expectation_search_param(combo_search_params.select do |sp|
sp[:names] == combo_search_param[:names]
end)
combo_search_param[:expectation] = expectation
result << combo_search_param
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def capability_statement_reference_string

def generate
FileUtils.mkdir_p(output_file_directory)
File.open(output_file_name, "w") { |f| f.write(output) }
File.write(output_file_name, output)

group_metadata.add_test(
id: test_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module InfernoSuiteGenerator
class Generator
class ChainSearchTestGenerator < SearchTestGenerator
include GeneratorUtils

class << self
def generate(ig_metadata, base_output_dir)
ig_metadata.groups
Expand Down
4 changes: 2 additions & 2 deletions lib/inferno_suite_generator/generators/group_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def optional?
end

def generate
File.open(output_file_name, "w") { |f| f.write(output) }
File.write(output_file_name, output)
group_metadata.id = group_id
group_metadata.file_name = base_output_file_name
File.open(metadata_file_name, "w") { |f| f.write(YAML.dump(group_metadata.to_hash)) }
File.write(metadata_file_name, YAML.dump(group_metadata.to_hash))
end

def test_id_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class << self
def generate(ig_metadata, base_output_dir, ig_resources = nil)
ig_metadata.groups.each do |group|
group_generate(group, base_output_dir, {
ig_metadata: ig_metadata, ig_resources: ig_resources
ig_metadata:, ig_resources:
})
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module InfernoSuiteGenerator
class Generator
class ProvenanceRevincludeSearchTestGenerator < BasicTestGenerator
include GeneratorUtils

class << self
def generate(ig_metadata, base_output_dir)
ig_metadata.groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module InfernoSuiteGenerator
class Generator
class SearchTestGenerator < BasicTestGenerator
include GeneratorUtils

class << self
def generate(ig_metadata, base_output_dir)
ig_metadata.groups
Expand Down Expand Up @@ -59,7 +60,7 @@ def fixed_value_search?

def first_search_not_patient?
first_search? && search_metadata[:names] != ["patient"] &&
!group_metadata.delayed? && resource_type != "Patient"
!group_metadata.delayed? && resource_type != "Patient"
end

def any_observation_search?
Expand Down
2 changes: 1 addition & 1 deletion lib/inferno_suite_generator/generators/suite_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def generate
links_replacement = " links [\n#{links_array}\n ]"
template_output.gsub!(/ links \[.*?\]/m, links_replacement)

File.open(output_file_name, "w") { |f| f.write(template_output) }
File.write(output_file_name, template_output)
end

def groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def skip_if_empty

def generate
FileUtils.mkdir_p(output_file_directory)
File.open(output_file_name, "w") { |f| f.write(output) }
File.write(output_file_name, output)

test_metadata = {
id: test_id,
Expand Down
6 changes: 6 additions & 0 deletions lib/inferno_suite_generator/templates/create.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ module <%= suite_module_name %>
)
end

def self.metadata
@metadata ||= InfernoSuiteGenerator::Generator::GroupMetadata.new(
YAML.load_file(File.join(__dir__, 'metadata.yml'), aliases: true)
)
end

def resource_type
'<%= resource_type %>'
end
Expand Down
10 changes: 10 additions & 0 deletions lib/inferno_suite_generator/templates/update.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ module <%= suite_module_name %>
'<%= resource_type %>'
end

def self.demodata
@demodata ||= InfernoSuiteGenerator::Generator::IGDemodata.new(
YAML.load_file(File.join(File.dirname(__dir__), 'demodata.yml'), aliases: true)
)
end

def self.metadata
@metadata ||= InfernoSuiteGenerator::Generator::GroupMetadata.new(YAML.load_file(File.join(__dir__, 'metadata.yml'), aliases: true))
end

run do
<%= executor %>
end
Expand Down
22 changes: 21 additions & 1 deletion lib/inferno_suite_generator/test_modules/basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,27 @@ def demo_resources
end

def resource_body_by_resource_type(resource_type)
resource_body_list[resource_type] || []
resources_by_resource_type = resource_body_list[resource_type] || []
if resources_by_resource_type.empty?
warning "No #{resource_type} resources appear to be available."

return []
end

resource_filtered_by_profile = resources_by_resource_type.select do |resource|
next false if resource["meta"].blank?
next false if resource["meta"]["profile"].blank?

resource["meta"]["profile"].include?(metadata.profile_url)
end

if resource_filtered_by_profile.empty?
warning "No #{resource_type} resources appear to be available with profile #{metadata.profile_url}"

return resources_by_resource_type
end

resource_filtered_by_profile
end

def resource_body_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def extract_target_resource_from_chained_search_parameter(search_param)
end

def get_resources_identifier(resources, target_identifier)
if !target_identifier
resources.map(&:identifier).flatten
else
if target_identifier
resources.map do |r|
r.identifier.filter { |idnt| idnt.system == target_identifier[:url] }
end.flatten
else
resources.map(&:identifier).flatten
end
end

Expand Down
9 changes: 5 additions & 4 deletions lib/inferno_suite_generator/test_modules/must_support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def perform_must_support_test(resources)

pass if (missing_elements + missing_slices + missing_extensions).empty?
skip_with_msg "Could not find #{missing_must_support_strings.join(", ")} element(s) in the #{resources.length} " \
"provided #{resource_type} resource(s). To prevent this issue, please add the missing must support "\
"elements to at least one #{resource_type} resource on the server."
"provided #{resource_type} resource(s). To prevent this issue, please add the missing must support " \
"elements to at least one #{resource_type} resource on the server."
end

def handle_must_support_choices
Expand Down Expand Up @@ -114,7 +114,7 @@ def missing_elements(resources = [])
path = element_definition[:path] # .delete_suffix('[x]')
value_found = find_a_value_at(resource, path) do |value|
value_without_extensions =
value.respond_to?(:to_hash) ? value.to_hash.reject { |key, _| key == "extension" } : value
value.respond_to?(:to_hash) ? value.to_hash.except("extension") : value

(value_without_extensions.present? || value_without_extensions == false) &&
(element_definition[:fixed_value].blank? || value == element_definition[:fixed_value])
Expand Down Expand Up @@ -188,7 +188,8 @@ def find_slice_by_values(element, value_definitions)
.select { |value_definition| value_definition[:path].first == path_prefix }
.each { |value_definition| value_definition[:path].shift }

search_path = if el.respond_to?(:coding) && !el.respond_to?(path_prefix.to_sym) && %w[code system display].include?(path_prefix)
search_path = if el.respond_to?(:coding) && !el.respond_to?(path_prefix.to_sym) && %w[code system
display].include?(path_prefix)
"coding.#{path_prefix}"
else
path_prefix
Expand Down
7 changes: 4 additions & 3 deletions lib/inferno_suite_generator/test_modules/read_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def perform_read_test(resources, _reply_handler = nil)
def fetch_resource_ids(resource_type)
method_name = "#{camel_to_snake(resource_type)}_ids"
return "" unless respond_to?(method_name)

send(method_name)
end

Expand Down Expand Up @@ -91,8 +92,8 @@ def read_and_validate(resource_to_read)
def read_and_validate_as_first(resource_to_read, patient_id)
basic_read_and_validate(resource_to_read)

all_scratch_resources.concat([resource]).uniq!
scratch_resources_for_patient(patient_id).concat([resource]).uniq!
all_scratch_resources.push(resource).uniq!
scratch_resources_for_patient(patient_id).push(resource).uniq!
end

def resource_id(resource)
Expand All @@ -101,7 +102,7 @@ def resource_id(resource)

def no_resources_skip_message
"No #{resource_type} resources appear to be available. " \
"Please use patients with more information."
"Please use patients with more information."
end

def bad_resource_id_message(expected_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def resolved_references

def no_resources_skip_message
"No #{resource_type} resources appear to be available. " \
"Please use patients with more information."
"Please use patients with more information."
end

def must_support_references
Expand Down
Loading