Class: Clinical::Trial

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HappyMapper
Defined in:
lib/clinical/trial.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



55
56
57
# File 'lib/clinical/trial.rb', line 55

def categories
  @categories
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



54
55
56
# File 'lib/clinical/trial.rb', line 54

def keywords
  @keywords
end

#termsObject (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 extract_options!
  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)
  options = args.extract_options!

  options[:page] ||= 1
  options[:per_page] ||= 20

  query = query_hash_for(*[args, options])
  response = get("/search", :query => query)
  trials = Collection.create_from_results(options[:page], 
    options[:per_page], 
    response.body)

  if options[: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 = {}
  options = args.extract_options! || {}
  
  conditions = options[:conditions] || {}
  query["start"] = (options[:per_page] * options[:page]) - (options[: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

#conditionsObject



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_metadataObject

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

#idObject



58
59
60
# File 'lib/clinical/trial.rb', line 58

def id
  self.nct_id
end

#maximum_ageObject



74
75
76
# File 'lib/clinical/trial.rb', line 74

def maximum_age
  parsed_maximum_age == "N/A" ? nil : parsed_maximum_age
end

#minimum_ageObject



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/clinical/trial.rb', line 62

def open?
  self.status && self.status.open?
end

#outcomesObject



78
79
80
# File 'lib/clinical/trial.rb', line 78

def outcomes
  @outcomes ||= [primary_outcomes, secondary_outcomes].flatten
end

#phaseObject



94
95
96
# File 'lib/clinical/trial.rb', line 94

def phase
  self.text_phase.gsub(/phase /i, "").to_i
end

#sponsorsObject



66
67
68
# File 'lib/clinical/trial.rb', line 66

def sponsors
  @sponsors ||= [lead_sponsor, (collaborators || []), (agencies || [])].flatten
end

#statusObject



82
83
84
# File 'lib/clinical/trial.rb', line 82

def status
  self.read_status || self.overall_status
end