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



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

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



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

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

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

Yields:

  • (oid, vs)


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

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

#process_valuesets(oids, &block) ⇒ Object



21
22
23
24
25
26
# File 'lib/health-data-standards/util/vs_api.rb', line 21

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

#proxy_ticketObject



28
29
30
# File 'lib/health-data-standards/util/vs_api.rb', line 28

def proxy_ticket
 	@proxy_ticket ||= get_proxy_ticket
end