Class: Clinical::Trial
- Inherits:
-
Object
- Object
- Clinical::Trial
- Includes:
- HTTParty, HappyMapper
- Defined in:
- lib/clinical/trial.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Class Method Summary collapse
- .extract_options! ⇒ Object
- .find(*args) ⇒ Object
- .find_by_id(id) ⇒ Object
- .query_hash_for(*args) ⇒ Object
Instance Method Summary collapse
- #conditions ⇒ Object
-
#get_metadata ⇒ Object
this metadata is not accessible in the feed so crawl the html page to get keywords, categories, and terms.
- #id ⇒ Object
- #maximum_age ⇒ Object
- #minimum_age ⇒ Object
- #open? ⇒ Boolean
- #outcomes ⇒ Object
- #phase ⇒ Object
- #sponsors ⇒ Object
- #status ⇒ Object
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
55 56 57 |
# File 'lib/clinical/trial.rb', line 55 def categories @categories end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
54 55 56 |
# File 'lib/clinical/trial.rb', line 54 def keywords @keywords end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
56 57 58 |
# File 'lib/clinical/trial.rb', line 56 def terms @terms end |
Class Method Details
.extract_options! ⇒ Object
193 194 195 |
# File 'lib/clinical/trial.rb', line 193 def last.is_a?(Hash) ? pop : { } end |
.find(*args) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/clinical/trial.rb', line 139 def find(*args) = args. [:page] ||= 1 [:per_page] ||= 20 query = query_hash_for(*[args, ]) response = get("/search", :query => query) trials = Collection.create_from_results([:page], [:per_page], response.body) if [:extended] fetch_more_details(trials) else trials end end |
.find_by_id(id) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/clinical/trial.rb', line 126 def find_by_id(id) response = get("/show/#{id}") if response.code == 400 nil else begin parse(response.body) rescue LibXML::XML::Error return nil end end end |
.query_hash_for(*args) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/clinical/trial.rb', line 158 def query_hash_for(*args) query = {} = args. || {} conditions = [:conditions] || {} query["start"] = ([:per_page] * [:page]) - ([:per_page] - 1) unless conditions[:recruiting].nil? query["recr"] = conditions[:recruiting] ? "open" : "closed" end query["term"] = args.first if args.first.is_a?(String) { :condition => "cond", :sponsor => "spons", :intervention => "intr", :outcome => "outc", :sponsor => "spons" }.each do |key,value| query[value] = conditions[key] unless conditions[key].nil? end unless conditions[:updated_at].nil? unless conditions[:updated_at].is_a?(Array) conditions[:updated_at] = [conditions[:updated_at]] end query["lup_s"] = conditions[:updated_at][0].strftime("%m/%d/%Y") if conditions[:updated_at].size == 2 query["lup_e"] = conditions[:updated_at][1].strftime("%m/%d/%Y") end end query end |
Instance Method Details
#conditions ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/clinical/trial.rb', line 86 def conditions if condition_items.nil? || condition_items.empty? condition_summary.nil? ? nil : condition_summary.split(";") else condition_items end end |
#get_metadata ⇒ Object
this metadata is not accessible in the feed so crawl the html page to get keywords, categories, and terms
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/clinical/trial.rb', line 100 def response = self.class.get("/show/#{id}", :query => {:displayxml => false}) html = Nokogiri::HTML(response.body) = {} { :terms => 0, :keywords => 1 }.each do |key, value| [key] = [] html.search("div.indent3:nth-last-child(#{value}) td").each do |td| words = td.inner_html.split(/\<br\/?\>/).collect{|i| i.gsub(/\<div.*/, "").strip.chomp} if !words.empty? [key] += words end [key] end end @terms, @categories, @keywords = [:terms], [:categories], [:keywords] end |
#id ⇒ Object
58 59 60 |
# File 'lib/clinical/trial.rb', line 58 def id self.nct_id end |
#maximum_age ⇒ Object
74 75 76 |
# File 'lib/clinical/trial.rb', line 74 def maximum_age parsed_maximum_age == "N/A" ? nil : parsed_maximum_age end |
#minimum_age ⇒ Object
70 71 72 |
# File 'lib/clinical/trial.rb', line 70 def minimum_age parsed_minimum_age == "N/A" ? nil : parsed_minimum_age end |
#open? ⇒ Boolean
62 63 64 |
# File 'lib/clinical/trial.rb', line 62 def open? self.status && self.status.open? end |
#outcomes ⇒ Object
78 79 80 |
# File 'lib/clinical/trial.rb', line 78 def outcomes @outcomes ||= [primary_outcomes, secondary_outcomes].flatten end |
#phase ⇒ Object
94 95 96 |
# File 'lib/clinical/trial.rb', line 94 def phase self.text_phase.gsub(/phase /i, "").to_i end |
#sponsors ⇒ Object
66 67 68 |
# File 'lib/clinical/trial.rb', line 66 def sponsors @sponsors ||= [lead_sponsor, (collaborators || []), (agencies || [])].flatten end |
#status ⇒ Object
82 83 84 |
# File 'lib/clinical/trial.rb', line 82 def status self.read_status || self.overall_status end |