Requires the output from map_clinical_events_to_phecodes(), which maps UK Biobank clinical events from Read 2, Read 3 and ICD-9 to ICD-10, then uses Phecode Map 1.2 with ICD-10 Codes (beta) to map these ICD-10 equivalents (and any actual ICD-10 records) to Phecodes. This function uses the output from map_clinical_events_to_phecodes() to reverse map from phecodes to Read 2, Read 3, ICD-9 and ICD-10. This is useful for checking which raw clinical codes have been used in any phecode-defined phenotypes.

make_phecode_reverse_map(clinical_events_phecodes, all_lkps_maps)

Arguments

clinical_events_phecodes

A data frame created by map_clinical_events_to_phecodes().

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.

Value

A data frame with columns "phecode", "phecode_description", "data_coding", "code" "description", "icd10_equivalent" and "icd10_description". Column 'code' contains the original 'raw' UK clinical codes, with code type indicated by the 'data_coding' column.

Examples

# build dummy all_lkps_maps
all_lkps_maps_dummy <- build_all_lkps_maps_dummy()

# map dummy clinical events df to phecodes
clinical_events_phecodes_dummy <- map_clinical_events_to_phecodes(
  clinical_events = dummy_clinical_events_tidy(),
  all_lkps_maps = all_lkps_maps_dummy,
  min_date_only = FALSE
)
#> Identified the following 5 data sources to map to phecodes: [1] **Death register** - Underlying (primary) cause of death, [2] **Death register** - Contributory (secondary) cause of death, [3] **Primary care** - `read_2` column, data provider England (Vision), [4] **Primary care** - `read_3` column, data provider England (TPP), [5] **Summary Diagnoses - Hospital inpatient - Health-related outcomes** - Diagnoses - ICD9
#> 
#> ***MAPPING clinical_events TO PHECODES***
#> [1] **Death register** - Underlying (primary) cause of death
#> [2] **Death register** - Contributory (secondary) cause of death
#> [3] **Primary care** - `read_2` column, data provider England (Vision)
#> [4] **Primary care** - `read_3` column, data provider England (TPP)
#> [5] **Summary Diagnoses - Hospital inpatient - Health-related outcomes** - Diagnoses - ICD9
#> Time taken: 0 minutes, 0 seconds.

# create reverse map
make_phecode_reverse_map(
  clinical_events_phecodes = clinical_events_phecodes_dummy,
  all_lkps_maps = all_lkps_maps_dummy
)
#> Time taken: 0 minutes, 0 seconds.
#> # A tibble: 6 × 7
#>   phecode phecode_description     data_coding code  description icd10_equivalent
#>   <chr>   <chr>                   <chr>       <chr> <chr>       <chr>           
#> 1 401.1   Essential hypertension  icd10       I10   Essential … I10             
#> 2 250.1   Type 1 diabetes         icd10       E109  Type 1 dia… E109            
#> 3 401.1   Essential hypertension  icd9        4019  ESSENTIAL … I10             
#> 4 706.2   Sebaceous cyst          read3       XaIP9 Sebaceous … L721            
#> 5 704     Diseases of hair and h… read3       XaIP9 Sebaceous … L721            
#> 6 401.1   Essential hypertension  read3       XE0Uc Essential … I10             
#> # … with 1 more variable: icd10_description <chr>