Module: Inferno::DSL::InputOutputHandling

Defined in:
lib/inferno/dsl/input_output_handling.rb

Instance Method Summary collapse

Instance Method Details

#all_outputsObject



147
148
149
150
151
152
# File 'lib/inferno/dsl/input_output_handling.rb', line 147

def all_outputs
  outputs
    .map { |output_identifier| config.output_name(output_identifier) }
    .concat(all_children.flat_map(&:all_outputs))
    .uniq
end

#available_inputs(selected_suite_options = nil) ⇒ Object

Inputs available for the user for this runnable and all its children.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/inferno/dsl/input_output_handling.rb', line 183

def available_inputs(selected_suite_options = nil)
  available_inputs =
    config.inputs
      .slice(*inputs)
      .each_with_object({}) do |(_, input), inputs|
        inputs[input.name.to_sym] = Entities::Input.new(**input.to_hash)
      end

  available_inputs.each do |input, current_definition|
    child_definition = children_available_inputs(selected_suite_options)[input]
    current_definition.merge_with_child(child_definition)
  end

  available_inputs = children_available_inputs(selected_suite_options).merge(available_inputs)
  order_available_inputs(available_inputs)
end

#children_available_inputs(selected_suite_options = nil) ⇒ Object

Inputs available for this runnable’s children. A running list of outputs created by the children is used to exclude any inputs which are provided by an earlier child’s output.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/inferno/dsl/input_output_handling.rb', line 158

def children_available_inputs(selected_suite_options = nil)
  child_outputs = []
  children(selected_suite_options).each_with_object({}) do |child, definitions|
    new_definitions = child.available_inputs(selected_suite_options).map(&:dup)
    new_definitions.each do |input, new_definition|
      existing_definition = definitions[input]

      updated_definition =
        if existing_definition.present?
          existing_definition.merge_with_child(new_definition)
        else
          new_definition
        end

      next if child_outputs.include?(updated_definition.name.to_sym)

      definitions[updated_definition.name.to_sym] = updated_definition
    end

    child_outputs.concat(child.all_outputs).uniq!
  end
end

#input(identifier, *other_identifiers, **input_params) ⇒ void

This method returns an undefined value.

Define inputs

Examples:

input :patient_id, title: 'Patient ID', description: 'The ID of the patient being searched for',
                  default: 'default_patient_id'
input :textarea, title: 'Textarea Input Example', type: 'textarea', optional: true

Parameters:

  • identifier (Symbol)

    identifier for the input

  • other_identifiers (Symbol)

    array of symbols if specifying multiple inputs

  • input_params (Hash)

    options for input such as type, description, or title

  • options (Hash)

    a customizable set of options

Options Hash (**input_params):

  • :title (String)

    Human readable title for input

  • :description (String)

    Description for the input

  • :type (String)

    text | textarea | radio | checkbox | oauth_credentials

  • :default (String)

    The default value for the input

  • :optional (Boolean)

    Set to true to not require input for test execution

  • :locked (Boolean)

    If true, the user can not alter the value

  • :options (Hash)

    Possible input option formats based on input type



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/inferno/dsl/input_output_handling.rb', line 24

def input(identifier, *other_identifiers, **input_params)
  if other_identifiers.present?
    [identifier, *other_identifiers].compact.each do |input_identifier|
      inputs << input_identifier
      config.add_input(input_identifier)
      children
        .reject { |child| child.inputs.include? input_identifier }
        .each do |child|
          child.input(input_identifier)
        end
    end
  else
    inputs << identifier
    config.add_input(identifier, input_params)
    children
      .reject { |child| child.inputs.include? identifier }
      .each do |child|
        child.input(identifier, **input_params)
      end
  end
end

#input_order(*new_input_order) ⇒ Array<String, Symbol>

Define a particular order for inputs to be presented in the API/UI

Examples:

group do
  input :input1, :input2, :input3
  input_order :input3, :input2, :input1
end

Parameters:

  • new_input_order (Array<String,Symbol>)

Returns:

  • (Array<String, Symbol>)


116
117
118
119
120
# File 'lib/inferno/dsl/input_output_handling.rb', line 116

def input_order(*new_input_order)
  return @input_order = new_input_order if new_input_order.present?

  @input_order ||= []
end

#inputsObject



80
81
82
# File 'lib/inferno/dsl/input_output_handling.rb', line 80

def inputs
  @inputs ||= []
end

#missing_inputs(submitted_inputs, selected_suite_options) ⇒ Object



102
103
104
105
106
# File 'lib/inferno/dsl/input_output_handling.rb', line 102

def missing_inputs(, selected_suite_options)
   = [] if .nil?

  required_inputs(selected_suite_options).map(&:to_s) - .map { |input| input[:name] }
end

#order_available_inputs(original_inputs) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/inferno/dsl/input_output_handling.rb', line 123

def order_available_inputs(original_inputs)
  input_names = original_inputs.map { |_, input| input.name }.join(', ')

  ordered_inputs =
    input_order.each_with_object({}) do |input_name, inputs|
      key, input = original_inputs.find { |_, input| input.name == input_name.to_s }
      if input.nil?
        Inferno::Application[:logger].error <<~ERROR
          Error trying to order inputs in #{id}: #{title}:
          - Unable to find input #{input_name} in available inputs: #{input_names}
        ERROR
        next
      end
      inputs[key] = original_inputs.delete(key)
    end

  original_inputs.each do |key, input|
    ordered_inputs[key] = input
  end

  ordered_inputs
end

#output(identifier, *other_identifiers, **output_definition) ⇒ void

This method returns an undefined value.

Define outputs

Examples:

output :patient_id, :condition_id, :observation_id
output :oauth_credentials, type: 'oauth_credentials'

Parameters:

  • identifier (Symbol)

    identifier for the output

  • other_identifiers (Symbol)

    array of symbols if specifying multiple outputs

  • output_definition (Hash)

    options for output

Options Hash (**output_definition):

  • :type (String)

    text, textarea, or oauth_credentials



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/inferno/dsl/input_output_handling.rb', line 57

def output(identifier, *other_identifiers, **output_definition)
  if other_identifiers.present?
    [identifier, *other_identifiers].compact.each do |output_identifier|
      outputs << output_identifier
      config.add_output(output_identifier)
      children
        .reject { |child| child.outputs.include? output_identifier }
        .each do |child|
          child.output(output_identifier)
        end
    end
  else
    outputs << identifier
    config.add_output(identifier, output_definition)
    children
      .reject { |child| child.outputs.include? identifier }
      .each do |child|
        child.output(identifier, **output_definition)
      end
  end
end

#output_definitionsObject



90
91
92
# File 'lib/inferno/dsl/input_output_handling.rb', line 90

def output_definitions
  config.outputs.slice(*outputs)
end

#outputsObject



85
86
87
# File 'lib/inferno/dsl/input_output_handling.rb', line 85

def outputs
  @outputs ||= []
end

#required_inputs(selected_suite_options) ⇒ Object



95
96
97
98
99
# File 'lib/inferno/dsl/input_output_handling.rb', line 95

def required_inputs(selected_suite_options)
  available_inputs(selected_suite_options)
    .reject { |_, input| input.optional }
    .map { |_, input| input.name }
end