map_clinical_events_to_phecodes: Map UK Biobank clinical events to phecodes

View source: R/clinical_events_to_phecodes.R

map_clinical_events_to_phecodesR Documentation

Map UK Biobank clinical events to phecodes

Description

UK Biobank clinical events sources that are recorded in ICD10 are mapped directly to phecodes, while non-ICD10 sources are mapped to phecodes via ICD10.

Usage

map_clinical_events_to_phecodes(
  clinical_events,
  all_lkps_maps = NULL,
  min_date_only = FALSE,
  col_filters = default_col_filters()
)

Arguments

clinical_events

A long format data frame created by tidy_clinical_events, tidy_gp_clinical, tidy_gp_scripts or make_clinical_events_db. This can also be a tbl_dbi object.

all_lkps_maps

Either a named list of lookup and mapping tables (either data frames or tbl_dbi objects), or the path to a SQLite database containing these tables (see also build_all_lkps_maps() and all_lkps_maps_to_db()). If NULL, will attempt to connect to an SQLite database named 'all_lkps_maps.db' in the current working directory, or to a a SQLite database specified by an environmental variable named 'ALL_LKPS_MAPS_DB' (see here for how to set environment variables using a .Renviron file). The latter method will be used in preference.

min_date_only

If TRUE, result will be filtered for only the earliest date per eid-phecode pair (date will be recorded as NA for cases where there are no dates).

col_filters

A named list where each name in the list refers to the name of a lookup or mapping table. Each item is also a named list, where the names refer to column names in the corresponding table, and the items are vectors of values to filter for. For example, ⁠list(my_lookup_table = list(colA = c("A", "B"))⁠ will result in my_lookup_table being filtered for rows where colA is either 'A' or 'B'. Uses default_col_filters() by default. Set to NULL to remove all filters.

Details

Maps the following UK Biobank clinical events sources to phecodes: f40001, f40002, f20002_icd10, f40006, f41270, f40013, f41271, gpc1_r3, gpc2_r3, gpc3_r3, gpc4_r3, gpc1_r2, gpc2_r2, gpc3_r2, gpc4_r2.

Value

A data frame with column names 'eid', 'source', 'index', 'code', 'icd10', 'phecode' and 'date'.

Examples

# build dummy all_lkps_maps
all_lkps_maps_dummy <- build_all_lkps_maps_dummy()

# dummy clinical events data frame
dummy_clinical_events_tidy()

# map to phecodes
map_clinical_events_to_phecodes(
  clinical_events = dummy_clinical_events_tidy(),
  all_lkps_maps = all_lkps_maps_dummy,
  min_date_only = FALSE
)

rmgpanw/codemapper documentation built on Aug. 30, 2023, 4:07 p.m.