From 260737bb1c35ecd0863ce91560109ad7bd0da06a Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Mon, 18 Oct 2021 15:06:41 +0200 Subject: [PATCH] Subir script i fichero para introducir queries. --- RellenarOVBD.R | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ queryOV.xlsx | Bin 0 -> 10591 bytes 2 files changed, 60 insertions(+) create mode 100644 RellenarOVBD.R create mode 100644 queryOV.xlsx diff --git a/RellenarOVBD.R b/RellenarOVBD.R new file mode 100644 index 0000000..e01177c --- /dev/null +++ b/RellenarOVBD.R @@ -0,0 +1,60 @@ +library(tidyverse) +library(RODBC) +library(openxlsx) + +dta<-odbcConnectAccess2007(access.file = "C:/Users/47926492N/OneDrive - IDIBELL - Institut d'Investigació Biomèdica de Bellvitge/RATG-PIULATS/OVARIO.accdb", + pwd = .rs.askForPassword("Enter password:")) + +nhc.test<-read.xlsx("queryOV.xlsx", sheet = "NHC") %>% pull(NHC) + +sqlQuery(dta, "SELECT O.NHC,S.* + FROM SAMPLES S + INNER JOIN OVID O + ON O.OVID=S.OVID") %>% filter(NHC %in% nhc.test) %>% + group_by(NHC,OVID) %>% summarise(Samples=length(samples), Names=paste0(samples, collapse = ";")) %>% merge(data.frame(NHC=nhc.test),all=T) + +sqlQuery(dta, "SELECT O.NHC,S.* + FROM SAMPLES S + INNER JOIN OVID O + ON O.OVID=S.OVID") %>% filter(NHC %in% nhc.test) + + +## Generar OVIDs para nuevos NHC +ovid<-sqlFetch(dta,"OVID") + +new.nhc<-nhc.test[!nhc.test %in% ovid$NHC] +next.num<-gsub("OVID","",ovid$OVID) %>% as.numeric %>% max(na.rm=T)+1 +last.num<-next.num+(length(new.nhc)-1) +upd.ovid<-rbind(ovid,data.frame("NHC"=new.nhc, "OVID"=sprintf("OVID%04d",next.num:last.num))) +rownames(upd.ovid)<-as.character(1:nrow(upd.ovid)) +upd.ovid<-filter(upd.ovid, NHC %in% new.nhc) +sqlSave(dta, upd.ovid, tablename="OVID", append = T) + +samples<-sqlFetch(dta, "SAMPLES") +if(sum(grepl(paste0("OV",Sys.time() %>% format("%y")), samples$samples)) > 0){ + next.samp<-gsub(paste0("OV",Sys.time() %>% format("%y")),"", samples$samples) %>% as.numeric %>% max(na.rm=T)+1 +}else{ + next.samp<-1 +} +last.samp<-next.samp+(length(nhc.test)-1) +new.samp<-sprintf("OV%s%02d",Sys.time() %>% format("%y"),next.samp:last.samp) +new.samp.df<-merge(sqlFetch(dta,"OVID") %>% merge(data.frame("NHC"=nhc.test)), data.frame("NHC"=nhc.test, "samples"=new.samp)) +samples.exp<-merge(samples %>% slice(0), new.samp.df %>% select(-NHC), all=T) %>% select(colnames(samples)) %>% arrange(samples) +samples.exp[is.na(samples.exp)]<-"" + +upd.clinics<-sqlFetch(dta, "CLINICS") +ovid.new<-sqlFetch(dta, "OVID") %>% filter(NHC %in% nhc.test) +upd.clinics<-merge(ovid.new,upd.clinics, all.x=T) +upd.clinics$NHC<-as.character(upd.clinics$NHC) +for (i in colnames(upd.clinics)[sapply(upd.clinics, lubridate::is.POSIXct)]){upd.clinics[,i]<-as.Date(upd.clinics[,i])} + +wb <- loadWorkbook("queryOV.xlsx") +writeData(wb, "NHC", upd.ovid) +writeData(wb,"samples",samples.exp) +writeData(wb,"CLINICS",upd.clinics) +saveWorkbook(wb,"queryOV.xlsx",overwrite = TRUE) + +nsamples<-sqlFetch(dta, "SAMPLES") %>% nrow +upd.samples<-read.xlsx("QuerySamplesOV.xlsx") +rownames(upd.samples)<-(nsamples+1):(nsamples+nrow(upd.samples)) %>% as.character +sqlSave(dta, upd.samples, tablename="SAMPLES", append = T) diff --git a/queryOV.xlsx b/queryOV.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..744a339a063f39044b530436ab5abfc7e45860a0 GIT binary patch literal 10591 zcmeHtWmFv5);0<5?hcI;+}+*Xg9fL8#@zzJ-Q7cQClK6&B)B^S2?Up*Uo-d4otezs zAK&lyRx+pT*>&H38f2>} zR$m-PxZ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