> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omophub.com/llms.txt
> Use this file to discover all available pages before exploring further.

# R SDK - Working with OMOP vocabularies

> Work with OMOP vocabularies in the OMOPHub R SDK - list, describe, and query SNOMED, ICD-10, LOINC, RxNorm, and 100+ terminologies from R scripts.

## List All Vocabularies

Get a paginated list of all available medical vocabularies:

```r theme={null}
# Basic list
result <- client$vocabularies$list()
for (vocab in result$data$vocabularies) {
  cat(sprintf("%s: %s\n", vocab$vocabulary_id, vocab$vocabulary_name))
}

# Include statistics
result <- client$vocabularies$list(include_stats = TRUE)
for (vocab in result$data$vocabularies) {
  cat(sprintf("%s: %s concepts\n", vocab$vocabulary_id, vocab$concept_count))
}

# Custom sorting and pagination
result <- client$vocabularies$list(
  sort_by = "name",
  sort_order = "asc",
  page = 1,
  page_size = 50
)
```

### Parameters

| Parameter          | Type      | Default | Description                                |
| ------------------ | --------- | ------- | ------------------------------------------ |
| `include_stats`    | logical   | FALSE   | Include vocabulary statistics              |
| `include_inactive` | logical   | FALSE   | Include inactive vocabularies              |
| `sort_by`          | character | "name"  | Sort field ("name", "priority", "updated") |
| `sort_order`       | character | "asc"   | Sort order ("asc", "desc")                 |
| `page`             | integer   | 1       | Page number                                |
| `page_size`        | integer   | 100     | Results per page (max 1000)                |

## Get Vocabulary Details

Get detailed information about a specific vocabulary:

```r theme={null}
vocab <- client$vocabularies$get("SNOMED")
cat(sprintf("Name: %s\n", vocab$data$vocabulary_name))
cat(sprintf("Version: %s\n", vocab$data$vocabulary_version))
cat(sprintf("Reference: %s\n", vocab$data$vocabulary_reference))
```

### Parameters

| Parameter       | Type      | Default  | Description                                       |
| --------------- | --------- | -------- | ------------------------------------------------- |
| `vocabulary_id` | character | required | Vocabulary identifier (e.g., "SNOMED", "ICD10CM") |

### Response Fields

Returns `vocabulary_id`, `vocabulary_name`, `vocabulary_reference`, `vocabulary_version`, `vocabulary_concept_id`.

For detailed statistics, use `client$vocabularies$stats(vocabulary_id)`.

## Get Vocabulary Statistics

Get statistical information about a vocabulary:

```r theme={null}
stats <- client$vocabularies$stats("SNOMED")
cat(sprintf("Total concepts: %d\n", stats$total_concepts))
cat(sprintf("Standard concepts: %d\n", stats$standard_concepts))
```

## Get Domain Statistics

Get statistics for a specific domain within a vocabulary:

```r theme={null}
result <- client$vocabularies$domain_stats("SNOMED", "Condition")
cat(sprintf("Total concepts: %d\n", result$data$total_concepts))
cat(sprintf("Standard concepts: %d\n", result$data$standard_concepts))

# View concept class breakdown
for (cls in result$data$concept_classes) {
  cat(sprintf("%s: %d concepts\n", cls$concept_class_id, cls$concept_count))
}
```

### Parameters

| Parameter       | Type      | Default  | Description                                                |
| --------------- | --------- | -------- | ---------------------------------------------------------- |
| `vocabulary_id` | character | required | Vocabulary identifier (e.g., "SNOMED", "ICD10CM")          |
| `domain_id`     | character | required | Domain identifier (e.g., "Condition", "Drug", "Procedure") |

## Get Vocabulary Domains

Get all standard OHDSI domains:

```r theme={null}
result <- client$vocabularies$domains()
for (domain in result$data$domains) {
  cat(sprintf("%s: %s\n", domain$domain_id, domain$domain_name))
}
```

Returns all available domains with `domain_id`, `domain_name`, and `description`.

## Get Concept Classes

Get all available concept classes:

```r theme={null}
result <- client$vocabularies$concept_classes()
for (cls in result$data) {
  cat(sprintf("%s: %s\n", cls$concept_class_id, cls$concept_class_name))
}
```

Returns concept classes with `concept_class_id`, `concept_class_name`, and `concept_class_concept_id`.

## Get Vocabulary Concepts

Retrieve concepts within a specific vocabulary with filtering and pagination:

```r theme={null}
# Basic usage
result <- client$vocabularies$concepts("SNOMED", page_size = 100)
for (concept in result$data$concepts) {
  cat(sprintf("%s (%d)\n", concept$concept_name, concept$concept_id))
}

# Search within vocabulary
result <- client$vocabularies$concepts(
  "SNOMED",
  search = "diabetes",
  standard_concept = "S",
  page_size = 50
)

# Include additional data
result <- client$vocabularies$concepts(
  "SNOMED",
  search = "hypertension",
  include_relationships = TRUE,
  include_synonyms = TRUE
)

# With sorting
result <- client$vocabularies$concepts(
  "RxNorm",
  sort_by = "concept_id",
  sort_order = "desc",
  page_size = 100
)

# Include invalid/deprecated concepts
result <- client$vocabularies$concepts(
  "ICD10CM",
  include_invalid = TRUE,
  page = 1,
  page_size = 50
)

# Pagination
cat(sprintf("Page %d of %d\n",
  result$meta$pagination$page,
  result$meta$pagination$total_pages
))
cat(sprintf("Total: %d concepts\n", result$meta$pagination$total_items))
```

### Parameters

| Parameter               | Type      | Default  | Description                                         |
| ----------------------- | --------- | -------- | --------------------------------------------------- |
| `vocabulary_id`         | character | required | Vocabulary identifier (e.g., "SNOMED", "ICD10CM")   |
| `search`                | character | NULL     | Search term to filter concepts by name or code      |
| `standard_concept`      | character | "all"    | Filter by standard concept status ("S", "C", "all") |
| `include_invalid`       | logical   | TRUE     | Include invalid or deprecated concepts              |
| `include_relationships` | logical   | FALSE    | Include concept relationships in response           |
| `include_synonyms`      | logical   | FALSE    | Include concept synonyms in response                |
| `sort_by`               | character | "name"   | Sort field ("name", "concept\_id", "concept\_code") |
| `sort_order`            | character | "asc"    | Sort order ("asc", "desc")                          |
| `page`                  | integer   | 1        | Page number                                         |
| `page_size`             | integer   | 20       | Results per page (max 1000)                         |
