class Infermedica::Api

Api defines all operations available from the REST API

Public Class Methods

new(args) click to toggle source

Create a new Infermedica::Api object. Takes a hash as argument. The api_id and api_key entries are required.

# File lib/infermedica.rb, line 144
def initialize(args)
  raise ArgumentError, 
  'Infermedica::Api::initialize argument needs to be a Hash)' unless
    args.is_a?(Hash)
  raise ArgumentError, 'api_id is required' unless args.key?(:api_id)
  raise ArgumentError, 'api_key is required' unless args.key?(:api_key)

  connection_args = { api_id: args[:api_id], api_key: args[:api_key] }
  connection_args[:endpoint] = args[:endpoint] if args.key?(:endpoint)
  @connection = Connection.new(connection_args)

  # Probably need more argument validation here...
  args.each do |k, v|
    instance_variable_set(:"@#{k}", v)
  end
end

Public Instance Methods

diagnosis(diag) click to toggle source

Submit a diagnosis object to get a diagnosis, or a list of additional conditions required to refine the diagnosis See examples/diagnosis.rb for an example

# File lib/infermedica.rb, line 104
def diagnosis(diag)
  response = @connection.post('/diagnosis', diag.to_json)
end
explain(req, args = {}) click to toggle source

Submit a diagnosis object to get an explanation See examples/explain.rb for an example

# File lib/infermedica.rb, line 116
def explain(req, args = {})
  raise Infermedica::MissingField, 'target must be set' if
    req.target.nil?
  response = @connection.post('/explain', req.to_json, args)
end
get_condition(id) click to toggle source
# File lib/infermedica.rb, line 61
def get_condition(id) # return a Condition object
  response = @connection.get("/conditions/#{id}")
  return Condition.new(response)
end
get_conditions() click to toggle source
# File lib/infermedica.rb, line 57
def get_conditions     # return a Hash of known conditions
  get_collection('/conditions')
end
get_info() click to toggle source

Get the Api info (version, date, number of conditions, lab_tests, risk_factors, symptoms

# File lib/infermedica.rb, line 96
def get_info 
  response = @connection.get("/info")
  return Info.new(response)
end
get_lab_test(id) click to toggle source
# File lib/infermedica.rb, line 70
def get_lab_test(id) # return a LabTest object
  response = @connection.get("/lab_tests/#{id}")
  return LabTest.new(response)
end
get_lab_tests() click to toggle source
# File lib/infermedica.rb, line 66
def get_lab_tests # erturn a Hash of lab_tests
  get_collection('/lab_tests')
end
get_risk_factor(id) click to toggle source
# File lib/infermedica.rb, line 79
def get_risk_factor(id) # return a RiskFactor object
  response = @connection.get("/risk_factors/#{id}")
  return RiskFactor.new(response)
end
get_risk_factors() click to toggle source
# File lib/infermedica.rb, line 75
def get_risk_factors # return a Hash of risk_factors
  get_collection('/risk_factors')
end
get_symptom(id) click to toggle source
# File lib/infermedica.rb, line 88
def get_symptom(id) # return a Symptom object
  response = @connection.get("/symptoms/#{id}")
  return Symptom.new(response)
end
get_symptoms() click to toggle source
# File lib/infermedica.rb, line 84
def get_symptoms # return a list of symptoms
  get_collection('/symptoms')
end
triage(diag) click to toggle source

Submit a diagnosis object to get a triage See examples/triage.rb for an example

# File lib/infermedica.rb, line 110
def triage(diag)
  response = @connection.post('/triage', diag.to_json)
end