View source: R/multiple_entries.R
fhir_collapse | R Documentation |
This function collapses multiple entries that belong to the same higher level FHIR element (see examples).
fhir_collapse(indexed_data_frame, columns, sep, brackets, collapse = " ")
indexed_data_frame |
A data.frame/data.table with indexed multiple entries. |
columns |
A character vector of column names where values should be collapsed |
sep |
A character vector of length one defining the separator that was used when pasting together multiple entries in |
brackets |
A character vector of length two, defining the brackets used for the indices. |
collapse |
A character vector of length one used to separate the collapsed fields. Defaults to blank space. |
Currently this function is only needed for very few FHIR elements where multiple values should be kept together
in the melting process. To our knowledge, this is only true for address.line elements and name.given elements.
Rather than building the cross product with all other elements in the resource as done by fhir_melt()
, these
elements should be collapsed into a single entry before melting. See examples to get a better idea of this.
The modified data.table/data.frame with collapsed multiple entries
fhir_melt()
### First example: Keep name.given elements together
#unserialize example
bundles <- fhir_unserialize(bundles = example_bundles7)
#Have a look at the structure of example_bundles7
?example_bundles7
#Define sep and brackets
sep <- "|"
brackets <- c("[", "]")
#crack fhir resources
table_desc <- fhir_table_description(
resource = "Patient",
brackets = brackets,
sep = sep
)
df <- fhir_crack(bundles = bundles, design = table_desc)
df
#name.given elements from the same name (i.e. the official vs. the nickname)
#should be collapsed
df2 <- fhir_collapse(df, columns = "name.given", sep = sep, brackets = brackets)
df2
#Next the name can be molten
fhir_melt(df2, brackets = brackets, sep = sep, columns = fhir_common_columns(df2,"name"))
### Second: Keep address line elements together
#unserialize example
bundles <- fhir_unserialize(bundles = example_bundles6)
#Have a look at the structure of example_bundles6
?example_bundles6
#Define sep and brackets
sep <- "|"
brackets <- c("[", "]")
#crack fhir resources
table_desc <- fhir_table_description(
resource = "Patient",
brackets = brackets,
sep = sep
)
df <- fhir_crack(bundles = bundles, design = table_desc)
df
#Address.line elements from the same address (i.e. the work vs. the home address)
#should be collapsed
df2 <- fhir_collapse(df, columns = "address.line", sep = sep, brackets = brackets, collapse = ", ")
df2
#Next the address can be molten
fhir_melt(df2, brackets = brackets, sep = sep, columns = fhir_common_columns(df2,"address"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.