Class: DaVinciPlanNetTestKit::Generator::ReverseChainSearchTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, search_metadata, base_output_dir, rev_chain_example) ⇒ ReverseChainSearchTestGenerator

Returns a new instance of ReverseChainSearchTestGenerator.



20
21
22
23
24
25
26
27
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 20

def initialize(, , base_output_dir, rev_chain_example)
  self. = 
  self. = 
  self.base_output_dir = base_output_dir
  self.source_resource = rev_chain_example["source_resource"]
  self.target_param = rev_chain_example["target_param"]
  self.constraining_param = rev_chain_example["constraining_param"]
end

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 18

def base_output_dir
  @base_output_dir
end

#constraining_paramObject

Returns the value of attribute constraining_param.



18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 18

def constraining_param
  @constraining_param
end

#group_metadataObject

Returns the value of attribute group_metadata.



18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 18

def 
  @group_metadata
end

#search_metadataObject

Returns the value of attribute search_metadata.



18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 18

def 
  @search_metadata
end

#source_resourceObject

Returns the value of attribute source_resource.



18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 18

def source_resource
  @source_resource
end

#target_paramObject

Returns the value of attribute target_param.



18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 18

def target_param
  @target_param
end

Class Method Details

.generate(ig_metadata, examples_hash, base_output_dir) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 8

def generate(, examples_hash, base_output_dir)
  examples_hash.keys.each do |group|
    examples_hash[group].each do |rev_chain_example| 
      group_to_add_to = .groups.find { |ig_meta_group| ig_meta_group.name == "plannet_#{group}"}
      new(group_to_add_to, group_to_add_to.searches.first, base_output_dir, rev_chain_example).generate
    end
  end
end

Instance Method Details

#a_or_an(name) ⇒ Object



100
101
102
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 100

def a_or_an(name)
  ['a','e','i','o','u'].include?(name.first.downcase) ? "an #{name}" : "a #{name}"
end

#array_of_strings(array) ⇒ Object



155
156
157
158
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 155

def array_of_strings(array)
  quoted_strings = array.map { |element| "'#{element}'" }
  "[#{quoted_strings.join(', ')}]"
end

#base_output_file_nameObject



37
38
39
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 37

def base_output_file_name
  "#{class_name.underscore}.rb"
end

#class_nameObject



65
66
67
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 65

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

#first_search?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 87

def first_search?
  .searches.first == 
end

#fixed_value_search?Boolean

Returns:

  • (Boolean)


91
92
93
94
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 91

def fixed_value_search?
  #TODO
  false
end

#fixed_value_search_param_nameObject



96
97
98
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 96

def fixed_value_search_param_name
  #TODO
end

#generateObject



183
184
185
186
187
188
189
190
191
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 183

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

  .add_test(
    id: test_id,
    file_name: base_output_file_name
  )
end

#input_nameObject



160
161
162
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 160

def input_name
  "#{search_identifier}_input"
end

#module_nameObject



69
70
71
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 69

def module_name
  "DaVinciPlanNet#{.reformatted_version.upcase}"
end

#outputObject



33
34
35
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 33

def output
  @output ||= ERB.new(template).result(binding)
end

#output_file_directoryObject



41
42
43
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 41

def output_file_directory
  File.join(base_output_dir, profile_identifier.downcase)
end

#output_file_nameObject



45
46
47
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 45

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#path_for_value(path) ⇒ Object



112
113
114
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 112

def path_for_value(path)
  path == 'class' ? 'local_class' : path
end

#possible_status_search?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 136

def possible_status_search?
  ![:names].include?('status') && .search_definitions.key?(:status)
end

#profile_identifierObject



49
50
51
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 49

def profile_identifier
  Naming.snake_case_for_profile()
end

#required_comparatorsObject



120
121
122
123
124
125
126
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 120

def required_comparators
  @required_comparators ||=
    search_param_names.each_with_object({}) do |name, comparators|
      required_comparators = required_comparators_for_param(name)
      comparators[name] = required_comparators if required_comparators.present?
    end
end

#required_comparators_for_param(name) ⇒ Object



116
117
118
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 116

def required_comparators_for_param(name)
  search_definition(name)[:comparators].select { |_comparator, expectation| expectation == 'SHALL' }
end

#required_comparators_stringObject



151
152
153
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 151

def required_comparators_string
  array_of_strings(required_comparators.keys)
end

#resource_typeObject



73
74
75
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 73

def resource_type
  .resource
end

#saves_delayed_references?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 132

def saves_delayed_references?
  first_search? && .delayed_references.present?
end

#search_definition(name) ⇒ Object



128
129
130
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 128

def search_definition(name)
  .search_definitions[name.to_sym]
end

#search_identifierObject



57
58
59
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 57

def search_identifier
  "#{source_resource}_#{target_param}_#{constraining_param}".gsub(/[-:]/, '_').underscore.gsub("organization_affiliation", "org_affil")
end

#search_param_namesObject



104
105
106
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 104

def search_param_names
  search_params.map { |param| param[:name] }
end

#search_param_names_arrayObject



108
109
110
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 108

def search_param_names_array
  array_of_strings(search_param_names)
end

#search_paramsObject



77
78
79
80
81
82
83
84
85
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 77

def search_params
  @search_params ||=
    [:names].map do |name|
      {
        name: name,
        path: search_definition(name)[:path]
      }
    end
end

#search_propertiesObject



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 164

def search_properties
  {}.tap do |properties|
    properties[:fixed_value_search] = 'true' if fixed_value_search?
    properties[:resource_type] = "'#{resource_type}'"
    properties[:search_param_names] = []
    properties[:input_name] = "'#{input_name}'"
    properties[:reverse_chain_param] = "'#{constraining_param}'"
    properties[:reverse_chain_target] = "'#{target_param}'"
    properties[:possible_status_search] = 'true' if possible_status_search?
    properties[:additional_resource_type] = "'#{source_resource}'"
  end
end

#search_test_properties_stringObject



177
178
179
180
181
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 177

def search_test_properties_string
  search_properties
    .map { |key, value| "#{' ' * 10}#{key}: #{value}" }
    .join(",\n")
end

#search_titleObject



61
62
63
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 61

def search_title
  search_identifier.camelize
end

#templateObject



29
30
31
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 29

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

#test_idObject



53
54
55
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 53

def test_id
  "davinci_plan_net_#{.reformatted_version}_#{profile_identifier}_reverse_chain_#{search_identifier}_search_test"
end

#token_search_paramsObject



140
141
142
143
144
145
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 140

def token_search_params
  @token_search_params ||=
    search_param_names.select do |name|
      ['Identifier', 'CodeableConcept', 'Coding'].include? .search_definitions[name.to_sym][:type]
    end
end

#token_search_params_stringObject



147
148
149
# File 'lib/davinci_plan_net_test_kit/generator/reverse_chain_search_test_generator.rb', line 147

def token_search_params_string
  array_of_strings(token_search_params)
end