# NOT RUN {
# Setting up a fhirClient
client <- fhirClient$new("https://vonk.fire.ly")
# Read
client$read("Patient/example")
# Search
bundle <- client$search("Patient", c("name=Peter", "address-postalcode=3999"))
while(!is.null(bundle)){
# Do something useful
bundle <- client$continue(bundle)
}
# }
# NOT RUN {
# Using Oauth 2.0
client <- fhirClient$new("https://vonk.fire.ly")
# Retrieving a token
client_id <- "id"
client_secret <- "secret"
app_name <- "TestApp"
scopes <- c("patient/*.read")
app <- httr::oauth_app(appname = app_name, client_id, client_secret)
oauth_endpoint <- httr::oauth_endpoint(
authorize = paste(client$authUrl, "?aud=", client$endpoint, sep=""),
access = client$tokenUrl)
token <- httr::oauth2.0_token(endpoint = oauth_endpoint, app = app, scope = scopes)
# Set a token and read a patient resource
client$setToken(token$credentials$access_token)
client$read("Patient/example")
# Token refresh
token <- token$refresh()
client$setToken(token$credentials$access_token)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab