rxnorm

package
v0.1.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: 10 Imported by: 0

Documentation

Overview

Package rxnorm is the library behind the rxnorm command line: the HTTP client, request shaping, and the typed data models for the NLM RxNorm drug terminology API at rxnav.nlm.nih.gov/REST.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.

Index

Constants

View Source
const BaseURL = "https://" + Host + "/REST"

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "rxnorm-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to the NLM API. A real, honest User-Agent is both polite and less likely to get blocked.

View Source
const Host = "rxnav.nlm.nih.gov"

Host is the API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the RxNorm REST API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 15s timeout, a 300ms minimum gap between requests, and three retries on transient errors.

func (*Client) DrugProperties

func (c *Client) DrugProperties(ctx context.Context, rxcui string) (name, tty string, err error)

DrugProperties calls /rxcui/{id}/properties.json and returns the canonical name and TTY for the given RxCUI.

func (*Client) Drugs

func (c *Client) Drugs(ctx context.Context, drugName string) ([]*Drug, error)

Drugs searches for drugs by name using /drugs.json and returns one Drug record per concept in every concept group. Returns an error if nothing is found.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.

func (*Client) Interactions

func (c *Client) Interactions(ctx context.Context, names []string) ([]*Interaction, error)

Interactions resolves each name to a RxCUI, then calls /interaction/list.json to find all drug-drug interactions among them. At least 2 names must resolve; returns an error otherwise.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, drugName string) ([]*Drug, error)

Lookup resolves a drug name to one or more Drug records, fetching properties for each matching RxCUI. Returns an error if nothing is found.

func (*Client) ResolveName

func (c *Client) ResolveName(ctx context.Context, name string) ([]string, error)

ResolveName calls /rxcui.json?name={name} and returns all matching RxCUI strings. Returns an empty slice (not an error) when the API finds nothing.

type Domain

type Domain struct{}

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

func (Domain) Classify

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

Classify turns an RxCUI id or a full URL into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

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

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type Drug

type Drug struct {
	RxCUI   string `kit:"id" json:"rxcui"`
	Name    string `json:"name"`
	Type    string `json:"type"`
	Synonym string `json:"synonym,omitempty"`
}

Drug is one RxNorm drug concept: a normalized identifier, a canonical name, a type derived from the TTY code, and an optional synonym.

type Interaction

type Interaction struct {
	Drug1       string `json:"drug1"`
	Drug2       string `json:"drug2"`
	Severity    string `json:"severity"`
	Description string `json:"description"`
}

Interaction records a drug-drug interaction pair with severity and a plain-English description.

Jump to

Keyboard shortcuts

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