class RxNav::RxNorm

Public Class Methods

available_strength(id) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 103
def available_strength id
  property id, "available_strength"
end
display_names() click to toggle source
# File lib/rx_nav/rx_norm.rb, line 107
def display_names
  query = "/displaynames"
  display_terms_list = get_response_hash(query)[:display_terms_list]
  display_terms_list ? display_terms_list[:term] : nil
end
find_drugs_by_name(name) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 36
def find_drugs_by_name name
  query = "/drugs?name=#{name}"
  drugs = []
  dg = get_response_hash(query)[:drug_group]
  return nil if dg[:concept_group].nil?
  dg[:concept_group].each do |cg|
    props = cg[:concept_properties]
    if props.nil?
      next
    else
      concepts = props.kind_of?(Array) ? props.map { |c| RxNav::Concept.new(c) } : RxNav::Concept.new(props)
      drugs << {
        name: dg[:name],
        concepts: concepts
      }
    end
  end
  return drugs
end
find_rxcui_by_id(type, id) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 24
def find_rxcui_by_id type, id
  type  = type.upcase
  id    = id.to_s
  query = "/rxcui?idtype=#{type}&id=#{id}"
  return extract_rxcui query
end
find_rxcui_by_name(name) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 31
def find_rxcui_by_name name
  query = "/rxcui?name=#{name}"
  return extract_rxcui query
end
properties(id) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 79
def properties id
  query = "/rxcui/#{id}/properties"
  return OpenStruct.new get_response_hash(query)[:properties]
end
property(id, name) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 84
def property id, name
  query    = "/rxcui/#{id}/property?propName=#{name.upcase}"
  response = get_response_hash(query)

  concept_group = response[:property_concept_group]
  return nil unless concept_group

  concepts = concept_group[:property_concept]
  return concepts ? concepts[:prop_value] : nil
end
quantity(id) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 95
def quantity id
  property id, "quantity"
end
search_by_name(name, options = {}) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 5
def search_by_name name, options = {}
  options = {max_results: 20, options: 0}.merge(options)

  query = "/approximateTerm?term=#{name}"\
          "&maxEntries=#{options[:max_results]}"\
          "&options=#{options[:options]}"

  # Get the data we care about in the right form
  data = get_response_hash(query)[:approximate_group][:candidate]

  # If we didn't get anything, say so
  return nil if data.nil?

  # Put it in the right form
  data = RxNav.ensure_array data

  return data.map { |c| RxNav::Concept.new(c) }
end
spelling_suggestions(name) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 56
def spelling_suggestions name
  query = "/spellingsuggestions?name=#{name}"
  data = get_response_hash(query)[:suggestion_group][:suggestion_list]
  data ? data[:suggestion] : nil
end
status(id) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 62
def status id
  query           = "/rxcui/#{id}/status"
  data            = get_response_hash(query)[:rxcui_status]
  status          = OpenStruct.new
  reported_status = data[:status].downcase

  status.send("remapped?=", reported_status == 'remapped')
  status.send("active?=", reported_status == 'active')

  if status.remapped?
    concepts = RxNav.ensure_array data[:min_concept_group][:min_concept]
    status.remapped_to = concepts.map { |c| c[:rxcui] }
  end

  return status
end
strength(id) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 99
def strength id
  property id, "strength"
end

Private Class Methods

extract_rxcui(query) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 119
def extract_rxcui query
  data = get_response_hash(query)
  if data[:id_group]
    data = RxNav.ensure_array data
    return data.map { |c| c[:id_group][:rxnorm_id] }
  else
    return nil
  end
end
get_response_hash(query) click to toggle source
# File lib/rx_nav/rx_norm.rb, line 115
def get_response_hash query
  RxNav.make_request(query)[:rxnormdata]
end