class NDFRT
Constants
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/ndfrt.rb, line 10 def initialize @nori = Nori.new(convert_tags_to: -> tag { tag.snakecase.to_sym }) end
Public Instance Methods
all_records_by_kind(kind)
click to toggle source
# File lib/ndfrt.rb, line 84 def all_records_by_kind kind kind = kind.upcase + "_KIND" query = "/allconcepts?kind=#{kind}" data = get_response_hash(query)[:group_concepts][:concept] return data.map { |i| NDFRT::Concept.new i } end
Also aliased as: all_concepts_by_kind
api_version()
click to toggle source
# File lib/ndfrt.rb, line 14 def api_version get_response_hash("/version")[:version][:version_name].to_s end
find_by(hash)
click to toggle source
# File lib/ndfrt.rb, line 43 def find_by hash return find_by_id(hash[:type], hash[:id]) if hash.has_key? :id return find_by_name(hash[:name], hash[:kind]) if hash.has_key? :name end
find_by_id(type, id)
click to toggle source
# File lib/ndfrt.rb, line 48 def find_by_id type, id type = type.upcase query = "/idType=#{type}&idString=#{id}" return get_concepts query end
find_by_name(name, kind = nil)
click to toggle source
# File lib/ndfrt.rb, line 54 def find_by_name name, kind = nil query = "/search?conceptName=#{name}" unless kind.nil? kind = kind.upcase + '_KIND' query += "&kindName=#{kind}" end return get_concepts query end
find_interacting_drugs(nui, scope = 3)
click to toggle source
# File lib/ndfrt.rb, line 63 def find_interacting_drugs nui, scope = 3 query = "/interaction/nui=#{nui}&scope=#{scope}" response = get_response_hash query data = response[:group_interactions][:interactions][:group_interacting_drugs][:interacting_drug] data = [data] unless data.is_a? Array return data.map { |i| NDFRT::Concept.new i[:concept] } end
find_interactions_between(nuis, scope = 3)
click to toggle source
# File lib/ndfrt.rb, line 71 def find_interactions_between nuis, scope = 3 query = "/interaction?nuis=#{nuis.join('+')}&scope=#{scope}" data = get_response_hash query return data[:full_interaction_group][:full_interaction].map do |fi| NDFRT::Interaction.new fi[:interaction_triple_group][:interaction_triple] end end
get_info(nui)
click to toggle source
# File lib/ndfrt.rb, line 79 def get_info nui query = "/allInfo/#{nui}" return OpenStruct.new get_response_hash(query)[:full_concept] end
possible_associations()
click to toggle source
# File lib/ndfrt.rb, line 23 def possible_associations get_options "association" end
possible_kinds()
click to toggle source
# File lib/ndfrt.rb, line 31 def possible_kinds get_options("kind").map { |k| k.split('_')[0...-1].join('_').downcase } end
possible_options_for(type)
click to toggle source
# File lib/ndfrt.rb, line 18 def possible_options_for type get_options type.to_s.downcase end
Also aliased as: available_options_for
possible_properties()
click to toggle source
# File lib/ndfrt.rb, line 35 def possible_properties get_options "property" end
possible_roles()
click to toggle source
# File lib/ndfrt.rb, line 39 def possible_roles get_options "role" end
possible_types()
click to toggle source
# File lib/ndfrt.rb, line 27 def possible_types get_options "type" end
Private Instance Methods
get_concepts(query)
click to toggle source
# File lib/ndfrt.rb, line 104 def get_concepts query response = get_response_hash query data = response[:group_concepts][:concept] data = [data] unless data.is_a?(Array) return data.map { |c| NDFRT::Concept.new(c) } end
get_options(type)
click to toggle source
# File lib/ndfrt.rb, line 99 def get_options type data = get_response_hash "/#{type}List" return data["#{type}_list".to_sym]["#{type}_name".to_sym].map { |a| a.to_s } end
get_response_hash(query)
click to toggle source
# File lib/ndfrt.rb, line 94 def get_response_hash query request = URI.parse('http://rxnav.nlm.nih.gov/REST/Ndfrt' + query) return @nori.parse(Net::HTTP.get request)[:ndfrtdata] end