Skip to content

Commit

Permalink
Merge pull request #217 from hl7au/199-separate-include-tests
Browse files Browse the repository at this point in the history
199 separate include tests
  • Loading branch information
projkov authored Oct 12, 2024
2 parents 92ab51e + 9710092 commit 0d31ae9
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ AllCops:
- 'lib/au_core_test_kit/generator/special_identifier_search_test_generator.rb'
- 'lib/au_core_test_kit/special_identifier_search_test.rb'
- 'lib/au_core_test_kit/generator/special_identifiers_chain_search_test_generator.rb'
- 'lib/au_core_test_kit/generator/include_search_test_generator.rb'
Style/Documentation:
Enabled: false
Layout/LineLength:
Expand Down
6 changes: 6 additions & 0 deletions lib/au_core_test_kit/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_relative 'generator/chain_search_test_generator'
require_relative 'generator/special_identifier_search_test_generator'
require_relative 'generator/special_identifiers_chain_search_test_generator'
require_relative 'generator/include_search_test_generator'

module AUCoreTestKit
class Generator
Expand All @@ -42,6 +43,7 @@ def generate
generate_search_tests
generate_read_tests
generate_provenance_revinclude_search_tests
generate_include_search_tests
generate_validation_tests
generate_must_support_tests
generate_reference_resolution_tests
Expand Down Expand Up @@ -93,6 +95,10 @@ def generate_search_tests
generate_special_identifiers_chain_search_tests
end

def generate_include_search_tests
IncludeSearchTestGenerator.generate(ig_metadata, base_output_dir)
end

def generate_provenance_revinclude_search_tests
ProvenanceRevincludeSearchTestGenerator.generate(ig_metadata, base_output_dir)
end
Expand Down
92 changes: 92 additions & 0 deletions lib/au_core_test_kit/generator/include_search_test_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true

require_relative 'naming'
require_relative 'special_cases'
require_relative 'search_test_generator'

module AUCoreTestKit
class Generator
class IncludeSearchTestGenerator < SearchTestGenerator
class << self
def generate(ig_metadata, base_output_dir)
ig_metadata.groups
.reject { |group| SpecialCases.exclude_group? group }
.select { |group| group.include_params.present? }
.each do |group|
group.include_params.each { |include_param| new(group, group.searches.first, base_output_dir, include_param).generate }
end
end
end

attr_accessor :group_metadata, :search_metadata, :base_output_dir, :include_param

def initialize(group_metadata, search_metadata, base_output_dir, include_param)
self.group_metadata = group_metadata
self.search_metadata = search_metadata
self.base_output_dir = base_output_dir
self.include_param = include_param
end

def template
@template ||= File.read(File.join(__dir__, 'templates', 'include.rb.erb'))
end

def search_identifier
includes.first['target_resource']
end

def class_name
"#{Naming.upper_camel_case_for_profile(group_metadata)}#{search_title}IncludeTest"
end

def conformance_expectation
'SHOULD'
end

def optional?
true
end

def needs_patient_id?
true
end

def search_properties
{}.tap do |properties|
properties[:resource_type] = "'#{resource_type}'"
properties[:saves_delayed_references] = 'true' if saves_delayed_references?
properties[:search_param_names] = search_param_names_array
properties[:includes] = includes if group_metadata.include_params.present?
end
end

def target_resources_string
includes.map { |include| include['target_resource'] }.join(', ')
end

def include_params_string
includes.map { |include| include['parameter'] }.join(', ')
end

def search_param_names_string
search_param_names.join(', ')
end

def title
"Server returns #{target_resources_string} resources from #{resource_type} search by #{search_param_names_string} and #{include_params_string}"
end

def description
<<~DESCRIPTION.gsub(/\n{3,}/, "\n\n")
This test will perform a search by #{search_param_names_string} and #{include_params_string}
Test will pass if a #{target_resources_string} resources are found in the response.
DESCRIPTION
end

def search_method
'run_include_test'
end
end
end
end
48 changes: 48 additions & 0 deletions lib/au_core_test_kit/generator/templates/include.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require_relative '../../../search_test'
require_relative '../../../generator/group_metadata'
require_relative '../../../helpers'

module AUCoreTestKit
module <%= module_name %>
class <%= class_name %> < Inferno::Test
include AUCoreTestKit::SearchTest
title '<%= title %>'
description %(
<%= description %>
)

id :<%= test_id %><% if optional? %>
optional
<% end %><% if needs_patient_id? %>
input :patient_ids,
title: 'Patient IDs',
description: 'Comma separated list of patient IDs that in sum contain all MUST SUPPORT elements',
default: '<%= Helpers.default_patient_ids_string %>'
<% end %><% if resource_type == 'Device' %>
input :implantable_device_codes,
title: 'Implantable Device Type Code',
description: 'Enter the code for an Implantable Device type, or multiple codes separated by commas. '\
'If blank, Inferno will validate all Device resources against the Implantable Device profile',
optional: true
<% end %>
def self.properties
@properties ||= SearchTestProperties.new(
<%= search_test_properties_string %>
)
end

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

def scratch_resources
scratch[:<%= profile_identifier %>_resources] ||= {}
end

run do
<%= search_method %>
end
end
end
end

26 changes: 23 additions & 3 deletions lib/au_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ def run_search_test_with_system
run_search_test_common(method(:perform_search_with_system))
end

def run_include_test
all_search_params.flat_map do |patient_id, params_list|
patient_resources = scratch_resources_for_patient(patient_id)
next if patient_resources.blank?
params_list.flat_map do |params|
includes.each do |include_param|
test_include_param(
patient_resources,
params,
patient_id,
include_param,
false
)
end
end
end
end

def run_read_test_and_skip_first_search(patient_id)
resource = create_reference('Patient', patient_id)
read_and_validate_as_first(resource, patient_id)
Expand Down Expand Up @@ -450,8 +468,8 @@ def perform_multiple_search_test(multiple_type)
end
end

def test_include_param(base_resources, params, patient_id, include_param)
return if search_variant_test_records[:inclusion]
def test_include_param(base_resources, params, patient_id, include_param, keep_search_variant = true)
return if keep_search_variant && search_variant_test_records[:inclusion]
resources_to_check = "#{include_param['target_resource'].downcase}_resources".to_sym
target_resource_type = include_param['target_resource']

Expand Down Expand Up @@ -507,7 +525,9 @@ def test_include_param(base_resources, params, patient_id, include_param)
scratch[resources_to_check][:all] += resources
scratch[resources_to_check][patient_id] += resources

search_variant_test_records[:inclusion] = true
if keep_search_variant
search_variant_test_records[:inclusion] = true
end
end

def is_reference_match?(reference, local_reference)
Expand Down

0 comments on commit 0d31ae9

Please sign in to comment.