MyNixOS website logo
Description

Read and Search Interface to the 'HL7 FHIR' REST API.

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 brings the results into the R environment. R on FHIR is based on the FhirClient of the official 'HL7 FHIR .NET API', also made by Firely.

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 official 'HL7 FHIR .NET API', 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 fhirClient
client <- fhirClient$new("https://vonk.fire.ly/")

# Setting up a fhirClient with OAuth 2.0
client <- 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)

# Search
bundle <- 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 mechanism
  bundle <- client$continue(bundle)
}

# Searching with a searchParams object
query <- 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 read
client$qraphQL("{id name{given,family}}", "Patient/example")

#GraphQL read
client$qraphQL("{PatientList(name:\"pet\"){name @first @flatten{family,given @first}}}")

# Operations
client$operation("Observation", name = "lastn")

fhirBulkClient

privatekey <- openssl::read_key("PrivateKey.pem")

# Create your claim
claim <- jose::jwt_claim(iss = "ServiceURL",
                         sub = "ClientID",
                         aud = "TokenURL",
			 # expiration date as epoch (5 minutes)
                         exp = as.integer(as.POSIXct( Sys.time() + 300)), 
   			 # 'random' number
                         jti = charToRaw(as.character(runif(1, 0.5, 100000000000)))) 

# Sign your claim with your private key
jwt <- jose::jwt_encode_sig(claim, privatekey)

# Define your scope(s)
scopes <- c("system/*.read", "system/CommunicationRequest.write")

# Create a new fhirBulkClient
bulkclient <- fhirBulkClient$new("FHIRBulkServerURL", tokenURL = "TokenURL")

# Retrieve your token
token <- bulkclient$retrieveToken(jwt, scopes)

# Set your token
bulkclient$setToken(token$access_token)

# Request a download for Patient Cohort 3
bulkclient$groupExport(3)

# Request the progress of the requests
bulkclient$getBulkStatus()

# When the downloads a available, download the bulkdata
patient_cohort_3 <- bulkclient$downloadBulk(1)

View(patient_cohort_3)
Metadata

Version

0.4.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows