Learn R Programming

fhircrackr (version 1.0.0)

fhir_crack: Flatten list of FHIR bundles

Description

Converts a '>fhir_bundle_list (the result of fhir_search() to a list of data.frames/data.tables, i.e. a '>fhir_df_list/'>fhir_dt_list if a '>fhir_design is given in the argument design. Creates a single data.frame/data.table, if only a '>fhir_table_description is given in the argument design.

Usage

fhir_crack(
  bundles,
  design,
  sep = NULL,
  remove_empty_columns = NULL,
  brackets = NULL,
  verbose = 2,
  data.table = FALSE
)

# S4 method for ANY,fhir_design fhir_crack( bundles, design, sep = NULL, remove_empty_columns = NULL, brackets = NULL, verbose = 2, data.table = FALSE )

# S4 method for ANY,fhir_table_description fhir_crack( bundles, design, sep = NULL, remove_empty_columns = NULL, brackets = NULL, verbose = 2, data.table = FALSE )

# S4 method for ANY,list fhir_crack( bundles, design, sep = NULL, remove_empty_columns = NULL, brackets = NULL, verbose = 2, data.table = FALSE )

Arguments

bundles

A FHIR search result as returned by fhir_search().

design

A '>fhir_design or '>fhir_table_description object. See fhir_design()/fhir_table_description() and the corresponding vignette (vignette("flattenResources", package ="fhircrackr")) for a more detailed explanation and comprehensive examples of both.

sep

Optional. A character vector of length ones to separate pasted multiple entries which will overwrite the sep defined in design. If sep = NULL, it is looked up in design, where the default is " ".

remove_empty_columns

Optional. Remove empty columns? Logical scalar which will overwrite the rm_empty_cols defined in design. If remove_empty_columns = NULL, it is looked up in design, where the default is FALSE.

brackets

Optional. A character vector of length two defining the brackets surrounding indices for multiple entries, e.g. c( "<", ">"), which will overwrite the brackets defined in design. If brackets = NULL, it is looked up in design, where the default is character(0), i.e. no indices are added to multiple entries. Empty strings ("") are not allowed.

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 TRUE the fhir_crack-function returns a data.table, otherwise a data.frame. Defaults to FALSE.

Value

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.

See Also

Examples

Run this code
# NOT RUN {
#unserialize example bundle
bundles <- fhir_unserialize(medication_bundles)


###Example 1###
#Extract just one resource type

#define attributes to extract
medications <- fhir_table_description(
   resource = "MedicationStatement",
   cols = c(
			    	MS.ID              = "id",
				    STATUS.TEXT        = "text/status",
			    	STATUS             = "status",
			    	MEDICATION.SYSTEM  = "medicationCodeableConcept/coding/system",
			    	MEDICATION.CODE    = "medicationCodeableConcept/coding/code",
			    	MEDICATION.DISPLAY = "medicationCodeableConcept/coding/display",
			    	DOSAGE             = "dosage/text",
			    	PATIENT            = "subject/reference",
			    	LAST.UPDATE        = "meta/lastUpdated"
	    	),
	 style = fhir_style(
 			sep = " ",
	        	brackets = c("[", "]"),
    		    rm_empty_cols= FALSE
    		)
)

med_df <- fhir_crack(bundles = bundles, design = medications)

head(med_df) #data.frame


###Example 2###
#extract more resource types

patients <- fhir_table_description(
   resource = "Patient"
)

design <- fhir_design(medications, patients)

df_list <- fhir_crack(bundles = bundles, design = design)

#list of data.frames/fhir_df_list
head(df_list$medications)
head(df_list$patients)

#The design that was used can be extracted from a fhir_df_list
fhir_design(df_list)

# }

Run the code above in your browser using DataLab