Class: HealthDataStandards::Util::VSApi

Inherits:
Object
  • Object
show all
Defined in:
lib/health-data-standards/util/vs_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticket_url, api_url, username, password) ⇒ VSApi

Returns a new instance of VSApi.



8
9
10
11
12
13
# File 'lib/health-data-standards/util/vs_api.rb', line 8

def initialize(ticket_url, api_url, username, password)
  @api_url = api_url
  @ticket_url = ticket_url
  @username = username
  @password = password
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



6
7
8
# File 'lib/health-data-standards/util/vs_api.rb', line 6

def api_url
  @api_url
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/health-data-standards/util/vs_api.rb', line 6

def password
  @password
end

#ticket_urlObject

Returns the value of attribute ticket_url.



6
7
8
# File 'lib/health-data-standards/util/vs_api.rb', line 6

def ticket_url
  @ticket_url
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/health-data-standards/util/vs_api.rb', line 6

def username
  @username
end

Instance Method Details

#get_proxy_ticketObject



35
36
37
38
39
# File 'lib/health-data-standards/util/vs_api.rb', line 35

def get_proxy_ticket
  # the content type is set and the body is a string becuase the NLM service does not support urlencoded content and
  # throws an error on that contnet type
   RestClient.post ticket_url, {username: username, password: password}
end

#get_ticketObject



41
42
43
# File 'lib/health-data-standards/util/vs_api.rb', line 41

def get_ticket
 RestClient.post "#{ticket_url}/#{proxy_ticket}", {service: "http://umlsks.nlm.nih.gov"}
end

#get_valueset(oid, effective_date = nil) {|oid, vs| ... } ⇒ Object

Yields:

  • (oid, vs)


16
17
18
19
20
21
22
# File 'lib/health-data-standards/util/vs_api.rb', line 16

def get_valueset(oid, effective_date=nil, &block)
  params = {id: oid, ticket: get_ticket}
  params[:effectiveDate] = effective_date if effective_date
  vs = RestClient.get api_url, {:params=>params}
  yield oid,vs if block_given?
  vs
end

#process_valuesets(oids, effective_date = nil, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/health-data-standards/util/vs_api.rb', line 24

def process_valuesets(oids, effective_date=nil, &block)
  oids.each do |oid|
        vs = get_valueset(oid,effective_date)
        yield oid,vs
  end
end

#proxy_ticketObject



31
32
33
# File 'lib/health-data-standards/util/vs_api.rb', line 31

def proxy_ticket
  @proxy_ticket ||= get_proxy_ticket
end