Class: RxNav::RxNorm
- Inherits:
-
Object
- Object
- RxNav::RxNorm
- Defined in:
- lib/rx_nav/rx_norm.rb
Class Method Summary collapse
- .available_strength(id) ⇒ Object
- .display_names ⇒ Object
- .find_drugs_by_name(name) ⇒ Object
- .find_rxcui_by_id(type, id) ⇒ Object
- .find_rxcui_by_name(name) ⇒ Object
- .properties(id) ⇒ Object
- .property(id, name) ⇒ Object
- .quantity(id) ⇒ Object
- .search_by_name(name, options = {}) ⇒ Object
- .spelling_suggestions(name) ⇒ Object
- .status(id) ⇒ Object
- .strength(id) ⇒ Object
Class Method Details
.available_strength(id) ⇒ Object
103 104 105 |
# File 'lib/rx_nav/rx_norm.rb', line 103 def available_strength id property id, "available_strength" end |
.display_names ⇒ Object
107 108 109 110 111 |
# 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) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
24 25 26 27 28 29 |
# 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) ⇒ Object
31 32 33 34 |
# 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) ⇒ Object
79 80 81 82 |
# 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) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
95 96 97 |
# File 'lib/rx_nav/rx_norm.rb', line 95 def quantity id property id, "quantity" end |
.search_by_name(name, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rx_nav/rx_norm.rb', line 5 def search_by_name name, = {} = {max_results: 20, options: 0}.merge() query = "/approximateTerm?term=#{name}"\ "&maxEntries=#{[:max_results]}"\ "&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) ⇒ Object
56 57 58 59 60 |
# 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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) ⇒ Object
99 100 101 |
# File 'lib/rx_nav/rx_norm.rb', line 99 def strength id property id, "strength" end |