Learn R Programming

fhircrackr (version 0.2.1)

fhir_search: Download Fhir search result

Description

Downloads all FHIR bundles of a FHIR search request from a FHIR server.

Usage

fhir_search(
  request,
  username = NULL,
  password = NULL,
  max_bundles = Inf,
  verbose = 1,
  max_attempts = 5,
  delay_between_attempts = 10,
  log_errors = 0,
  save_to_disc = FALSE,
  directory = paste0("FHIR_bundles_", gsub("-| |:", "", Sys.time()))
)

Arguments

request

A string containing the full FHIR search request.

username

A string containing the username for basic authentication. Defaults to NULL, meaning no authentication.

password

A string containing the password for basic authentication. Defaults to NULL, meaning no authentication.

max_bundles

Maximal number of bundles to get. Defaults to Inf meaning all available bundles are downloaded.

verbose

An Integer Scalar. If 0, nothings is printed, if 1, only finishing message is printed, if > 1, downloading progress will be printed. Defaults to 2.

max_attempts

A numeric scalar. The maximal number of attempts to send a request, defaults to 5.

delay_between_attempts

A numeric scalar specifying the delay in seconds between two attempts. Defaults to 10.

log_errors

Takes values 0, 1 or 2. Controls the logging of errors. 1 and 2 will write a file to the current working directory.

0: no logging of errors,

1: tabulate http response and write to csv-file

2: write http response as to xml-file

save_to_disc

A logical scalar. If TRUE the bundles are saved as numerated xml-files into the directory specified in the argument directory and not returned as a bundle list in the R session. This is useful when a lot of bundles are to be downloaded and keeping them all in one R session might overburden working memory. When download is complete, the bundles can be loaded into R using fhir_load. Defaults to FALSE, i.e. bundles are returned as a list within the R session.

directory

The directory the bundles are saved to when save_to_disc is TRUE. Defaults to creating a time-stamped directory into the current working directory.

Value

A list of bundles in xml format when save_to_disc = FALSE (the default), else NULL.

Examples

Run this code
# NOT RUN {
bundles <- fhir_search("https://hapi.fhir.org/baseR4/Medication?", max_bundles=3)
# }

Run the code above in your browser using DataLab