fhir_crack | R Documentation |
Converts a fhir_bundle_list (the result of fhir_search()
) to a data.frame/data.table or list of df/dt,
if more than one resource type is extracted at once.
There are two main output formats for the table: compact and wide. They differ regarding their handling of multiple occurrences of
the same FHIR element (e.g. Patient.adress
). In the compact format multiple occurrences are pasted together into one cell/column,
in the wide format multiple occurrences are distributed over several (indexed) columns. If none of the resources contains any multiple
values on the extracted elements, the two formats will result in the same structure.
To increase speed with larger amounts of data the cracking process can be parallelised over a number of cores defined in the
ncores
argument.
fhir_crack(
bundles,
design,
sep = NULL,
brackets = NULL,
rm_empty_cols = NULL,
verbose = 2,
data.table = FALSE,
format = NULL,
keep_attr = NULL,
ncores = 1
)
## S4 method for signature 'ANY,fhir_table_description'
fhir_crack(
bundles,
design,
sep = NULL,
brackets = NULL,
rm_empty_cols = NULL,
verbose = 2,
data.table = FALSE,
format = NULL,
keep_attr = NULL,
ncores = 1
)
## S4 method for signature 'ANY,fhir_design'
fhir_crack(
bundles,
design,
sep = NULL,
brackets = NULL,
rm_empty_cols = NULL,
verbose = 2,
data.table = FALSE,
format = NULL,
keep_attr = NULL,
ncores = 1
)
bundles |
A FHIR search result as returned by |
design |
A fhir_design or fhir_table_description object. See |
sep |
Optional. A character of length one containing the separator string used for separating multiple entries in cells when |
brackets |
Optional. A character of length one or two used for the indices of multiple entries, which will overwrite the |
rm_empty_cols |
Optional. Remove empty columns? Logical scalar which will overwrite the |
verbose |
An integer vector of length one. If 0, nothing is printed, if 1, only finishing message is printed, if > 1, extraction progress will be printed. Defaults to 2. |
data.table |
A logical vector of length one. If it is set to |
format |
Optional. A character of length one indicating whether the resulting table should be cracked to a |
keep_attr |
Optional. A logical of length one indicating whether the attribute name of the respective element ( |
ncores |
Either |
If a fhir_design was used, the result is a list of data.frames, i.e. a fhir_df_list object, or a list of data.tables, i.e. a fhir_dt_list object. If a fhir_table_description was used, the result is a single data.frame/data.table.
Downloading bundles from a FHIR server: fhir_search()
Creating designs/table_descriptions: fhir_table_description()
and fhir_design()
Dealing with multiple entries: fhir_melt()
, fhir_cast()
, fhir_rm_indices()
#unserialize example bundle
bundles <- fhir_unserialize(medication_bundles)
###Example 1###
#Extract just one resource type
#define attributes to extract
med_desc <- fhir_table_description(
resource = "MedicationStatement",
cols = c(
id = "id",
status = "status",
system = "medicationCodeableConcept/coding/system",
code = "medicationCodeableConcept/coding/code",
display = "medicationCodeableConcept/coding/display"
)
)
med_df <- fhir_crack(bundles = bundles, design = med_desc)
head(med_df) #data.frame
###Example 2###
#extract two resource types at once
pat_desc <- fhir_table_description(
resource = "Patient"
)
design <- fhir_design(med_desc, pat_desc)
df_list <- fhir_crack(bundles = bundles, design = design)
#list of data.frames/fhir_df_list
head(df_list$med_desc)
head(df_list$pat_desc)
#The design that was used can be extracted from a fhir_df_list
fhir_design(df_list)
###Example 3###
#Filter values before extracting
#unserialize example bundle
b <- fhir_unserialize(bundles = example_bundles5)
#only extract codings with loinc system
table_desc <- fhir_table_description(
resource = "Observation",
cols = c(
id = "id",
loinc = "code/coding[system[@value='http://loinc.org']]/code",
display = "code/coding[system[@value='http://loinc.org']]/display"
)
)
table <- fhir_crack(bundles = b,
design = table_desc)
table
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.