Class: DaVinciUSDrugFormularyTestKit::Generator::IncludeSearchTestGenerator

Inherits:
SearchTestGenerator
  • Object
show all
Defined in:
lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb

Constant Summary collapse

INCLUDE_SEARCH_PARAMS =
{ 'Payer Insurance Plan' => 'coverage-type', 'Formulary Item' => 'code' }.freeze

Instance Attribute Summary collapse

Attributes inherited from SearchTestGenerator

#base_output_dir, #group_metadata, #search_metadata

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SearchTestGenerator

#array_of_strings, #base_output_file_name, #conformance_expectation, #description, #first_search?, #first_search_description, #fixed_value_search?, #fixed_value_search_param_name, #generate, #module_name, #needs_id?, #optional?, #output, #output_file_directory, #output_file_name, #path_for_value, #post_search_description, #profile_identifier, #reference_search_description, #required_comparators, #required_comparators_for_param, #required_comparators_string, #required_multiple_or_search_params, #required_multiple_or_search_params_string, #resource_type, #saves_delayed_references?, #search_definition, #search_param_name_string, #search_param_names, #search_param_names_array, #search_params, #search_test_properties_string, #search_title, #test_post_search?, #test_reference_variants?, #token_search_params, #token_search_params_string, #url_version

Constructor Details

#initialize(group_metadata, search_metadata, base_output_dir, include_param) ⇒ IncludeSearchTestGenerator

Returns a new instance of IncludeSearchTestGenerator.



28
29
30
31
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 28

def initialize(, , base_output_dir, include_param)
  super(, , base_output_dir)
  self.include_param = include_param
end

Instance Attribute Details

#include_paramObject

Returns the value of attribute include_param.



26
27
28
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 26

def include_param
  @include_param
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 9

def generate(, base_output_dir)
  # The IG defines the formulary-coverage include param for both InsuancePlan profiles,
  # even though it only pertains to Payer Insurance Plan, so we explicitly exclude Formulary
  .groups
    .reject { |group| group.profile_name == 'Formulary' }
    .reject { |group| group.include_params.empty? }
    .each do |group|
      group.include_params.each do |include_param|
        search_meta = group.searches.find do |search|
          search[:names].include? INCLUDE_SEARCH_PARAMS[group.profile_name]
        end
        new(group, search_meta, base_output_dir, include_param).generate
      end
    end
end

Instance Method Details

#class_nameObject



45
46
47
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 45

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

#include_param_resourceObject



73
74
75
76
77
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 73

def include_param_resource
  res_type = .search_definitions[:"#{include_search_look_up_param}"][:type]
  res_type = .search_definitions[:"#{include_search_look_up_param}"][:target] if res_type == 'Reference'
  res_type
end

#include_param_stringObject



69
70
71
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 69

def include_param_string
  "_include=#{include_param}"
end

#include_search_look_up_paramObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 58

def include_search_look_up_param
  # Returns the `searchParam` part of the `include_param` string, which should be
  # formatted as `SourceType:searchParam(:targetType)`. See (https://hl7.org/fhir/R4/search.html#table)
  # If the `include_param` is formatted incorrectly, returns `include_param`.
  #
  # The `searchParam` part of `include_param` is necessary for indexing dictionaries generated
  # from the `searchParams` list in the Capability Statement.
  params = include_param.split(':')
  params.length > 1 ? params[1] : include_param
end

#search_identifierObject



41
42
43
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 41

def search_identifier
  include_search_look_up_param.gsub(/[-:]/, '_').underscore
end

#search_propertiesObject



49
50
51
52
53
54
55
56
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 49

def search_properties
  {}.tap do |properties|
    properties[:resource_type] = "'#{resource_type}'"
    properties[:search_param_names] = search_param_names
    properties[:include_param] = "'#{include_param}'"
    properties[:include_search_look_up_param] = "'#{include_search_look_up_param}'"
  end
end

#templateObject



33
34
35
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 33

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

#test_idObject



37
38
39
# File 'lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb', line 37

def test_id
  "usdf_#{.reformatted_version}_#{profile_identifier}_#{search_identifier}_include_search_test"
end