Skip to content

Instantly share code, notes, and snippets.

View gabrielburcea's full-sized avatar

GabrielBurcea gabrielburcea

View GitHub Profile
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)
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 %>%
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 %>%
@gabrielburcea
gabrielburcea / gist:465aaa7214daf81c8b4f007c920ade57
Created January 8, 2019 14:04
length of stay with stacked bars - with reduced bins
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)
@gabrielburcea
gabrielburcea / gist:c9b7f8700f0b04c2b962b7f155f508ab
Created January 8, 2019 13:59
length of stay with stacked bars
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)
# 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)
@gabrielburcea
gabrielburcea / gist:38230487a4481298126b4c1c1176f4b4
Created September 19, 2018 14:08
ggplot overlayed lines.
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")) +
@gabrielburcea
gabrielburcea / gist:78fa55fa630384f4232adade65729390
Created August 29, 2018 14:25
Rename of the variables function
# 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"),
@gabrielburcea
gabrielburcea / Reproducible example of a dataframe
Created August 29, 2018 10:03
How to reproduce a dataframe
dput(head(ae_att_df, 10))
@gabrielburcea
gabrielburcea / LOS
Created August 22, 2018 14:54
Calculate the Length of stay
############################
# 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()