A function to call an epidm lookup table and recode where we are aware of a new value.
Built in are the organism re-classifications and specimen_type groupings and a manual mode.
Usage
lookup_recode(
src,
type = c("species", "specimen", "inpatient_admission_method",
"inpatient_discharge_destination", "ecds_destination_code", "manual"),
.import = NULL
)
Examples
df <- data.frame(
spec = c(
sample(grep(")",
respeciate_organism$previous_organism_name,
value=TRUE,
invert = TRUE),
9),
"ESCHERICHIA COLI","SARS-COV-2","CANDIDA AUREUS"),
type = sample(specimen_type_grouping$specimen_type,12),
date = sample(seq.Date(from = Sys.Date()-365,
to = Sys.Date(),
by = "day"),12)
)
df <- df[order(df$date),]
# show the data before the changes
df
#> spec type date
#> 8 CORYNEBACTERIUM EQUI BRONCHIAL 2023-09-20
#> 7 ALCALIGENES XYLOSOXIDANS XYLOSOXIDANS BURN 2023-10-01
#> 9 RHIZOBIUM RADIOBACTER WOUND 2023-10-28
#> 11 SARS-COV-2 PENIS 2024-01-16
#> 3 CITROBACTER DIVERSUS IV CATHETER TIP 2024-01-28
#> 4 PANTOEA AGGLOMERANS ARTERIAL LINE TIP 2024-01-29
#> 6 CALYMMATOBACTERIUM GRANULOMATIS SKIN ULCER 2024-03-20
#> 5 ANAEROCOCCUS PREVOTII DENTAL ABSCESS 2024-03-23
#> 2 STREPTOCOCCUS FAECALIS PERITONEAL FLUID 2024-04-15
#> 1 STOMATOCOCCUS SP BONE 2024-05-05
#> 10 ESCHERICHIA COLI TRACHEA 2024-05-10
#> 12 CANDIDA AUREUS BIOPSY-NOS 2024-05-11
# check the lookup tables
# observe the changes
head(respeciate_organism[1:2])
#> previous_organism_name organism_species_name
#> 1 ALCALIGENES DENITRIFICANS ACHROMOBACTER DENITRIFICANS
#> 2 ALCALIGENES PIECHAUDII ACHROMOBACTER PIECHAUDII
#> 3 ALCALIGENES XYLOSOXIDANS ACHROMOBACTER XYLOSOXIDANS
#> 4 ALCALIGENES XYLOSOXIDANS XYLOSOXIDANS ACHROMOBACTER XYLOSOXIDANS
#> 5 ACTINOBACULUM SCHAALII ACTINOTIGNUM SCHAALII
#> 6 TETRATHIOBACTER KASHMIRENSIS ADVENELLA KASHMIRENSIS
df$species <- lookup_recode(df$spec,'species')
df[,c('spec','species','date')]
#> spec species date
#> 8 CORYNEBACTERIUM EQUI RHODOCOCCUS EQUI 2023-09-20
#> 7 ALCALIGENES XYLOSOXIDANS XYLOSOXIDANS ACHROMOBACTER XYLOSOXIDANS 2023-10-01
#> 9 RHIZOBIUM RADIOBACTER AGROBACTERIUM TUMEFACIENS 2023-10-28
#> 11 SARS-COV-2 SARS-COV-2 2024-01-16
#> 3 CITROBACTER DIVERSUS CITROBACTER KOSERI 2024-01-28
#> 4 PANTOEA AGGLOMERANS PANTOEA AGGLOMERANS 2024-01-29
#> 6 CALYMMATOBACTERIUM GRANULOMATIS KLEBSIELLA GRANULOMATIS 2024-03-20
#> 5 ANAEROCOCCUS PREVOTII PEPTOSTREPTOCOCCUS PREVOTII 2024-03-23
#> 2 STREPTOCOCCUS FAECALIS ENTEROCOCCUS FAECALIS 2024-04-15
#> 1 STOMATOCOCCUS SP ROTHIA SP 2024-05-05
#> 10 ESCHERICHIA COLI ESCHERICHIA COLI 2024-05-10
#> 12 CANDIDA AUREUS CANDIDA AUREUS 2024-05-11
head(specimen_type_grouping)
#> specimen_type specimen_group
#> 1 BLOOD Blood
#> 2 CORD BLOOD Blood
#> 3 JOINT Bones & Joints
#> 4 SYNOVIAL FLUID Bones & Joints
#> 5 BONE Bones & Joints
#> 6 JOINT PROSTHESIS Bones & Joints
df$grp <- lookup_recode(df$type,'specimen')
df[,c('species','type','grp','date')]
#> species type grp
#> 8 RHODOCOCCUS EQUI BRONCHIAL Lower Respiratory Tract
#> 7 ACHROMOBACTER XYLOSOXIDANS BURN Swabs-General
#> 9 AGROBACTERIUM TUMEFACIENS WOUND Wound Swabs
#> 11 SARS-COV-2 PENIS Genital
#> 3 CITROBACTER KOSERI IV CATHETER TIP Tips & Lines
#> 4 PANTOEA AGGLOMERANS ARTERIAL LINE TIP Tips & Lines
#> 6 KLEBSIELLA GRANULOMATIS SKIN ULCER Swabs-General
#> 5 PEPTOSTREPTOCOCCUS PREVOTII DENTAL ABSCESS URT/Mouth/Ear
#> 2 ENTEROCOCCUS FAECALIS PERITONEAL FLUID Fluids
#> 1 ROTHIA SP BONE Bones & Joints
#> 10 ESCHERICHIA COLI TRACHEA Lower Respiratory Tract
#> 12 CANDIDA AUREUS BIOPSY-NOS Swabs-General
#> date
#> 8 2023-09-20
#> 7 2023-10-01
#> 9 2023-10-28
#> 11 2024-01-16
#> 3 2024-01-28
#> 4 2024-01-29
#> 6 2024-03-20
#> 5 2024-03-23
#> 2 2024-04-15
#> 1 2024-05-05
#> 10 2024-05-10
#> 12 2024-05-11
# for a tidyverse use
# df %>% mutate(spec=lookup_recode(spec,'species))
# manual input of your own lookup
# .import=list(new,old)
lookup_recode(
"ALCALIGENES DENITRIFICANS",
type = 'manual',
.import=list(respeciate_organism$organism_species_name,
respeciate_organism$previous_organism_name)
)
#> [1] "ACHROMOBACTER DENITRIFICANS"