fhir_put: PUT to a FHIR server

View source: R/build_resources.R

fhir_putR Documentation

PUT to a FHIR server

Description

This function is a convenience wrapper around httr::PUT().

Usage

fhir_put(
  url,
  body,
  username = NULL,
  password = NULL,
  token = NULL,
  add_headers = NULL,
  verbose = 1,
  log_errors = NULL
)

Arguments

url

An object of class fhir_url or a character vector of length one containing the url to PUT to.

body

An object of class fhir_resource or fhir_body. See details for how to generate them.

username

A character vector of length one containing the username for basic authentication.

password

A character vector of length one containing the password for basic authentication.

token

A character vector of length one or object of class httr::Token, for bearer token authentication (e.g. OAuth2). See fhir_authenticate() for how to create this.

add_headers

A named character vector of custom headers to add to the HTTP request, e.g. c(myHeader = "somevalue") or c(firstHeader = "value1", secondHeader = "value2").

verbose

An integer vector of length one. If 0, nothing is printed, if > 0 success message is printed. Defaults to 1.

log_errors

Either NULL or a character vector of length one indicating the name of a file in which to save http errors. NULL means no error logging. When a file name is provided, the errors are saved in the specified file. Defaults to NULL. Regardless of the value of log_errors the most recent http error message within the current R session is saved internally and can be accessed with fhir_recent_http_error().

Details

fhir_put() accepts two classes for the body:

  1. A fhir_resource as created by fhir_build_resource(). This is used when just a single resource should be PUT to the server. In this case url must contain the base url plus the resource type and the resource id, e.g. http://hapi.fhir.org/baseR4/Patient/1a2b3c.

  2. A fhir_body as created by fhir_body(). This is the most flexible approach, because within the fhir_body object you can represent any kind of content as a string and set the type accordingly. See examples.

For examples of how to create the different body types see the respective help pages. For an example of the entire workflow around creating and PUTing resources, see the package vignette on recreating resources.

Examples

## Not run: 
### 1. PUT fhir__resource object
#unserialize example resource
resource <- fhir_unserialize(example_resource2)

#have a look at the resource
resource

#put
fhir_put(url = "http://hapi.fhir.org/baseR4/Patient/1a2b3c", body = resource)

### 2. PUT fhir_body object
#define body
body <- fhir_body(content = "<Patient> <id value='x1y2'/> <gender value='female'/> </Patient>",
                  type = "xml")

#put
fhir_put(url = "http://hapi.fhir.org/baseR4/Patient/x1y2", body = body)

## End(Not run)

POLAR-fhiR/fhircrackr documentation built on Dec. 24, 2024, 3:06 a.m.