Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
CTG
is a Ruby client library for interacting with the ClinicalTrials.gov API. It allows you to fetch and query clinical study data, including study metadata, search areas, study sizes, field values, and more. The library supports both JSON and CSV response formats, with built-in support for pagination and advanced querying.
Add this line to your application's Gemfile:
gem 'ctg'
And then execute:
bundle install
Or install it yourself as:
gem install ctg
To start using the CTG
, first create a new client instance:
require 'ctg'
client = CTG.new
You can fetch studies using the studies
method. This will return a CTG::Response
object that you can query.
response = client.studies('query.term' => 'cancer')
studies = response.query('studies')
puts studies
You can fetch a single study by its NCT number:
response = client.number('NCT04050163')
study = response.query('nctId')
puts study
To fetch metadata information about study fields:
response = client.metadata
metadata = response.data
puts metadata
If your query returns multiple pages of results, you can fetch the next page using the next_page
method:
response = client.studies('query.term' => 'cancer', 'pageSize' => 5)
puts response.query('studies')
next_page_response = response.next_page
puts next_page_response.query('studies') if next_page_response
You can query JSON responses using keys or XPath expressions:
response = client.number('NCT04050163')
nct_id = response.query('nctId')
puts nct_id # Outputs 'NCT04050163'
For CSV responses, query by column name:
response = client.number('NCT04050163', format: 'csv')
nct_ids = response.query('NCT Number')
puts nct_ids
You can find the first occurrence of a specific key within the JSON data using the find
method:
response = client.number('NCT04050163')
nct_id = response.find('nctId')
puts nct_id # Outputs 'NCT04050163'
The CTG::Query
class is designed to help you build complex queries for searching clinical studies on ClinicalTrials.gov. It provides a convenient way to add different query parameters and filters, allowing for advanced search capabilities.
To start building a query, you first need to create an instance of the CTG::Query
class:
query = CTG::Query.new
The CTG::Query
object allows you to add various search parameters using method chaining. Below are the available methods:
condition(condition)
Adds a condition or disease to the query.
condition
(String) - The condition or disease to search for.CTG::Query
object.query = CTG::Query.new.condition('diabetes')
term(term)
Adds additional search terms to the query.
term
(String) - Additional search terms.CTG::Query
object.query = CTG::Query.new.term('lung cancer')
location(location)
Adds a location filter to the query.
location
(String) - The location term to filter results by.CTG::Query
object.query = CTG::Query.new.location('New York')
title(title)
Adds a title or acronym to the query.
title
(String) - The title or acronym to search for.CTG::Query
object.query = CTG::Query.new.title('COVID-19 Vaccine')
intervention(intervention)
Adds an intervention or treatment to the query.
intervention
(String) - The intervention or treatment to search for.CTG::Query
object.query = CTG::Query.new.intervention('remdesivir')
outcome(outcome)
Adds an outcome measure to the query.
outcome
(String) - The outcome measure to search for.CTG::Query
object.query = CTG::Query.new.outcome('survival rate')
collaborator(collaborator)
Adds a sponsor or collaborator to the query.
collaborator
(String) - The sponsor or collaborator to search for.CTG::Query
object.query = CTG::Query.new.collaborator('IQVIA')
sponsor(lead_sponsor)
Adds a lead sponsor to the query.
sponsor
(String) - The lead sponsor to search for.CTG::Query
object.query = CTG::Query.new.sponsor('National Institutes of Health')
study_id(study_id)
Adds a study ID filter to the query.
study_id
(String) - The study ID or IDs to search for (comma- or space-separated).CTG::Query
object.query = CTG::Query.new.study_id('NCT01234567')
status(*statuses)
Adds an overall status filter to the query.
statuses
(Array) - The list of statuses to filter by (e.g., ['RECRUITING', 'COMPLETED']
).CTG::Query
object.query = CTG::Query.new.status('RECRUITING', 'COMPLETED')
page_size(size)
Specifies the number of results per page.
size
(Integer) - The number of results to return per page (max 1000).CTG::Query
object.query = CTG::Query.new.page_size(50)
format(format)
Specifies the format of the response.
format
(String) - The format of the response ('json'
or 'csv'
).CTG::Query
object.query = CTG::Query.new.format('json')
Once you’ve built your query, you can retrieve the complete set of query parameters as a hash:
query_params = query.params
This params
method returns a hash of all the query parameters that have been set.
Here’s an example of how you might build a more complex query using method chaining:
query = CTG::Query.new
.condition('diabetes')
.term('insulin')
.location('California')
.status('RECRUITING')
.page_size(10)
.format('json')
# Use the query in a client request
response = client.studies(query)
puts response.query('studies', 'protocolSection', 'outcomesModule', 'secondaryOutcomes' )
In this example, the query is set to search for recruiting studies related to diabetes and insulin in California, returning results in JSON format with a page size of 10.
If you need to find all occurrences of a specific key within the JSON data, use the find_all
method:
references = response.find_all('references')
puts references
To run the tests, use RSpec:
rspec
This will run all the tests located in the spec/
directory and report on their success.
Bug reports and pull requests are welcome on GitHub at https://github.com/trialize/ctg.
This library is available as open source under the terms of the MIT License. Copyright 2024 Leonid Stoianov. Copyright 2024 Trialize.
FAQs
Unknown package
We found that ctg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.