Class: Clinical::Trial
- Inherits:
-
Object
- Object
- Clinical::Trial
- Includes:
- AbstractElement, 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
Methods included from AbstractElement
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
56 57 58 |
# File 'lib/clinical/trial.rb', line 56 def categories @categories end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
55 56 57 |
# File 'lib/clinical/trial.rb', line 55 def keywords @keywords end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
57 58 59 |
# File 'lib/clinical/trial.rb', line 57 def terms @terms end |
Class Method Details
.extract_options! ⇒ Object
194 195 196 |
# File 'lib/clinical/trial.rb', line 194 def last.is_a?(Hash) ? pop : { } end |
.find(*args) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/clinical/trial.rb', line 140 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
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/clinical/trial.rb', line 127 def find_by_id(id) response = get("/ct2/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
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 192 |
# File 'lib/clinical/trial.rb', line 159 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) query["count"] = [:per_page] { :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
87 88 89 90 91 92 93 |
# File 'lib/clinical/trial.rb', line 87 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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/clinical/trial.rb', line 101 def response = self.class.get("/ct2/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
59 60 61 |
# File 'lib/clinical/trial.rb', line 59 def id self.nct_id end |
#maximum_age ⇒ Object
75 76 77 |
# File 'lib/clinical/trial.rb', line 75 def maximum_age parsed_maximum_age == "N/A" ? nil : parsed_maximum_age end |
#minimum_age ⇒ Object
71 72 73 |
# File 'lib/clinical/trial.rb', line 71 def minimum_age parsed_minimum_age == "N/A" ? nil : parsed_minimum_age end |
#open? ⇒ Boolean
63 64 65 |
# File 'lib/clinical/trial.rb', line 63 def open? self.status && self.status.open? end |
#outcomes ⇒ Object
79 80 81 |
# File 'lib/clinical/trial.rb', line 79 def outcomes @outcomes ||= [primary_outcomes, secondary_outcomes].flatten end |
#phase ⇒ Object
95 96 97 |
# File 'lib/clinical/trial.rb', line 95 def phase self.text_phase.gsub(/phase /i, "").to_i end |
#sponsors ⇒ Object
67 68 69 |
# File 'lib/clinical/trial.rb', line 67 def sponsors @sponsors ||= [lead_sponsor, (collaborators || []), (agencies || [])].flatten end |
#status ⇒ Object
83 84 85 |
# File 'lib/clinical/trial.rb', line 83 def status self.read_status || self.overall_status end |