Module: Inferno::DSL::InputOutputHandling

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

Instance Method Summary collapse

Instance Method Details

#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

  • :hidden (Boolean)

    If true, the input will not be visible to the user in the UI

  • :options (Hash)

    Possible input option formats based on input type

  • :enable_when (Hash)

    Conditions for showing the input. Must be a Hash with String :input_name (the name of the controlling input) and String :value (the value that triggers visibility). For checkbox inputs the value must be a JSON-encoded sorted array, e.g. '["a","b"]'.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/inferno/dsl/input_output_handling.rb', line 29

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>)


121
122
123
124
125
# File 'lib/inferno/dsl/input_output_handling.rb', line 121

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

  @input_order ||= []
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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/inferno/dsl/input_output_handling.rb', line 62

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