ds_view: Execute a SQL on FHIR view

View source: R/view.R

ds_viewR Documentation

Execute a SQL on FHIR view

Description

Executes a SQL on FHIR view definition and returns the result as a Spark DataFrame.

Usage

ds_view(
  ds,
  resource,
  select = NULL,
  constants = NULL,
  where = NULL,
  json = NULL
)

Arguments

ds

The DataSource object containing the data to be queried.

resource

A string representing the type of FHIR resource that the view is based upon, e.g. 'Patient' or 'Observation'.

select

A list of columns and nested selects to include in the view. Each element should be a list with appropriate structure.

constants

An optional list of constants that can be used in FHIRPath expressions.

where

An optional list of FHIRPath expressions that can be used to filter the view.

json

An optional JSON string representing the view definition, as an alternative to providing the parameters as R objects.

Value

A Spark DataFrame containing the results of the view.

See Also

Pathling documentation - SQL on FHIR

Examples

## Not run: 
data_source <- pc %>% pathling_read_ndjson(pathling_examples('ndjson'))
data_source %>% ds_view('Patient',
     select = list(
       list(
         column = list(
           list(path = 'id', name = 'id'),
           list(path = 'gender', name = 'gender'),
           list(path = "telecom.where(system='phone').value", 
                             name = 'phone_numbers', collection = TRUE)
         )
       ),
       list(
         forEach = 'name',
         column = list(
           list(path = 'use', name = 'name_use'),
           list(path = 'family', name = 'family_name')
         ),
         select = list(
           list(
             forEachOrNull = 'given',
             column = list(
               list(path = '$this', name = 'given_name')
             )
           )
         )
       )
     ),
     where = list(
        list(path = "gender = 'male'")
     )
)

## End(Not run)

pathling documentation built on Sept. 15, 2025, 5:08 p.m.