This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_fct_recode <- function(path_config_fl) { | |
mapp_col <- readRDS(file.path(path_config_fl, "mapp_col.rds")) | |
list_config_fls <- Sys.glob(file.path(path_config_fl, "*.rds")) | |
mapp_col <- mapp_col %>% dplyr::mutate(file_name_config = file.path(path_config_fl, paste0(common, "_levels.rds")), | |
list_config_fct = dplyr::if_else(file_name_config %in% list_config_fls, file_name_config, NA_character_)) %>% | |
dplyr::select(-file_name_config) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
occupancy_fct <- function(start_date = as.Date("2016-06-01", tz = "Europe/London"), | |
end_date = as.Date("2016-06-08", tz = "Europe/London"), | |
data){ | |
dt_los <- data %>% | |
dplyr::select(spell_number, spell_start, spell_end) %>% | |
dplyr::mutate(Same_day_discharge = as.numeric(difftime(spell_end, spell_start, unit = c("min")))) | |
dt_calc <- dt_los %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
occupancy_fct <- function(start_date = as.Date("2016-06-01", tz = "Europe/London"), | |
end_date = as.Date("2016-06-08", tz = "Europe/London"), | |
data){ | |
dt_los <- data %>% | |
dplyr::select(spell_number, spell_start, spell_end) %>% | |
dplyr::mutate(Same_day_discharge = as.numeric(difftime(spell_end, spell_start, unit = c("min")))) | |
dt_calc <- dt_los %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
los_distrib_with_better_breaks <- function(data, plot_chart){ | |
# renaming the variables I am interested in | |
df_rename <- df %>% | |
select(PAT_CODE, START_DATETIME, END_DATETIME, episode.order, Admission.Type, disch.ward.type, WARD_CODE) %>% | |
dplyr::rename(IDcol = PAT_CODE, Admissions = START_DATETIME, | |
Discharges = END_DATETIME, Episode_number = episode.order, Ward_code = WARD_CODE, | |
Admission_type = Admission.Type, Discharge_ward_type = disch.ward.type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
los_distrib_1_month_with_breaks_provided <- function(data, plot_chart){ | |
# renaming the variables I am interested in | |
# renaming the variables I am interested in | |
df_rename <- data %>% | |
select(PAT_CODE, START_DATETIME, END_DATETIME, episode.order, Admission.Type, disch.ward.type, WARD_CODE) %>% | |
dplyr::rename(IDcol = PAT_CODE, Admissions = START_DATETIME, | |
Discharges = END_DATETIME, Episode_number = episode.order, Ward_code = WARD_CODE, | |
Admission_type = Admission.Type, Discharge_ward_type = disch.ward.type) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# renaming the variables I am interested in | |
df_rename <- df %>% | |
select(PAT_CODE, START_DATETIME, END_DATETIME, episode.order, AGE_BAND, SEX, spell.type, WARD_CODE, spell.end.ward) %>% | |
dplyr::rename(IDcol = PAT_CODE, Admissions = START_DATETIME, PatientType = spell.type, | |
Discharges = END_DATETIME, EpisodeNumber = episode.order, Ward = WARD_CODE, | |
Gender = SEX, AgeBand = AGE_BAND, LastWard = spell.end.ward) | |
#df_subset <- df_subset %>% | |
#filter(EpisodeStart > StartDate & EpisodeEnd < EndDate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
melt_for_plt <- melt(total_adm_disch_non_emerg) | |
plot_adm_disc <-ggplot(melt_for_plt, aes(Week_Day, value, group = variable)) + #shape = Event, colour = Event | |
#geom_bar(stat = "identity", position = "identity" , alpha=0.4, width = 0.5, fill = "slateblue4") + | |
geom_line(aes(linetype = variable, color = variable), size = 1.0) + | |
geom_point(aes(shape = variable), size = 1.0) + | |
scale_shape_manual(values = c(7, 6, 5)) + | |
scale_linetype_manual(values = c("solid", "solid" , "twodash")) + | |
scale_color_manual(values=c("red", "black", "black")) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to select the columns I need | |
rename_fct <- function(data, oldnames, newnames){ | |
data_names <- colnames(data) | |
data_names[which(data_names %in% oldnames)] <- newnames | |
colnames(data) <- data_names | |
data | |
} | |
data <- rename_fct(df, c("PAT_CODE", "WARD_CODE", "START_DATETIME", "END_DATETIME", "AGE_BAND", "SEX", "episode.order", "spell.end.ward"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dput(head(ae_att_df, 10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################ | |
# calculating total time by using difftime - length of stay | |
################################ | |
dt_los <- dt_subset %>% | |
mutate(LOS = as.numeric(difftime(end_datetime, start_datetime, units = c("days")))) %>% # or minutes? | |
select(pat_code, LOS, admission.type, disch.ward.type) %>% | |
na.omit() |
NewerOlder