rx_nav 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rx_nav.rb +5 -5
- data/lib/rx_nav/concept.rb +47 -12
- data/lib/rx_nav/ndfrt.rb +3 -2
- data/lib/rx_nav/rx_norm.rb +35 -14
- data/lib/rx_nav/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2c59070713b04541c769ff646e41b604a6bf346
|
4
|
+
data.tar.gz: 0a97e79e7f9702a0f3723be29bc44acbf61a8bef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 210aea05d43b00d1fb5187f0c03d5236dbab72ec0c53f3e66d12e19ed7f9e445422c08e2f0d9bd6c4059fca4183b9c3f2db6e982422cef38a74166e4d7271066
|
7
|
+
data.tar.gz: a064ff45a78dcccd3777933609bfd133e02a96e6ccc39d54ef3734e10bc62c57c459fc1d01123ef55075d81eeb3e1c0b6f8213466da6026631486022f7706b26
|
data/lib/rx_nav.rb
CHANGED
@@ -4,13 +4,13 @@ require 'nokogiri'
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
# Core of the API responses
|
7
|
-
|
8
|
-
|
7
|
+
require 'rx_nav/concept'
|
8
|
+
require 'rx_nav/interaction'
|
9
9
|
|
10
10
|
# Individual APIs
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
require 'rx_nav/ndfrt'
|
12
|
+
require 'rx_nav/rx_norm'
|
13
|
+
require 'rx_nav/rx_terms'
|
14
14
|
|
15
15
|
module RxNav
|
16
16
|
|
data/lib/rx_nav/concept.rb
CHANGED
@@ -16,45 +16,80 @@ module RxNav
|
|
16
16
|
kind ? titleize_kind(self.concept_kind) : nil
|
17
17
|
end
|
18
18
|
|
19
|
+
def nui
|
20
|
+
self.concept_nui
|
21
|
+
end
|
22
|
+
|
19
23
|
def to_s
|
20
24
|
name
|
21
25
|
end
|
22
26
|
|
27
|
+
# Supplementary calls to fetch info from other DBs
|
28
|
+
# Note: these methods return false if no information was found
|
29
|
+
|
23
30
|
def get_terms_info
|
31
|
+
rxcui = get_rxcui
|
32
|
+
info = RxNav::RxTerms.get_info(rxcui)
|
33
|
+
merge_concept info
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_ndfrt_info
|
37
|
+
nui = get_nui
|
38
|
+
info = RxNav::NDFRT.get_info(nui)
|
39
|
+
merge_concept info
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_norm_info
|
43
|
+
rxcui = get_rxcui
|
44
|
+
info = RxNav::RxNorm.properties rxcui
|
45
|
+
info.quantity = RxNav::RxNorm.quantity rxcui
|
46
|
+
info.strength = RxNav::RxNorm.strength rxcui
|
47
|
+
merge_concept info
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def get_rxcui
|
53
|
+
# Terms use the rxcui for the lookup
|
24
54
|
if self.rxcui.nil?
|
55
|
+
# Fail if we have a concept without any IDs (that are written so far)
|
25
56
|
if self.nui.nil?
|
26
57
|
raise "This concept doesn't have a nui or rxcui"
|
27
58
|
else
|
28
|
-
rxcui = RxNav::RxNorm.find_rxcui_by_id('nui', self.nui)
|
59
|
+
self.rxcui = RxNav::RxNorm.find_rxcui_by_id('nui', self.nui)
|
29
60
|
end
|
30
61
|
end
|
31
|
-
|
32
|
-
|
62
|
+
# If we had to look it up, use that, otherwise use the model's
|
63
|
+
return self.rxcui
|
33
64
|
end
|
34
65
|
|
35
|
-
def
|
66
|
+
def get_nui
|
36
67
|
if self.nui.nil?
|
37
68
|
if self.rxcui.nil?
|
38
69
|
raise "This concept doesn't have a nui or rxcui"
|
39
70
|
else
|
40
|
-
|
71
|
+
record = RxNav::NDFRT.find_by_id('rxcui', self.rxcui).first
|
72
|
+
self.concept_nui = record.nui
|
41
73
|
end
|
42
74
|
end
|
43
|
-
|
44
|
-
nui ? merge_concept(RxNav::NDFRT.get_info(nui)) : self
|
75
|
+
return self.nui
|
45
76
|
end
|
46
77
|
|
47
|
-
private
|
48
|
-
|
49
78
|
def titleize_kind str
|
50
79
|
str.split("_")[0...-1].map(&:capitalize).join(" ") if str.is_a? String
|
51
80
|
end
|
52
81
|
|
53
82
|
def merge_concept concept
|
54
|
-
|
55
|
-
|
56
|
-
|
83
|
+
if concept_hash.empty?
|
84
|
+
return false
|
85
|
+
else
|
86
|
+
concept_hash.each do |k,v|
|
87
|
+
puts self.k
|
88
|
+
self.k = v if self.k.nil?
|
89
|
+
puts self.k
|
90
|
+
end
|
57
91
|
end
|
92
|
+
return self
|
58
93
|
end
|
59
94
|
|
60
95
|
end
|
data/lib/rx_nav/ndfrt.rb
CHANGED
@@ -94,8 +94,9 @@ module RxNav
|
|
94
94
|
def get_concepts query
|
95
95
|
data = get_response_hash(query)[:group_concepts]
|
96
96
|
if data && data[:concept]
|
97
|
-
|
98
|
-
|
97
|
+
concepts = data[:concept]
|
98
|
+
concepts = [concepts] unless concepts.is_a?(Array)
|
99
|
+
return concepts.map { |c| RxNav::Concept.new(c) }
|
99
100
|
else
|
100
101
|
return nil
|
101
102
|
end
|
data/lib/rx_nav/rx_norm.rb
CHANGED
@@ -5,7 +5,9 @@ module RxNav
|
|
5
5
|
def search_by_name name, options = {}
|
6
6
|
options = {max_results: 20, options: 0}.merge(options)
|
7
7
|
|
8
|
-
query =
|
8
|
+
query = "/approximateTerm?term=#{name}"\
|
9
|
+
"&maxEntries=#{options[:max_results]}"\
|
10
|
+
"&options=#{options[:options]}"
|
9
11
|
|
10
12
|
# Get the data we care about in the right form
|
11
13
|
data = get_response_hash(query)[:approximate_group][:candidate]
|
@@ -29,15 +31,39 @@ module RxNav
|
|
29
31
|
return extract_rxcui query
|
30
32
|
end
|
31
33
|
|
34
|
+
def find_drugs_by_name name
|
35
|
+
query = "/drugs?name=#{name}"
|
36
|
+
drugs = []
|
37
|
+
dg = get_response_hash(query)[:drug_group]
|
38
|
+
dg[:concept_group].each do |cg|
|
39
|
+
drugs << {
|
40
|
+
name: dg[:name],
|
41
|
+
concepts: cg[:concept_properties].map { |c| RxNav::Concept.new(c) }
|
42
|
+
}
|
43
|
+
end
|
44
|
+
return drugs
|
45
|
+
end
|
46
|
+
|
32
47
|
def spelling_suggestions name
|
33
48
|
query = "/spellingsuggestions?name=#{name}"
|
34
49
|
get_response_hash(query)[:suggestion_group][:suggestion_list][:suggestion]
|
35
50
|
end
|
36
51
|
|
37
52
|
def status id
|
38
|
-
query
|
39
|
-
|
40
|
-
status
|
53
|
+
query = "/rxcui/#{id}/status"
|
54
|
+
data = get_response_hash(query)[:rxcui_status]
|
55
|
+
status = OpenStruct.new
|
56
|
+
reported_status = data[:status].downcase
|
57
|
+
|
58
|
+
status.send("remapped?=", reported_status == 'remapped')
|
59
|
+
status.send("active?=", reported_status == 'active')
|
60
|
+
|
61
|
+
if status.remapped?
|
62
|
+
concepts = data[:min_concept_group][:min_concept]
|
63
|
+
concepts = [concepts] if (concepts && !concepts.is_a?(Array))
|
64
|
+
status.remapped_to = concepts.map { |c| c[:rxcui] }
|
65
|
+
end
|
66
|
+
|
41
67
|
return status
|
42
68
|
end
|
43
69
|
|
@@ -48,19 +74,12 @@ module RxNav
|
|
48
74
|
|
49
75
|
def quantity id
|
50
76
|
query = "/rxcui/#{id}/quantity"
|
51
|
-
return
|
77
|
+
return get_response_hash(query)[:quantity_group][:quantity]
|
52
78
|
end
|
53
79
|
|
54
80
|
def strength id
|
55
81
|
query = "/rxcui/#{id}/strength"
|
56
|
-
return
|
57
|
-
end
|
58
|
-
|
59
|
-
def complete_info id
|
60
|
-
result = self.properties(id)
|
61
|
-
result.strength = self.strength(id).strength
|
62
|
-
result.quantity = self.quantity(id).quantity
|
63
|
-
return result
|
82
|
+
return get_response_hash(query)[:strength_group][:strength]
|
64
83
|
end
|
65
84
|
|
66
85
|
private
|
@@ -78,7 +97,9 @@ module RxNav
|
|
78
97
|
return nil
|
79
98
|
end
|
80
99
|
end
|
81
|
-
|
82
100
|
end
|
101
|
+
|
102
|
+
self.singleton_class.send(:alias_method, :find_by_name, :search_by_name)
|
103
|
+
|
83
104
|
end
|
84
105
|
end
|
data/lib/rx_nav/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rx_nav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bender
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nori
|