Skip to content

Commit 9b64e05

Browse files
authored
Merge pull request #4 from OMOPHub/develop
Prep for 1.7.0
2 parents e8bb9b2 + 42cb1a5 commit 9b64e05

12 files changed

Lines changed: 969 additions & 169 deletions

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
^\.Rproj\.user$
1111
^\.env$
1212
^cran-comments\.md$
13+
^doc$
14+
^Meta$

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ codecov.yml
3737
.env
3838
.env.local
3939
.env.production
40-
cran-comments.md
40+
cran-comments.md
41+
/doc/
42+
/Meta/

R/fhir.R

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ fhir_batch_to_tibble <- function(result, codings) {
201201
items <- result$results %||% list()
202202
n <- length(codings)
203203

204+
# Collapse a possibly-nested error object to a scalar string. The API
205+
# may return `error` as a plain string, a list like
206+
# `list(code = "concept_not_found", message = "...")`, or something
207+
# else. A list-column here would be expanded into extra tibble rows.
208+
error_to_string <- function(err) {
209+
if (is.null(err)) return(NA_character_)
210+
if (is.character(err) && length(err) == 1L) return(err)
211+
if (is.list(err)) {
212+
msg <- err$message %||% err$code %||% err$detail
213+
if (!is.null(msg) && is.character(msg) && length(msg) == 1L) {
214+
return(msg)
215+
}
216+
return(paste(names(err) %||% "", unlist(lapply(err, as.character)),
217+
sep = "=", collapse = "; "))
218+
}
219+
# Zero-length / non-character fallbacks: single-bracket indexing
220+
# returns NA on a length-0 vector instead of throwing. Guards
221+
# against `character(0)`, `integer(0)`, etc.
222+
as.character(err)[1L]
223+
}
224+
204225
make_row <- function(i) {
205226
input_coding <- codings[[i]]
206227
item <- if (i <= length(items)) items[[i]] else NULL
@@ -221,7 +242,7 @@ fhir_batch_to_tibble <- function(result, codings) {
221242
mapping_type = NA_character_,
222243
similarity_score = NA_real_,
223244
status = "failed",
224-
status_detail = item$error %||% "unresolved"
245+
status_detail = error_to_string(item$error)
225246
))
226247
}
227248

inst/examples/basic_usage.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111

1212
library(omophub)
1313

14+
# Null-coalescing operator (available in base R 4.4+; define locally for
15+
# compatibility with the R >= 4.1 package requirement).
16+
`%||%` <- function(a, b) if (is.null(a)) b else a
17+
1418
# ============================================================================
1519
# Setup
1620
# ============================================================================
1721

1822
# Initialize client (uses OMOPHUB_API_KEY environment variable)
1923
# You can also pass the API key directly:
20-
# client <- omophub(api_key = "oh_your_api_key")
21-
client <- omophub()
24+
# client <- OMOPHubClient$new(api_key = "oh_your_api_key")
25+
client <- OMOPHubClient$new()
2226

2327
cat("OMOPHub R Client - Basic Usage Example\n")
2428
cat("======================================\n\n")

0 commit comments

Comments
 (0)