Skip to content

Commit 466c0b3

Browse files
author
alex-omophub
committed
Update .gitignore, .Rbuildignore, and enhance error handling in fhir.R
- Added entries for `doc/` and `Meta/` to .gitignore and .Rbuildignore to exclude documentation and metadata files from version control. - Introduced a new `error_to_string` function in fhir.R to improve error handling by converting various error formats into a consistent string representation for better debugging and user feedback. - Updated example scripts to reflect changes in client initialization and error handling practices.
1 parent 7b55688 commit 466c0b3

11 files changed

Lines changed: 821 additions & 166 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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ 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+
as.character(err)[[1L]]
220+
}
221+
204222
make_row <- function(i) {
205223
input_coding <- codings[[i]]
206224
item <- if (i <= length(items)) items[[i]] else NULL
@@ -221,7 +239,7 @@ fhir_batch_to_tibble <- function(result, codings) {
221239
mapping_type = NA_character_,
222240
similarity_score = NA_real_,
223241
status = "failed",
224-
status_detail = item$error %||% "unresolved"
242+
status_detail = error_to_string(item$error)
225243
))
226244
}
227245

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)