fhir_tree: Represent a wide cast table as a tree

View source: R/fhir_tree.R

fhir_treeR Documentation

Represent a wide cast table as a tree

Description

This function takes a wide table as created by fhir_crack() with format="wide"and creates the tree structure implicit in the column names of the tables. It is useful to get an overview over the implied structure when planning to create FHIR bundles from this table using fhir_build_bundle().

Usage

fhir_tree(
  table,
  brackets,
  resource = "Resource",
  keep_attr = FALSE,
  keep_ids = FALSE,
  skip_one = FALSE,
  format = "plain",
  prompt = ": "
)

Arguments

table

A data.frame or data.table as produced by fhir_crack() with format="wide" or fhir_cast()

brackets

A character vector of length two. The brackets used in the table.

resource

A character vector of length one or fhir_resource_type object indicating which resource type the table is build from.

keep_attr

A logical vector of length one indicating whether attributes should be displayed or not. Only used for formats "plain" and "fancy".

keep_ids

A logical vector of length one indicating whether indices should be displayed or not. Only used for formats "plain" and "fancy".

skip_one

A logical vector of length one indicating whether first index 1 should be displayed or not. Only used for formats "plain" and "fancy".

format

The format of the tree. One of "plain", "fancy" or "xml".

prompt

A character vector of length one use as prompt Only used for formats "plain" and "fancy".

Value

A string that can be used with cat() or can be written to a text file.

See Also

fhir_cast(), fhir_build_bundle()

Examples

#' #unserialize example
bundles <- fhir_unserialize(bundles = example_bundles1)

#crack fhir resources
table_desc <- fhir_table_description(
    resource = "Patient",
    brackets = c("[", "]"),
    sep      = " ",
    format   = "wide"
)

df <- fhir_crack(bundles = bundles, design = table_desc)


###show tree

#plain format
cat(fhir_tree(
       table = df,
       brackets = c("[", "]"),
       resource = "Patient"
    )
 )

#fancy format with indices
cat(fhir_tree(
       table = df,
       brackets = c("[", "]"),
       resource = "Patient",
       format = "fancy",
       keep_ids = TRUE
     )
)

#xml format
cat(fhir_tree(
       table = df,
       brackets = c("[", "]"),
       resource = "Patient",
       format = "xml"
     )
 )

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