From 1193e3da989fd5ae36c616823aaaada52372c6bd Mon Sep 17 00:00:00 2001 From: Georgia Date: Tue, 1 Oct 2019 17:55:09 -0400 Subject: [PATCH] 10012019 pm updates --- DAWBA_database_and_deletions.R | 8 +-- IRTA_Merge_Code.R | 94 ++++++++++++++++---------------- Update_databases_master_script.R | 3 +- 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/DAWBA_database_and_deletions.R b/DAWBA_database_and_deletions.R index 2ba1a0d..29053b4 100644 --- a/DAWBA_database_and_deletions.R +++ b/DAWBA_database_and_deletions.R @@ -27,11 +27,11 @@ if (exists("master_IRTA_screens_latest")==FALSE) { print("master current screens tracker already imported") } -if (exists("master_IRTA_old_screens_latest")==FALSE) { - master_IRTA_old_screens_latest <- read_excel(paste0(IRTA_tracker_location, "OLD_REFERRALS_DATABASE.xlsx")) +if (exists("master_IRTA_oldest_screens_latest")==FALSE) { + master_IRTA_oldest_screens_latest <- read_excel(paste0(IRTA_tracker_location, "OLD_REFERRALS_DATABASE.xlsx")) date_variabes <- c("DOB", "Screening_Start_Date", "Referral_Date", "Consent_Date", "Clinical_Visit_Date", "Clinicals_date", "Overall_date") for(i in seq_len(max_tasks)) { date_variabes <- c(date_variabes, paste0("Task", i, "_Date"))} - master_IRTA_old_screens_latest[date_variabes] <- lapply(master_IRTA_old_screens_latest[date_variabes], as.Date) + master_IRTA_oldest_screens_latest[date_variabes] <- lapply(master_IRTA_oldest_screens_latest[date_variabes], as.Date) rm(i, date_variabes) } else { print("master old referrals tracker already imported") @@ -55,7 +55,7 @@ master_current_screen_identifiers <- master_IRTA_screens_latest %>% Parent_e_consented, Child_e_assented, Parent_DAWBA_completed, Child_DAWBA_completed, DAWBA_completed) %>% mutate(Source = "Current screens") %>% filter(!is.na(DAWBA_ID) | !is.na(PLUSID)) -master_old_screen_identifiers <- master_IRTA_old_screens_latest %>% +master_old_screen_identifiers <- master_IRTA_oldest_screens_latest %>% select(FIRST_NAME, LAST_NAME, Initials, DAWBA_ID, PLUSID, SDAN, IRTA_tracker, Participant_Type2, Clinical_Visit_Date, Screening_Start_Date, Referral_Date, Overall_date, Eligible, Eligibility_notes, Scheduling_status, Scheduling_status_notes, diff --git a/IRTA_Merge_Code.R b/IRTA_Merge_Code.R index ccc6b53..9983ad1 100644 --- a/IRTA_Merge_Code.R +++ b/IRTA_Merge_Code.R @@ -191,7 +191,7 @@ master_IRTA_reordered <- master_IRTA_reordered %>% select(-Clinical_Visit_Code2, irta_tracker_columns <- read_excel(paste0(IRTA_tracker_location, "other_data_never_delete/irta_tracker_columns.xlsx")) master_IRTA_latest <- master_IRTA_reordered %>% select(irta_tracker_columns$include) %>% arrange(Initials, Clinical_Visit_Date) master_IRTA_screens_latest <- master_IRTA_screens_reordered %>% select(irta_tracker_columns$include) %>% arrange(Initials, Referral_Date) -master_IRTA_old_screens_latest <- master_IRTA_old_screens_reordered %>% select(irta_tracker_columns$include) %>% arrange(Referral_Date) +master_IRTA_oldest_screens_latest <- master_IRTA_old_screens_reordered %>% select(irta_tracker_columns$include) %>% arrange(Referral_Date) ####################Chris's here..... @@ -378,50 +378,50 @@ MID_missing[of_interest] <- lapply(MID_missing[of_interest], na_if, '666') MID_missing %>% write_xlsx(paste0(IRTA_tracker_location,"MID_check.xlsx")) # if file empty, everything is perfect ###################################################################################### -#######Adding MRI QC information - -MEG_tasks <- c("MEG_MMI", "Booster", "RL_GNG") - -for(i in seq_along(MEG_tasks)) { - iter <- as.numeric(i) - # iter=1 - - temp_MEG_data <- read_excel(paste0(MEG_tracker_location, "MEG_Tracker.xlsx"), sheet = MEG_tasks[iter]) %>% - mutate_all(as.character) %>% mutate(MEG_tab=meg_task_name) - assign(paste0("task_", iter, "_meg_data"), temp_MEG_data) - -} - -# merge & tidy up - -rm(temp_MEG_data) -meg_sets <- ls(pattern="_meg_data") -meg_sets <- mget(meg_sets) -meg_combined <- reduce(meg_sets, full_join) %>% rename(Participant_Type = "Group") %>% rename(Task_Date = "taskDate") %>% - rename(Task_Time = "taskTime") %>% rename(SEX = "Sex") %>% rename(Age_at_visit = "Age") %>% rename(IRTA_tracker = "IRTA Contact") %>% - rename(TI_moved = "T1 moved to MEG directory") %>% rename(T1_notes = "T1 Image Notes") - -meg_reshape_master = data.frame(matrix(ncol = 23, nrow = 0)) -x <- c("Initials", "SDAN", "MRN", "SEX", "Age_at_visit", "Participant_Type", "MEG_tab", "IRTA_tracker", "Experimenter1", "Experimenter2", - "Photo_PII_Removal", "Earnings", "Scan_Notes", "Scheduling_Notes", "Recent_MPRAGE", - "TI_moved", "T1_notes", "GNGNotes", "Task_Name", "Task_Number", "Task_Date", "Task_Time", "Include") -colnames(meg_reshape_master) <- x - -for(j in seq_len(max_MEG)) { - iter <- as.numeric(j) - # iter=1 - - meg_reshape <- meg_combined %>% - select(Initials, SDAN, MRN, SEX, Age_at_visit, Participant_Type, MEG_tab, IRTA_tracker, Experimenter1, Experimenter2, - Photo_PII_Removal, Earnings, Scan_Notes, Scheduling_Notes, Recent_MPRAGE, TI_moved, T1_notes, GNGNotes, - Task_Date, Task_Time, paste0("Task", iter, "_Name"), paste0("Task", iter, "_Number"), paste0("Task", iter, "_Include")) - - names(meg_reshape)[names(meg_reshape) == paste0("Task", iter, "_Name")] <- "Task_Name" - names(meg_reshape)[names(meg_reshape) == paste0("Task", iter, "_Number")] <- "Task_Number" - names(meg_reshape)[names(meg_reshape) == paste0("Task", iter, "_Include")] <- "Include" - - meg_reshape_master <- merge.default(meg_reshape_master, meg_reshape, all=TRUE) - } +#######Adding MEG QC information + +# MEG_tasks <- c("MEG_MMI", "Booster", "RL_GNG") +# +# for(i in seq_along(MEG_tasks)) { +# iter <- as.numeric(i) +# # iter=1 +# +# temp_MEG_data <- read_excel(paste0(MEG_tracker_location, "MEG_Tracker.xlsx"), sheet = MEG_tasks[iter]) %>% +# mutate_all(as.character) %>% mutate(MEG_tab=meg_task_name) +# assign(paste0("task_", iter, "_meg_data"), temp_MEG_data) +# +# } +# +# # merge & tidy up +# +# rm(temp_MEG_data) +# meg_sets <- ls(pattern="_meg_data") +# meg_sets <- mget(meg_sets) +# meg_combined <- reduce(meg_sets, full_join) %>% rename(Participant_Type = "Group") %>% rename(Task_Date = "taskDate") %>% +# rename(Task_Time = "taskTime") %>% rename(SEX = "Sex") %>% rename(Age_at_visit = "Age") %>% rename(IRTA_tracker = "IRTA Contact") %>% +# rename(TI_moved = "T1 moved to MEG directory") %>% rename(T1_notes = "T1 Image Notes") +# +# meg_reshape_master = data.frame(matrix(ncol = 23, nrow = 0)) +# x <- c("Initials", "SDAN", "MRN", "SEX", "Age_at_visit", "Participant_Type", "MEG_tab", "IRTA_tracker", "Experimenter1", "Experimenter2", +# "Photo_PII_Removal", "Earnings", "Scan_Notes", "Scheduling_Notes", "Recent_MPRAGE", +# "TI_moved", "T1_notes", "GNGNotes", "Task_Name", "Task_Number", "Task_Date", "Task_Time", "Include") +# colnames(meg_reshape_master) <- x +# +# for(j in seq_len(max_MEG)) { +# iter <- as.numeric(j) +# # iter=1 +# +# meg_reshape <- meg_combined %>% +# select(Initials, SDAN, MRN, SEX, Age_at_visit, Participant_Type, MEG_tab, IRTA_tracker, Experimenter1, Experimenter2, +# Photo_PII_Removal, Earnings, Scan_Notes, Scheduling_Notes, Recent_MPRAGE, TI_moved, T1_notes, GNGNotes, +# Task_Date, Task_Time, paste0("Task", iter, "_Name"), paste0("Task", iter, "_Number"), paste0("Task", iter, "_Include")) +# +# names(meg_reshape)[names(meg_reshape) == paste0("Task", iter, "_Name")] <- "Task_Name" +# names(meg_reshape)[names(meg_reshape) == paste0("Task", iter, "_Number")] <- "Task_Number" +# names(meg_reshape)[names(meg_reshape) == paste0("Task", iter, "_Include")] <- "Include" +# +# meg_reshape_master <- merge.default(meg_reshape_master, meg_reshape, all=TRUE) +# } # meg_reshape_master %>% write_xlsx(paste0(IRTA_tracker_location,"meg_tracker_rough.xlsx")) @@ -453,8 +453,8 @@ master_IRTA_screens_latest %>% write_xlsx(paste0(backup_location,"REFERRAL_AND_S ###################################################################################### #######Saving Old Screens Dataset -master_IRTA_old_screens_latest %>% write_xlsx(paste0(IRTA_tracker_location,"OLD_REFERRALS_DATABASE.xlsx")) -master_IRTA_old_screens_latest %>% write_xlsx(paste0(backup_location,"OLD_REFERRALS_DATABASE","_",todays_date_formatted,".xlsx")) +master_IRTA_oldest_screens_latest %>% write_xlsx(paste0(IRTA_tracker_location,"OLD_REFERRALS_DATABASE.xlsx")) +master_IRTA_oldest_screens_latest %>% write_xlsx(paste0(backup_location,"OLD_REFERRALS_DATABASE","_",todays_date_formatted,".xlsx")) #####Removing unnecessary variables diff --git a/Update_databases_master_script.R b/Update_databases_master_script.R index 5fd9782..8c122a5 100644 --- a/Update_databases_master_script.R +++ b/Update_databases_master_script.R @@ -5,7 +5,7 @@ rm(list = ls()) # command to clear all variables from R environment # directories ------------------------------------------------------------- # what device are you running this script on? -computer = 'mac' # set this to either 'mac' or 'pc' or 'other' (Georgia = W:/ as I have string mounted differently) +computer = 'pc' # set this to either 'mac' or 'pc' or 'other' (Georgia = W:/ as I have string mounted differently) if (computer=="pc") { string = 'W:/' @@ -73,6 +73,7 @@ suppressPackageStartupMessages(library(purrr)) suppressPackageStartupMessages(library(tidyverse)) suppressPackageStartupMessages(library(shiny)) suppressPackageStartupMessages(library(knitr)) +suppressPackageStartupMessages(library(ggpubr)) # things to check and may need to modify before running -------------------