Skip to content

Commit

Permalink
10012019 pm updates
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiaoc committed Oct 1, 2019
1 parent fb49423 commit 1193e3d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 52 deletions.
8 changes: 4 additions & 4 deletions DAWBA_database_and_deletions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
94 changes: 47 additions & 47 deletions IRTA_Merge_Code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.....

Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion Update_databases_master_script.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:/'
Expand Down Expand Up @@ -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 -------------------

Expand Down

0 comments on commit 1193e3d

Please sign in to comment.