fhir_design-methods: Create a fhir_design object

fhir_designR Documentation

Create a fhir_design object

Description

A fhir_design is a named list of fhir_table_description objects (See fhir_table_description()) and should be created using the function described here. The design is used in fhir_crack() to tell the function how to flatten each resource type.

Usage

fhir_design(...)

## S4 method for signature 'fhir_table_description'
fhir_design(...)

## S4 method for signature 'list'
fhir_design(...)

## S4 method for signature 'fhir_table_list'
fhir_design(...)

Arguments

...

One or more fhir_table_description objects or a named list containing fhir_table_description objects, or an object of class fhir_df_list/fhir_dt_list. See fhir_table_description().

Details

A fhir_design looks for example like this:

A fhir_design with 2 table_descriptions:
A fhir_table_description with the following elements:

	fhir_resource_type: Patient

fhir_columns:
	------------ -----------------
	column name | xpath expression
------------ -----------------
	id          | id
name        | name/family
gender      | gender
------------ -----------------

	sep:           '||'
brackets:      '[', ']'
rm_empty_cols: FALSE
format:        'compact'
keep_attr:     TRUE

A fhir_table_description with the following elements:

	fhir_resource_type: MedicationAdministration

fhir_columns:
	An empty fhir_columns object

sep:           ':::'
brackets:      no brackets
rm_empty_cols: FALSE
format:        'wide'
keep_attr:     TRUE

The names of the table_descriptions are taken from the names of the arguments. If the table_descriptions are created within the call to fhir_design and therefore have no names, the names will be created from the respective resource type. See examples.

For backwards compatibility it is for the moment also possible to build it from an old-style design as used in fhircrackr (< 1.0.0). See examples.

If this function is given an object of class fhir_df_list or fhir_dt_list, it will extract the design that was used to create the respective list.

See Also

fhir_table_description(), fhir_crack()

Examples


####Example 1####

###create fhir_table_descriptions first
#see ?fhir_table_description for explanation

pat <- fhir_table_description(
    resource      = "Patient",
    cols          = c(
        id            = "id",
        name          = "name/family",
        gender        = "gender"
    ),
    sep           = "||",
    brackets      = c("[", "]"),
    rm_empty_cols = FALSE

)

meds <- fhir_table_description(resource = "MedicationAdministration")

###create design
#First option: Explicitly define names

design1 <- fhir_design(Pats = pat, Medics = meds)
print(design1)


#Second option: Names are taken from the object names

design2 <- fhir_design(pat, meds)
print(design2)


#Third option: Create table_description within fhir_design

design3 <- fhir_design(fhir_table_description(resource = "MedicationAdministration"))
print(design3)


#Fourth option: Names are taken from named list

design3 <- fhir_design(list(Patients = pat, Medications = meds))
print(design3)


###Example 2###
###Extract design from fhir_df_list/fhir_dt_list

#unserialize and crack example bundles
med_bundles <- fhir_unserialize(bundles = medication_bundles)
dfs <- fhir_crack(bundles = med_bundles, design = design1)

#extract design

fhir_design(dfs)


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