Sha256: 4bbf019a35c56c8bf019a9950fe1a23c3c03fdb4e2418b591416d50851db2303

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

require 'rest_client'
require 'uri'
module HealthDataStandards
  module Util
		class VSApi			
			attr_accessor :api_url, :ticket_url, :username, :password

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


			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

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

			def proxy_ticket
			 	@proxy_ticket ||= get_proxy_ticket
			end

			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
			
			def get_ticket
			  RestClient.post "#{ticket_url}/#{proxy_ticket}", {service: "http://umlsks.nlm.nih.gov"}
		  end
		end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
health-data-standards-3.1.1 lib/health-data-standards/util/vs_api.rb
health-data-standards-3.1.0 lib/health-data-standards/util/vs_api.rb