clinicaltrials

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package clinicaltrials is the library behind the clinicaltrials command: the HTTP client, request shaping, and the typed data models for the ClinicalTrials.gov REST API v2.

The public API at https://clinicaltrials.gov/api/v2 is fully open — no API key, no authentication required. The client sets a real User-Agent, paces requests at 500 ms by default, and retries 429/5xx with exponential backoff.

Index

Constants

View Source
const DefaultUserAgent = "clinicaltrials/dev (+https://github.com/tamnd/clinicaltrials-cli)"

DefaultUserAgent identifies the client to ClinicalTrials.gov.

View Source
const Host = "clinicaltrials.gov"

Host is the ClinicalTrials.gov hostname.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the API returns a 404 for an NCT ID.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the ClinicalTrials.gov REST API v2.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) GetStudy added in v0.2.0

func (c *Client) GetStudy(ctx context.Context, nctID string) (*Study, error)

GetStudy returns a single study by NCT ID.

func (*Client) Search

func (c *Client) Search(ctx context.Context, condition, intervention, term, status string, limit int) ([]Study, error)

Search returns studies matching condition, intervention, term, and/or status. limit 0 uses the default of 10.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds constructor parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain added in v0.2.0

type Domain struct{}

Domain is the ClinicalTrials.gov driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify added in v0.2.0

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (uriType, id). NCT IDs (8+ chars starting with NCT) → ("nctid", id); otherwise → ("query", input).

func (Domain) Info added in v0.2.0

func (Domain) Info() kit.DomainInfo

Info describes the scheme and the identity the single-site binary inherits.

func (Domain) Locate added in v0.2.0

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the canonical ClinicalTrials.gov URL for a (uriType, id).

func (Domain) Register added in v0.2.0

func (Domain) Register(app *kit.App)

Register installs the client factory and operations onto app.

type Study added in v0.2.0

type Study struct {
	NCTID          string   `kit:"id" json:"nct_id"`
	BriefTitle     string   `json:"brief_title"`
	OfficialTitle  string   `json:"official_title"`
	OverallStatus  string   `json:"overall_status"`
	Phase          string   `json:"phase"`
	StudyType      string   `json:"study_type"`
	Enrollment     int      `json:"enrollment"`
	StartDate      string   `json:"start_date"`
	CompletionDate string   `json:"completion_date"`
	LeadSponsor    string   `json:"lead_sponsor"`
	Conditions     []string `json:"conditions"`
	BriefSummary   string   `json:"brief_summary"`
}

Study is the record emitted for search and study operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL