Minor additions to include cpr and forloeabid for new entries
This commit is contained in:
parent
ea0f8f6e1e
commit
cd00ade74d
@ -63,8 +63,40 @@ for (i in 1:length(r_lup)){
|
||||
cnames<-c(cnames,colnames(r_lup[[i]]))
|
||||
}
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Fix missing record_id's for upload
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
## REDCap pull with minimum data
|
||||
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,
|
||||
# forms = "ID",
|
||||
fields = c("record_id","forloebid")
|
||||
)$data|>
|
||||
filter(record_id %in% 1:204) # Selecting only the first 204
|
||||
|
||||
## Adding and creating record_id's
|
||||
ids_r<-full_join(ids,redcap)
|
||||
|
||||
n_na<-length(ids_r$record_id[is.na(ids_r$record_id)])
|
||||
n_id<-max(ids_r$record_id,na.rm=T)
|
||||
# filter(!is.na(akut_ind))%>%
|
||||
ids_r$record_id[is.na(ids_r$record_id)]<-(n_id+1):(n_id+n_na) # Simple math
|
||||
|
||||
for (i in 1:length(r_lup)){
|
||||
r_lup[[i]]<-left_join(r_lup[[i]],ids_r)
|
||||
}
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Appending suffix for duplicated colnames from different sheets
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
dup_names<-unique(cnames[duplicated(cnames)])[-1] # omit the first, "forloebid"
|
||||
|
||||
for (i in 1:length(r_lup)){
|
||||
@ -82,32 +114,14 @@ for (i in 1:length(r_lup)){
|
||||
}
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Fix missing record_id's for upload
|
||||
## Creating ID instrument data - fidly!
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
## REDCap pull with minimum data
|
||||
token=names(suppressWarnings(read.csv("/Users/au301842/nottreated_redcap_token.csv",colClasses = "character")))
|
||||
uri="https://redcap.au.dk/api/"
|
||||
id_data<-read_excel("/Volumes/Data/toorisky/2022-02-08_ddsc_dataexport.xlsx", sheet = "Patienter")|>
|
||||
select(c("cpr","forloebid"))|>
|
||||
filter(forloebid %in% r_lup$Patienter$forloebid)|>
|
||||
full_join(ids_r)
|
||||
|
||||
library(REDCapR)
|
||||
|
||||
redcap <- redcap_read_oneshot(
|
||||
redcap_uri = uri,
|
||||
token = token,
|
||||
fields = c("record_id","forloebid")
|
||||
)$data
|
||||
|
||||
## Adding and creating record_id's
|
||||
ids_r<-full_join(ids,redcap)
|
||||
|
||||
n_na<-length(ids_r$record_id[is.na(ids_r$record_id)])
|
||||
n_id<-max(ids_r$record_id,na.rm=T)
|
||||
# filter(!is.na(akut_ind))%>%
|
||||
ids_r$record_id[is.na(ids_r$record_id)]<-(n_id+1):(n_id+n_na) # Simple math
|
||||
|
||||
for (i in 1:length(r_lup)){
|
||||
r_lup[[i]]<-left_join(r_lup[[i]],ids_r)
|
||||
}
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Data dictionary
|
||||
@ -198,22 +212,8 @@ for (i in 1:length(inst_names)){
|
||||
exp<-r_lup|>
|
||||
purrr::reduce(full_join)|>
|
||||
select(-matches("forloebid"))|>
|
||||
select(record_id,everything()) # To arrange "record_id" as first column
|
||||
select(record_id,everything())|> # To arrange "record_id" as first column
|
||||
full_join(id_data) # Adding cpr and forloebid to the newly added
|
||||
|
||||
write.csv(exp,"ddsc_dataset.csv",row.names = FALSE,na="")
|
||||
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## Dataset export of remaing
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
## REDCap faces troubles importing too large data sets. Apparently.
|
||||
|
||||
ups <- redcap_read_oneshot(
|
||||
redcap_uri = uri,
|
||||
token = token,
|
||||
fields = "record_id"
|
||||
)$data
|
||||
|
||||
write.csv(exp|>
|
||||
filter(!record_id %in% ups$record_id),"ddsc_dataset_remain.csv",row.names = FALSE,na="")
|
||||
|
Loading…
Reference in New Issue
Block a user