Executes an aggregate query over FHIR data. The query calculates summary values based on aggregations and groupings of FHIR resources.

ds_aggregate(
  ds,
  subject_resource,
  aggregations,
  groupings = NULL,
  filters = NULL
)

Arguments

ds

The DataSource object containing the data to be queried.

subject_resource

A string representing the type of FHIR resource to aggregate data from.

aggregations

A named list of FHIRPath expressions that calculate a summary value from each grouping. The expressions must be singular.

groupings

An optional named list of FHIRPath expressions that determine which groupings the resources should be counted within.

filters

An optional sequence of FHIRPath expressions that can be evaluated against each resource in the data set to determine whether it is included within the result. The expression must evaluate to a Boolean value. Multiple filters are combined using logical AND operation.

Value

A Spark DataFrame containing the aggregated data.

See also

Examples

pc <- pathling_connect()
data_source <- pc %>% pathling_read_ndjson(pathling_examples('ndjson'))
data_source %>% ds_aggregate('Patient',
     aggregations = c(patientCount='count()', 'id.count()'),
     groupings = c('gender', givenName='name.given'),
     filters = c('birthDate > @1950-01-01')
)
#> # Source:   table<`sparklyr_tmp_564a61d6_c69b_4acc_b80b_34313e4ae268`> [9 x 4]
#> # Database: spark_connection
#>   gender givenName   patientCount `id.count()`
#>   <chr>  <chr>              <dbl>        <dbl>
#> 1 female Karina848              1            2
#> 2 female Su690                  1            1
#> 3 male   Gilberto712            1            1
#> 4 male   Pedro316               1            1
#> 5 male   Guy979                 1            1
#> 6 male   Shirley182             1            1
#> 7 female Ophelia894             1            1
#> 8 female Cherryl901             1            1
#> 9 male   Seymour882             1            1
pathling_disconnect(pc)