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
- #open? ⇒ Boolean
- #outcomes ⇒ Object
- #phase ⇒ Object
- #sponsors ⇒ Object
- #status ⇒ Object
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
54 55 56 |
# File 'lib/clinical/trial.rb', line 54 def categories @categories end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
53 54 55 |
# File 'lib/clinical/trial.rb', line 53 def keywords @keywords end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
55 56 57 |
# File 'lib/clinical/trial.rb', line 55 def terms @terms end |
Class Method Details
.extract_options! ⇒ Object
185 186 187 |
# File 'lib/clinical/trial.rb', line 185 def last.is_a?(Hash) ? pop : { } end |
.find(*args) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/clinical/trial.rb', line 131 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
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/clinical/trial.rb', line 118 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
150 151 152 153 154 155 156 157 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 |
# File 'lib/clinical/trial.rb', line 150 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
77 78 79 80 81 82 83 |
# File 'lib/clinical/trial.rb', line 77 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/clinical/trial.rb', line 91 def response = self.class.get("/show/#{id}", :query => {:displayxml => false}) html = Nokogiri::HTML(response.body) = {} { :terms => 0, :categories => 1, :keywords => 2 }.each do |key, value| [key] = [] html.search("div.indent3:nth-last-child(#{value}) td").each do |td| word = td.inner_html.split(/\<br\>/).collect{|i| i.gsub(/\<div.*/, "").strip.chomp} if word != "" [key] += word end end end @terms, @categories, @keywords = [:terms], [:categories], [:keywords] end |
#id ⇒ Object
57 58 59 |
# File 'lib/clinical/trial.rb', line 57 def id self.nct_id end |
#open? ⇒ Boolean
61 62 63 |
# File 'lib/clinical/trial.rb', line 61 def open? self.status && self.status.open? end |
#outcomes ⇒ Object
69 70 71 |
# File 'lib/clinical/trial.rb', line 69 def outcomes @outcomes ||= [primary_outcomes, secondary_outcomes].flatten end |
#phase ⇒ Object
85 86 87 |
# File 'lib/clinical/trial.rb', line 85 def phase self.text_phase.gsub(/phase /i, "").to_i end |
#sponsors ⇒ Object
65 66 67 |
# File 'lib/clinical/trial.rb', line 65 def sponsors @sponsors ||= [lead_sponsor, (collaborators || []), (agencies || [])].flatten end |
#status ⇒ Object
73 74 75 |
# File 'lib/clinical/trial.rb', line 73 def status self.read_status || self.overall_status end |