Class: CTG::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/ctg/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuery

Returns a new instance of Query.



43
44
45
# File 'lib/ctg/query.rb', line 43

def initialize
  @params = {}
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



41
42
43
# File 'lib/ctg/query.rb', line 41

def params
  @params
end

Instance Method Details

#advanced_filter(expression) ⇒ CTG::Query

Add an advanced filter using the Essie expression syntax

Parameters:

  • expression (String)
    • The advanced filter expression

Returns:

  • (CTG::Query)
    • The current instance for method chaining



154
155
156
157
# File 'lib/ctg/query.rb', line 154

def advanced_filter(expression)
  @params['filter.advanced'] = expression
  self
end

#condition(condition) ⇒ CTG::Query

Add a condition or disease to the query

Parameters:

  • condition (String)
    • The condition or disease to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



50
51
52
53
# File 'lib/ctg/query.rb', line 50

def condition(condition)
  @params['query.cond'] = condition
  self
end

#format(format = 'json') ⇒ CTG::Query

Set the response format (json or csv)

Parameters:

  • format (String) (defaults to: 'json')
    • The format for the response, either ‘json’ or ‘csv’

Returns:

  • (CTG::Query)
    • The current instance for method chaining



162
163
164
165
# File 'lib/ctg/query.rb', line 162

def format(format = 'json')
  @params['format'] = format
  self
end

#geo_filter(geo) ⇒ CTG::Query

Add a geographical filter based on distance

Parameters:

  • geo (String)
    • The geo-function filter (e.g., “distance(39.0035707,-77.1013313,50mi)”)

Returns:

  • (CTG::Query)
    • The current instance for method chaining



138
139
140
141
# File 'lib/ctg/query.rb', line 138

def geo_filter(geo)
  @params['filter.geo'] = geo
  self
end

#intervention(intervention) ⇒ CTG::Query

Add an intervention or treatment to the query

Parameters:

  • intervention (String)
    • The intervention or treatment to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



82
83
84
85
# File 'lib/ctg/query.rb', line 82

def intervention(intervention)
  @params['query.intr'] = intervention
  self
end

#lead_sponsor(lead_sponsor) ⇒ CTG::Query

Add a lead sponsor to the query

Parameters:

  • lead_sponsor (String)
    • The lead sponsor to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



106
107
108
109
# File 'lib/ctg/query.rb', line 106

def lead_sponsor(lead_sponsor)
  @params['query.lead'] = lead_sponsor
  self
end

#location(location) ⇒ CTG::Query

Add a location filter to the query

Parameters:

  • location (String)
    • The location term to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



66
67
68
69
# File 'lib/ctg/query.rb', line 66

def location(location)
  @params['query.locn'] = location
  self
end

#nct_ids(*ids) ⇒ CTG::Query

Add a filter for specific NCT IDs

Parameters:

  • ids (Array<String>)
    • List of NCT IDs to filter by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



146
147
148
149
# File 'lib/ctg/query.rb', line 146

def nct_ids(*ids)
  @params['filter.ids'] = ids.join('|')
  self
end

#outcome(outcome) ⇒ CTG::Query

Add an outcome measure to the query

Parameters:

  • outcome (String)
    • The outcome measure to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



90
91
92
93
# File 'lib/ctg/query.rb', line 90

def outcome(outcome)
  @params['query.outc'] = outcome
  self
end

#page_size(page_size = 1000) ⇒ CTG::Query

Set the number of results per page. If not specified or set to 0, the default value will be used. It will be coerced down to 1,000, if greater than that.

Parameters:

  • page_size (Integer) (defaults to: 1000)
    • The number of results to return per page

Returns:

  • (CTG::Query)
    • The current instance for method chaining



171
172
173
174
# File 'lib/ctg/query.rb', line 171

def page_size(page_size = 1000)
  @params['pageSize'] = page_size
  self
end

#page_token(token) ⇒ CTG::Query

Token to get next page. Set it to a nextPageToken value returned with the previous page in JSON format. For CSV, it can be found in x-next-page-token response header. Do not specify it for first page.

Returns:

  • (CTG::Query)
    • The current instance for method chaining



196
197
198
199
# File 'lib/ctg/query.rb', line 196

def page_token(token)
  @params['pageToken'] = token
  self
end

#patient(patient) ⇒ CTG::Query

Add a patient-related search to the query

Parameters:

  • patient (String)
    • The patient-related search term

Returns:

  • (CTG::Query)
    • The current instance for method chaining



122
123
124
125
# File 'lib/ctg/query.rb', line 122

def patient(patient)
  @params['query.patient'] = patient
  self
end

#sort_by(sort_by, direction = 'asc') ⇒ CTG::Query

Set the sorting order for the results

Parameters:

  • sort_by (String)
    • The field to sort by

  • direction (String) (defaults to: 'asc')
    • The direction to sort (asc or desc)

Returns:

  • (CTG::Query)
    • The current instance for method chaining



180
181
182
183
# File 'lib/ctg/query.rb', line 180

def sort_by(sort_by, direction = 'asc')
  @params['sort'] = "#{sort_by}:#{direction}"
  self
end

Add a sponsor or collaborator to the query

Parameters:

  • sponsor (String)
    • The sponsor or collaborator to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



98
99
100
101
# File 'lib/ctg/query.rb', line 98

def sponsor(sponsor)
  @params['query.spons'] = sponsor
  self
end

#status(*statuses) ⇒ CTG::Query

Adds an overall status filter to the query

Parameters:

  • statuses (Array<String>)
    • The list of statuses to filter by (e.g., [‘RECRUITING’, ‘COMPLETED’])

Returns:



130
131
132
133
# File 'lib/ctg/query.rb', line 130

def status(*statuses)
  @params['filter.overallStatus'] = statuses.join(',')
  self
end

#study_id(study_id) ⇒ CTG::Query

Adds a study ID filter to the query

Parameters:

  • study_id (String)
    • The study ID or IDs to search for (comma- or space-separated)

Returns:



114
115
116
117
# File 'lib/ctg/query.rb', line 114

def study_id(study_id)
  @params['query.id'] = study_id
  self
end

#term(term) ⇒ CTG::Query

Add a term to the query

Parameters:

  • term (String)
    • Additional term to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



58
59
60
61
# File 'lib/ctg/query.rb', line 58

def term(term)
  @params['query.term'] = term
  self
end

#title(title) ⇒ CTG::Query

Add a title or acronym to the query

Parameters:

  • title (String)
    • The title or acronym to filter studies by

Returns:

  • (CTG::Query)
    • The current instance for method chaining



74
75
76
77
# File 'lib/ctg/query.rb', line 74

def title(title)
  @params['query.titles'] = title
  self
end

#totalCTG::Query

Count total number of studies. The parameter is ignored for the subsequent pages.

Returns:

  • (CTG::Query)
    • The current instance for method chaining



187
188
189
190
# File 'lib/ctg/query.rb', line 187

def total
  @params['countTotal'] = true
  self
end