Skip to content

Repository files navigation

RonFHIR

R on FHIR is an easy to use wrapper around the 'HL7 FHIR' REST API (STU 3 and R4). It provides tools to easily read and search resources on a FHIR server and bring the results into the R environment. R on FHIR is based on the FhirClient of the 'Firely .NET SDK', also made by Firely.

Installation

# To download the latest release from CRAN use:
install.packages("RonFHIR")
# Or download the development version from GitHub:# install.packages("devtools")devtools::install_github("FirelyTeam/RonFHIR")

Overview

  • Read
  • Search
  • GraphQL
  • Operations
  • Paging mechanism
  • Fluent search calls
  • OAuth 2.0
  • Bulk Data

Usage

fhirClient

library(RonFHIR)
# Setting up a fhirClientclient<-fhirClient$new("https://vonk.fire.ly/")
# Setting up a fhirClient with OAuth 2.0client<-fhirClient$new("Endpoint of FHIR server that supports SMART on FHIR OAuth2 access")
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)
client$setToken(token)
# Searchbundle<-client$search("Patient", c("name=Peter", "address-postalcode=3999"))
while(!is.null(bundle)){
# Do something useful here# Go to the next page of the bundle using FHIRs paging mechanismbundle<-client$continue(bundle)
}
# Searching with a searchParams objectquery<-searchParams$new()
query$select(c("name", "birthDate"))$where("given:exact=Peter")$orderBy("family")
peters<-client$searchByQuery(query, "Patient") # equivalent: client$search("Patient", c("_elements=name,birthDate","given:exact=Peter", "_sort=family"))#GraphQL readclient$qraphQL("{id name{given,family}}", "Patient/example")
#GraphQL readclient$qraphQL("{PatientList(name:\"pet\"){name @first @flatten{family,given @first}}}")
# Operationsclient$operation("Observation", name="lastn")

fhirBulkClient

privatekey<-openssl::read_key("PrivateKey.pem")
# Create your claimclaim<-jose::jwt_claim(iss="ServiceURL",
sub="ClientID",
aud="TokenURL",
# expiration date as epoch (5 minutes)exp= as.integer(as.POSIXct( Sys.time() +300)), # 'random' numberjti= charToRaw(as.character(runif(1, 0.5, 100000000000)))) # Sign your claim with your private keyjwt<-jose::jwt_encode_sig(claim, privatekey)
# Define your scope(s)scopes<- c("system/*.read", "system/CommunicationRequest.write")
# Create a new fhirBulkClientbulkclient<-fhirBulkClient$new("FHIRBulkServerURL", tokenURL="TokenURL")
# Retrieve your tokentoken<-bulkclient$retrieveToken(jwt, scopes)
# Set your tokenbulkclient$setToken(token$access_token)
# Request a download for Patient Cohort 3bulkclient$groupExport(3)
# Request the progress of the requestsbulkclient$getBulkStatus()
# When the downloads a available, download the bulkdatapatient_cohort_3<-bulkclient$downloadBulk(1)
View(patient_cohort_3)

About

R on FHIR

Topics

Resources

Stars

54 stars

Watchers

23 watching

Forks

Releases

Packages

Contributors

Languages