fhir_count_resource: Get Resources' Counts

View source: R/sample_resources.R

fhir_count_resourceR Documentation

Get Resources' Counts

Description

Downloads a count of resources matching the resource type and search parameters specified in resource and parameters. This function makes use of the _summary=count parameter of FHIR search and is therefore able to count resources on the server without actually downloading them.

Usage

fhir_count_resource(
  base_url,
  resource,
  parameters = NULL,
  username = NULL,
  password = NULL,
  token = NULL,
  add_headers = NULL
)

Arguments

base_url

A character vector of length one specifying the base URL of the FHIR server, e.g. "http://hapi.fhir.org/baseR4".

resource

A character vector of length one or fhir_resource_type object with the resource type to be searched, e.g. "Patient".

parameters

Optional. Either a length 1 character vector containing properly formatted FHIR search parameters, e.g. "gender=male&_summary=count" or a named list or named character vector e.g. list(gender="male", "_summary"="count") or c(gender="male", "_summary"="count"). Note that parameter names beginning with _ have to be put in quotation marks!

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").

Details

For more information on authentication options, please see the help page of fhir_search()

Value

An integer of length 1 containing the number of resources matching the type and search parameters specified in resource and parameters.

Examples



#the try({}, silent = TRUE) statement is only there to catch errors when the server is down
#you can skip it when the server is reachable

try({

#number of female Patient resources on the server
fhir_count_resource(
  base_url = 'https://vonk.fire.ly/R4',
  resource = "Patient",
  parameters = c(gender = "female"))
}, silent = TRUE)


fhircrackr documentation built on Feb. 16, 2023, 8:33 p.m.