Learn R Programming

OMOPHub R SDK

Query millions of standardized medical concepts from R

Access SNOMED CT, ICD-10, RxNorm, LOINC, and 90+ OHDSI ATHENA vocabularies without downloading, installing, or maintaining local databases.

Documentation · API Reference · Examples


Why OMOPHub?

Working with OHDSI ATHENA vocabularies traditionally requires downloading multi-gigabyte files, setting up a database, and writing complex SQL queries. OMOPHub eliminates this friction.

Traditional ApproachWith OMOPHub
Download 5GB+ ATHENA vocabulary filesinstall.packages("omophub")
Set up and maintain database instanceOne API call
Write complex SQL with multiple JOINsSimple R functions
Manually update vocabularies quarterlyAlways current data
Local infrastructure requiredWorks anywhere R runs

Installation

# Install from CRAN
install.packages("omophub")

# Or install development version from GitHub
# install.packages("pak")
pak::pak("omopHub/omophub-R")

Authentication

library(omophub)

# Option 1: Environment variable (recommended)
Sys.setenv(OMOPHUB_API_KEY = "oh_xxxxxxxxx")

# Option 2: Use helper function
set_api_key("oh_xxxxxxxxx")

# Option 3: Store securely in system keyring
set_api_key("oh_xxxxxxxxx", store = "keyring")

Get your API key from the OMOPHub Dashboard.

Quick Start

library(omophub)

# Create client
client <- OMOPHubClient$new()

# Get a concept by ID
concept <- client$concepts$get(201826)
concept$concept_name
# [1] "Type 2 diabetes mellitus"

# Search for concepts
results <- client$search$basic("metformin", vocabulary_ids = "RxNorm")
results$data

# Get concept by vocabulary code
snomed_concept <- client$concepts$get_by_code("SNOMED", "44054006")

# Map to another vocabulary
mappings <- client$mappings$get(201826, target_vocabulary = "ICD10CM")

# Navigate hierarchy
ancestors <- client$hierarchy$ancestors(201826, max_levels = 3)

Semantic Search

Use natural language queries to find concepts using neural embeddings:

# Natural language search - understands clinical intent
results <- client$search$semantic("high blood sugar levels")
for (r in results$data$results) {
  cat(sprintf("%s (similarity: %.2f)\n", r$concept_name, r$similarity_score))
}

# Filter by vocabulary and set minimum similarity threshold
results <- client$search$semantic(
  "heart attack",
  vocabulary_ids = "SNOMED",
  domain_ids = "Condition",
  threshold = 0.5
)

# Fetch all results with auto-pagination
all_results <- client$search$semantic_all("chronic kidney disease", page_size = 50)

# Find concepts similar to a reference concept
similar <- client$search$similar(concept_id = 201826, algorithm = "hybrid")
for (s in similar$similar_concepts) {
  cat(sprintf("%s (score: %.2f)\n", s$concept_name, s$similarity_score))
}

Use Cases

ETL & Data Pipelines

Validate and map clinical codes during OMOP CDM transformations:

# Validate source codes and find standard equivalents
validate_and_map <- function(source_vocab, source_code) {
  concept <- client$concepts$get_by_code(source_vocab, source_code)
  
  if (concept$standard_concept != "S") {
    mappings <- client$mappings$get(
      concept$concept_id,
      target_vocabulary = "SNOMED"
    )
    return(mappings$mappings[[1]]$target_concept_id)
  }
  
  concept$concept_id
}

# Example: Map ICD-10 to SNOMED
standard_id <- validate_and_map("ICD10CM", "E11.9")

Data Quality Checks

Verify codes exist and are valid:

# Check if condition codes are valid
condition_codes <- c("E11.9", "I10", "J44.9")

for (code in condition_codes) {
  tryCatch({
    concept <- client$concepts$get_by_code("ICD10CM", code)
    message(sprintf("OK %s: %s", code, concept$concept_name))
  }, omophub_api_error = function(e) {
    message(sprintf("ERROR %s: Invalid code!", code))
  })
}

Phenotype Development

Explore hierarchies to build comprehensive concept sets:

# Get all descendants for phenotype definition
descendants <- client$hierarchy$descendants(
  201826,  # Type 2 diabetes mellitus
  max_levels = 5
)

concept_set <- sapply(descendants$concepts, function(x) x$concept_id)
message(sprintf("Found %d concepts for T2DM phenotype", length(concept_set)))

Integration with tidyverse

library(dplyr)
library(purrr)

# Search and convert to tibble
results <- client$search$basic("hypertension", page_size = 100)

concepts_df <- results$data %>%
  map_dfr(~ tibble(
    concept_id = .x$concept_id,
    concept_name = .x$concept_name,
    vocabulary_id = .x$vocabulary_id,
    domain_id = .x$domain_id
  ))

# Filter and analyze
concepts_df %>%
  filter(vocabulary_id == "SNOMED") %>%
  count(domain_id)

API Resources

ResourceDescriptionKey Methods
conceptsConcept lookup and batch operationsget(), get_by_code(), batch(), suggest()
searchFull-text and semantic searchbasic(), advanced(), semantic(), semantic_all(), similar(), basic_all()
hierarchyNavigate concept relationshipsancestors(), descendants()
mappingsCross-vocabulary mappingsget(), map()
vocabulariesVocabulary metadatalist(), get(), stats()
domainsDomain informationlist(), get(), concepts()

Pagination

# Automatic pagination - fetch all results
all_results <- client$search$basic_all("diabetes", page_size = 100)

# Manual pagination
page1 <- client$search$basic("diabetes", page = 1, page_size = 20)
page2 <- client$search$basic("diabetes", page = 2, page_size = 20)

Configuration

# Specify vocabulary version
client <- OMOPHubClient$new(vocab_version = "2025.2")

# Custom configuration
client <- OMOPHubClient$new(
  api_key = "oh_xxx",
  base_url = "https://api.omophub.com/v1",
  timeout = 30
)

Error Handling

tryCatch({
  result <- client$concepts$get(999999999)
}, omophub_not_found_error = function(e) {
  message("Concept not found: ", conditionMessage(e))
}, omophub_auth_error = function(e) {
  message("Check your API key")
}, omophub_rate_limit_error = function(e) {
  message("Rate limited, please wait")
}, omophub_api_error = function(e) {
  message("API error: ", conditionMessage(e))
})

Compared to Alternatives

FeatureOMOPHub SDKATHENA DownloadOHDSI WebAPI
Setup time1 minuteHoursHours
InfrastructureNonePostgreSQL requiredFull OHDSI stack
UpdatesAutomaticManual downloadManual
Programmatic accessNative RSQL/DatabaseConnectorREST API

Best for: R users who need quick, programmatic access to OMOP vocabularies without infrastructure overhead.

Examples

The package includes comprehensive examples in inst/examples/:

ExampleDescription
basic_usage.RGetting started - client setup, concept lookup, search
search_concepts.RSearch capabilities - filters, autocomplete, pagination
navigate_hierarchy.RHierarchy navigation - ancestors, descendants
map_between_vocabularies.RCross-vocabulary mapping
error_handling.RError handling patterns

Run an example:

example_path <- system.file("examples", "basic_usage.R", package = "omophub")
source(example_path)

Documentation

Contributing

We welcome contributions!

# Clone and install for development
# install.packages("devtools")
devtools::install_github("omopHub/omophub-R")

# Run tests
devtools::test()

# Check package
devtools::check()

Support

License

MIT License - see LICENSE for details.


Built for the OHDSI community

Copy Link

Version

Install

install.packages('omophub')

Version

1.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Alex Chen

Last Published

February 23rd, 2026

Functions in omophub (1.4.0)

abort_auth_error

Abort with Authentication Error
SearchResource

Search Resource
OMOPHubClient

OMOPHub API Client
ConceptsResource

Concepts Resource
RelationshipsResource

Relationships Resource
bool_to_str

Convert Boolean to API String
build_request

Build Base OMOPHub Request
VocabulariesResource

Vocabularies Resource
has_api_key

Check if API Key is Available
get_api_key

Get OMOPHub API Key
new_omophub_mappings

Create OMOPHub Mappings Result
new_omophub_relationships

Create OMOPHub Relationships Result
DomainsResource

Domains Resource
abort_rate_limit

Abort with Rate Limit Error
new_omophub_concepts

Create OMOPHub Concepts Result
paginate_all

Fetch All Paginated Results
set_api_key

Set OMOPHub API Key
abort_validation

Abort with Validation Error
paginate_lazy

Create Lazy Pagination Iterator
validate_pagination

Validate Page Parameters
new_omophub_hierarchy

Create OMOPHub Hierarchy Result
HierarchyResource

Hierarchy Resource
MappingsResource

Mappings Resource
.onAttach

Package Attach Hook
validate_concept_id

Validate Concept ID
.onLoad

Package Load Hook
omophub-package

omophub: R Client for the 'OMOPHub' Medical Vocabulary API
is_transient_error

Check if Error is Transient (Retryable)
new_omophub_vocabularies

Create OMOPHub Vocabularies Result
extract_pagination

Extract Pagination Metadata
extract_error_message

Extract Error Message from API Response
join_params

Join List Elements for Query Parameter
perform_post

Perform POST Request
perform_get

Perform GET Request
abort_api_error

Abort with OMOPHub API Error