first commit
This commit is contained in:
parent
69ff6e802f
commit
31b9a01498
125
conversion_upload.R
Normal file
125
conversion_upload.R
Normal file
@ -0,0 +1,125 @@
|
||||
## -----------------------------------------------------------------------------
|
||||
## Data conversion and upload
|
||||
## -----------------------------------------------------------------------------
|
||||
##
|
||||
## This script is to create a datadictionary for REDCap, to upload data.
|
||||
##
|
||||
##
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Setup
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
library(haven)
|
||||
library(readxl)
|
||||
library(dplyr)
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Data
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
setwd("/Volumes/Data/toorisky/")
|
||||
|
||||
dta_ls<-list()
|
||||
dta_ls[1]<-read_dta("Alle apo Aarhus 2018.dta") %>% filter(VaskDiag==1) %>%
|
||||
mutate(treatment=factor(case_when(trombolyse!=2&trombektomi!=2 ~ 0,
|
||||
trombolyse==2|trombektomi==2 ~ 1)),
|
||||
sex.n=factor(ifelse(as.integer(substr(cpr, start = 10, stop = 10)) %%2 == 0,
|
||||
"female", "male"))) %>%
|
||||
left_join(.,read_excel("2022-02-08_ddsc_dataexport.xlsx", sheet = "Patienter"),
|
||||
by=c("ForloebID"="forloebid","cpr"="cpr"))
|
||||
|
||||
|
||||
|
||||
dta_ls[2]<-read_excel("2022-02-08_ddsc_dataexport.xlsx", sheet = "3 mdr. opf.") # This excludes patients not treated and not candidates, but included by mistake in the register. Manually adjusted.
|
||||
## Her mangler filter for kun at inkludere dem, fra baseline
|
||||
|
||||
setwd("/Users/au301842/nottreated/")
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Data dictionary
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
icname<-colnames(read.csv("examlpe instrument.csv"))
|
||||
dd<-data.frame(matrix(ncol = length(icname))) ## Data frame to collect all
|
||||
colnames(dd)<-icname
|
||||
|
||||
## Tilpasses
|
||||
## -----------------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
for (i in 1:length(r_lup)){
|
||||
dd_i<-data.frame(matrix(ncol = length(icname),nrow = ncol("[["(r_lup,i)))) ## Data frame to collect all
|
||||
|
||||
colnames(dd_i)<-icname ## for easier reading
|
||||
|
||||
## Variable names
|
||||
dd_i[1]<-colnames("[["(r_lup,i))
|
||||
|
||||
## Form Name
|
||||
dd_i[2]<-names(r_lup)[i]
|
||||
|
||||
## Field Type
|
||||
# dd_i[4]<-ifelse(sapply(r_lup[[i]], class)=="factor","radio","text")
|
||||
dd_i[4]<-"text"
|
||||
|
||||
## Field Label
|
||||
## Using original attributes as field labels
|
||||
fl<-lapply(r_lup[[i]], attr, "label")
|
||||
for (j in 1:length(fl)){
|
||||
fl[[j]]<-ifelse(is.null(fl[[j]]),
|
||||
names(fl)[[j]],
|
||||
fl[[j]])
|
||||
## If no attributes, variable name is used as "placeholder"
|
||||
}
|
||||
dd_i[5]<-unlist(fl)
|
||||
|
||||
## Choices
|
||||
# for (j in 1:ncol(r_lup[[i]])){
|
||||
# if (is.factor(r_lup[[i]][[j]])){
|
||||
# lvl<-levels(r_lup[[i]][[j]])
|
||||
# lvl_ch<-paste("1,",lvl[1])
|
||||
# for (k in 2:length(lvl)){
|
||||
# lvl_ch<-c(paste0(lvl_ch," | ",k,", ",lvl[k]))
|
||||
# }
|
||||
# dd_i[j,6]<-lvl_ch
|
||||
# }
|
||||
# }
|
||||
|
||||
## Text Validation
|
||||
## Only used for date and time data
|
||||
# for (j in 1:ncol(r_lup[[i]])){
|
||||
# dd_i[j,8]<-case_when(class(r_lup[[i]][[j]])[1]%in%c("POSIXct","POSIXt") ~"datetime_seconds_ymd",
|
||||
# class(r_lup[[i]][[j]])[1]%in%c("Date") ~"date_ymd")
|
||||
# }
|
||||
|
||||
## Merge all
|
||||
dd<-rbind(dd,dd_i)
|
||||
|
||||
if (exp_out){
|
||||
# dir.create(file.path("/Volumes/Data/REDCap/data",names(r_lup)[[i]]))
|
||||
write.csv(r_lup[[i]],paste0("/Volumes/Data/REDCap/data/",names(r_lup)[[i]],".csv"),row.names = FALSE)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## REDCap pull
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
token=names(suppressWarnings(read.csv("/Users/au301842/nottreated_redcap_token.csv",colClasses = "character")))
|
||||
uri="https://redcap.au.dk/api/"
|
||||
|
||||
library(REDCapR)
|
||||
|
||||
redcap <- redcap_read_oneshot(
|
||||
redcap_uri = uri,
|
||||
token = token
|
||||
)$data
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Data preparation
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
|
15
examlpe instrument.csv
Normal file
15
examlpe instrument.csv
Normal file
@ -0,0 +1,15 @@
|
||||
"Variable / Field Name","Form Name","Section Header","Field Type","Field Label","Choices, Calculations, OR Slider Labels","Field Note","Text Validation Type OR Show Slider Number","Text Validation Min","Text Validation Max",Identifier?,"Branching Logic (Show field only if...)","Required Field?","Custom Alignment","Question Number (surveys only)","Matrix Group Name","Matrix Ranking?","Field Annotation"
|
||||
record_id,registrering,,text,"Record ID",,,,,,,,,,,,,
|
||||
incl_date,registrering,,text,"Dato for inkludering",,,date_dmy,,,,,y,,,,,
|
||||
cpr,registrering,,text,CPR,,ddmmyy-xxxx,dk_cpr_dash,,,y,,y,,,,,
|
||||
first_name,registrering,,text,Fornavn,,,,,,y,,y,,,,,
|
||||
last_name,registrering,,text,Efternavn(e),,,,,,y,,y,,,,,
|
||||
incl_by,registrering,,dropdown,"Initialer for vedkommende, der har inkluderet pt","1, JKM | 2, SBV | 3, AGD | 4, BWD | 5, MLF | 6, RBT | 7, SJ | 8, KZ",,autocomplete,,,,,y,,,,,
|
||||
critical_info,registrering,Samtykke,radio,"Har patienten frabedt sig information om nye væsentlige helbredsoplysninger?","1, Ja | 2, Nej",,,,,,,y,,,,,
|
||||
project_results,registrering,,radio,"Ønsker patienten information om projektets resultater?","1, Ja | 2, Nej",,,,,,,y,,,,,
|
||||
resist_incl,registrering,,radio,"Er pt også inkluderet i RESIST?","1, Ja | 2, Nej | 99, Uoplyst",,,,,,,,,,,,
|
||||
resist_id,registrering,,text,"RESIST ID",,,,,,,"[resist_incl] = '1'",,,,,,
|
||||
incl_mr,registrering,"MR-skanning ved inklusion",radio,"MR-skanning efter ENIGMA protokol","1, MR udført | 2, MR IKKE udført | 99, Uoplyst","Er MR-skanning udført efter ENIGMA-protokol",,,,,,,,,,,
|
||||
incl_book3,registrering,"Booking af 3 mdr. kontrolbesøg",text,"Tidspunkt for booking af 3 mdr. kontrol",,"Angiv tidspunkt for booking af 3 mdr. kontrol",datetime_dmy,,,,,,,,,,
|
||||
incl_room3,registrering,,radio,"Lokale til kontrol","1, J109-139 | 2, J109-141 | 3, Andet",,,,,,,,RH,,,,
|
||||
incl_other3,registrering,,text,"Angiv andet lokalenummer",,,,,,,"[incl_room3] = '3'",,RH,,,,
|
|
13
nottreated.Rproj
Normal file
13
nottreated.Rproj
Normal file
@ -0,0 +1,13 @@
|
||||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
Loading…
x
Reference in New Issue
Block a user