Skip to content

Commit 95dd223

Browse files
author
alex-omophub
committed
Update LICENSE and README files to reflect copyright and add comprehensive examples
1 parent a1a4864 commit 95dd223

16 files changed

Lines changed: 3263 additions & 2 deletions

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) 2025 OMOPHub Team
3+
Copyright (c) 2025 OMOPHub
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,30 @@ tryCatch(
115115
)
116116
```
117117

118+
## Examples
119+
120+
The package includes comprehensive examples in `inst/examples/`:
121+
122+
| Example | Description |
123+
|---------|-------------|
124+
| [`basic_usage.R`](inst/examples/basic_usage.R) | Getting started - client setup, concept lookup, search |
125+
| [`search_concepts.R`](inst/examples/search_concepts.R) | Search capabilities - filters, autocomplete, pagination |
126+
| [`navigate_hierarchy.R`](inst/examples/navigate_hierarchy.R) | Hierarchy navigation - ancestors, descendants, relationships |
127+
| [`map_between_vocabularies.R`](inst/examples/map_between_vocabularies.R) | Vocabulary mapping - ICD-10, SNOMED, batch mapping |
128+
| [`error_handling.R`](inst/examples/error_handling.R) | Error handling patterns - tryCatch, retry logic |
129+
130+
Run an example:
131+
```r
132+
# After installing the package
133+
example_path <- system.file("examples", "basic_usage.R", package = "omophub")
134+
source(example_path)
135+
```
118136

119137
## Documentation
120138

121139
- [Full Documentation](https://docs.omophub.com/sdks/r/overview)
122140
- [API Reference](https://docs.omophub.com/api-reference)
123-
- [Examples](https://github.com/omopHub/omophub-r/tree/main/examples)
141+
- [Examples](https://github.com/omopHub/omophub-r/tree/main/inst/examples)
124142

125143
## License
126144

inst/examples/basic_usage.R

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env Rscript
2+
#' Example: Basic Usage
3+
#'
4+
#' Demonstrates basic OMOPHub client usage including:
5+
#' - Client initialization
6+
#' - Getting a single concept
7+
#' - Basic search
8+
#' - Listing vocabularies
9+
#'
10+
#' Run with: Rscript inst/examples/basic_usage.R
11+
12+
library(omophub)
13+
14+
# ============================================================================
15+
# Setup
16+
# ============================================================================
17+
18+
# Initialize client (uses OMOPHUB_API_KEY environment variable)
19+
# You can also pass the API key directly:
20+
# client <- omophub(api_key = "oh_your_api_key")
21+
client <- omophub()
22+
23+
cat("OMOPHub R Client - Basic Usage Example\n")
24+
cat("======================================\n\n")
25+
26+
# ============================================================================
27+
# Get a Single Concept
28+
# ============================================================================
29+
30+
cat("1. Getting a single concept by ID\n")
31+
cat("---------------------------------\n")
32+
33+
# Get Type 2 diabetes mellitus (SNOMED concept)
34+
concept <- client$concepts$get(201826)
35+
36+
cat("Concept ID:", concept$concept_id, "\n")
37+
cat("Name:", concept$concept_name, "\n")
38+
cat("Vocabulary:", concept$vocabulary_id, "\n")
39+
cat("Domain:", concept$domain_id, "\n")
40+
cat("Concept Class:", concept$concept_class_id, "\n")
41+
cat("Concept Code:", concept$concept_code, "\n")
42+
cat("Standard Concept:", concept$standard_concept, "\n\n")
43+
44+
# ============================================================================
45+
# Basic Search
46+
# ============================================================================
47+
48+
cat("2. Searching for concepts\n")
49+
cat("-------------------------\n")
50+
51+
# Search for diabetes-related concepts
52+
results <- client$search$basic("diabetes", page_size = 5)
53+
54+
cat("Found concepts matching 'diabetes':\n")
55+
concepts <- results$data %||% results$concepts %||% results
56+
for (c in concepts) {
57+
cat(sprintf(" [%s] %s (%s)\n",
58+
c$concept_id,
59+
c$concept_name,
60+
c$vocabulary_id))
61+
}
62+
cat("\n")
63+
64+
# ============================================================================
65+
# List Vocabularies
66+
# ============================================================================
67+
68+
cat("3. Listing available vocabularies\n")
69+
cat("---------------------------------\n")
70+
71+
# Get first 10 vocabularies
72+
vocabs <- client$vocabularies$list(page_size = 10)
73+
74+
cat("Available vocabularies:\n")
75+
vocab_list <- vocabs$data %||% vocabs$vocabularies %||% vocabs
76+
for (v in vocab_list) {
77+
cat(sprintf(" %s - %s\n",
78+
v$vocabulary_id,
79+
v$vocabulary_name))
80+
}
81+
cat("\n")
82+
83+
# ============================================================================
84+
# Get Concept with Additional Information
85+
# ============================================================================
86+
87+
cat("4. Getting a concept with relationships\n")
88+
cat("---------------------------------------\n")
89+
90+
# Get concept with relationships included
91+
concept_full <- client$concepts$get(201826, include_relationships = TRUE)
92+
93+
cat("Concept:", concept_full$concept_name, "\n")
94+
if (!is.null(concept_full$relationships)) {
95+
cat("Number of relationships:", length(concept_full$relationships), "\n")
96+
}
97+
cat("\n")
98+
99+
# ============================================================================
100+
# Done
101+
# ============================================================================
102+
103+
cat("Done!\n")

0 commit comments

Comments
 (0)