From 5ea3b493f4d965b4e33dab337d4bdafc83278ab0 Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Tue, 22 Mar 2022 14:25:17 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20la=20sincronizaci=C3=B3n=20de=20t?= =?UTF-8?q?ablas=20para=20CC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BDAccess/app.R | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/BDAccess/app.R b/BDAccess/app.R index 3ecc064..bfde515 100644 --- a/BDAccess/app.R +++ b/BDAccess/app.R @@ -520,6 +520,77 @@ server <- function(input, output) { sqlSave(dta, clinics.new, tablename="CLINICS", append = T, varTypes = varTypes, rownames = F) print("Tabla CLINICS sincronizada.") } + if (input$dbtype %in% c("CC")){ + ## Nuevas entradas en MUESTRAS + nsamples<-values[["samples"]] %>% nrow + upd.samples<-values[["samples"]] + if (nrow(upd.samples) > 0){rownames(upd.samples)<-(nsamples+1):(nsamples+nrow(upd.samples)) %>% as.character} + + if (nrow(upd.samples) > 0){ + upd.samples$FECHA_RECEPCION<-lubridate::parse_date_time(upd.samples$FECHA_RECEPCION, c("d/m/Y","d/m/y")) %>% as.Date() + upd.samples$TIPO<-as.character(upd.samples$TIPO) + upd.samples$OBS<-as.character(upd.samples$OBS) + ### !! Atención, esto cambia la base de datos: + sqlSave(dta, upd.samples, tablename="MUESTRAS", append = T, varTypes = c("FECHA_RECEPCION"="Date"), rownames = F) + print("Tabla MUESTRAS sincronizada.") + } + + ## Entradas modificadas en CLINICOS + upd.clinics<-values[["CLINICS"]] + PATID.mod<-upd.clinics$PATID[upd.clinics$PATID %in% (sqlFetch(dta, "CLINICOS") %>% pull(PATID))] + rnames<-sqlFetch(dta, "CLINICOS") %>% filter(PATID %in% PATID.mod) %>% rownames + clinics.mod<-upd.clinics %>% filter(PATID %in% PATID.mod) %>% select(-NHC) + rownames(clinics.mod)<-rnames + + ### !! Atención, esto cambia la base de datos: + fechas<-colnames(clinics.mod)[grepl("date|MET_DX|DoB", colnames(clinics.mod), ignore.case = T)] + for (i in fechas){ + clinics.mod[,i]<-lubridate::parse_date_time(clinics.mod[,i], c("d/m/Y","d/m/y")) %>% as.Date() + } + sqlUpdate(dta, clinics.mod,"CLINICOS", index="PATID") + print("Tabla CLINICOS modificada.") + + ## Nuevas entradas en CLINICOS + nsamples.clin<-sqlFetch(dta, "CLINICOS") %>% nrow + PATID.new<-upd.clinics$PATID[!upd.clinics$PATID %in% (sqlFetch(dta, "CLINICOS") %>% pull(PATID))] + clinics.new<-upd.clinics %>% filter(PATID %in% PATID.new) %>% select(-NHC) + if (length(PATID.new) > 0){rownames(clinics.new)<-(nsamples.clin+1):(nsamples.clin+nrow(clinics.new)) %>% as.character} + + ### !! Atención, esto cambia la base de datos: + fechas<-colnames(clinics.new)[grepl("date|MET_DX|DoB", colnames(clinics.new), ignore.case = T)] + varTypes<-rep("Date",length(fechas)) + names(varTypes)<-fechas + for (i in fechas){ + clinics.new[,i]<-lubridate::parse_date_time(clinics.new[,i], c("d/m/Y","d/m/y","Y-m-d")) %>% as.Date() + } + sqlSave(dta, clinics.new, tablename="CLINICOS", append = T, varTypes = varTypes, rownames = F) + print("Tabla CLINICOS sincronizada.") + + ## Nuevas entradas en CNAG + if (nrow(values[["cnag"]]) > 0){ + cnag.sync<-values[["cnag"]] + fechas<-colnames(cnag.sync)[sqlFetch(dta, "CNAG") %>% sapply(lubridate::is.POSIXct)] + varTypes<-rep("Date",length(fechas)) + names(varTypes)<-fechas + print(fechas) + for (i in fechas){ + cnag.sync[,i]<-lubridate::parse_date_time(cnag.sync[,i], c("d/m/Y","d/m/y","Y-m-d")) %>% as.Date() + } + sqlSave(dta, cnag.sync, tablename="CNAG", append = T, varTypes = varTypes, rownames = F) + } + + ## Nuevas entradas en RNADNA + if (nrow(values[["rna"]]) > 0){ + rna.sync<-values[["rna"]] + fechas<-colnames(rna.sync)[sqlFetch(dta, "RNADNA") %>% sapply(lubridate::is.POSIXct)] + varTypes<-rep("Date",length(fechas)) + names(varTypes)<-fechas + for (i in fechas){ + rna.sync[,i]<-lubridate::parse_date_time(rna.sync[,i], c("d/m/Y","d/m/y","Y-m-d")) %>% as.Date() + } + sqlSave(dta, rna.sync, tablename="RNADNA", append = T, varTypes = varTypes, rownames = F) + } + } }) ## Visor