From b12ae3fd5f1c0f43aa649cca89d2181439c793c7 Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Mon, 28 Mar 2022 14:52:04 +0200 Subject: [PATCH] =?UTF-8?q?Introducci=C3=B3n=20de=20un=20bot=C3=B3n=20para?= =?UTF-8?q?=20actualizar=20nitr=C3=B3geno.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BDAccess/app.R | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/BDAccess/app.R b/BDAccess/app.R index e360628..b4ba8bb 100644 --- a/BDAccess/app.R +++ b/BDAccess/app.R @@ -1,5 +1,6 @@ library(shiny) library(rhandsontable) +library(BDCIT) print(getwd()) source("../sqlFunctions.R", encoding = "UTF-8") @@ -53,6 +54,7 @@ ui <- fluidPage( choices = list("NHC" = 1, "UMID/OVID" = 2, "UM/OV"=3), selected = 2), textInput("id", label = "ID", value = ""), + actionButton("nitrosync", "Sincroniza Nitrógeno") ), mainPanel( htmlOutput("report"), @@ -675,6 +677,92 @@ server <- function(input, output) { nitro }) + observeEvent(input$nitrosync, { + + if (input$dbtype == "UM"){ + ## Copia de backup + + if (!dir.exists(NitroRoute)){ + dir.create(NitroRoute) + print(paste0("Back Up directory ", NitroRoute, " created")) + } + + write.xlsx( + sqlFetch(dta, "NITROGEN"), + file=paste0(NitroRoute, format(Sys.time(), format="%Y%m%d"),"-","UM-Nitrogen.xlsx") + ) + + table<-read.xlsx(paste0(gsub("/BU_NITRO/", "", NitroRoute),"/Nitrogen_ICO.xlsx")) + + table.um<-table %>% filter( grepl("UM|MU", Nombre) | grepl("Met|Prim|hep|Enn",Nombre, ignore.case = T) | + Nombre == "TILs f. 21/09/20" | Nombre == "TILS DISG f. 03/07/20") + + table.um<-add_column(table.um,.before=1, "CODIGO"=str_extract(table.um$Nombre, "UM[0-9]{4}")) + + table.samp<-sqlQuery(dta, "SELECT U.NHC,M.* FROM MUESTRAS M INNER JOIN UMID U ON M.UMID=U.UMID") + table.samp$FECHA_RECEPCION<-table.samp$FECHA_RECEPCION+24*60*60 + + + table.um<-add_column(table.um, .after=1, + "FECHA"=str_extract(table.um$Nombre, "[0-9]{2}[\\./][0-9]{2}[\\./][0-9]{2}") %>% gsub("\\.","/",.)) + table.um$FECHA<-as.POSIXct(table.um$FECHA, format="%d/%m/%y") + + table.um<-merge(table.um, table.samp %>% select(CODIGO,FECHA_RECEPCION), by.x="FECHA", by.y="FECHA_RECEPCION", all.x=T) + table.um<-table.um %>% mutate(CODIGO=case_when(is.na(CODIGO.x)~CODIGO.y, TRUE~CODIGO.x), .before=1) %>% select(-CODIGO.x,-CODIGO.y) + + table.um[table.um$Nombre == "MU Met f. 10/02/20","CODIGO"]<-"UM0009" + table.um[table.um$Nombre == "TILs Diss Met","CODIGO"]<-"UM0020" + table.um[table.um$Nombre == "UM Met","CODIGO"]<-"UM0020" + table.um[table.um$Nombre == "UM MET NHC 11489341","CODIGO"]<-"UM0044" + table.um[table.um$Nombre == "UM Primary 20278822","CODIGO"]<-"UM0029" + table.um[table.um$Nombre == "Hip Nod Hep NHC11489341","CODIGO"]<-"UM0044" + + ## Actualización + + sqlDrop(dta, "NITROGEN") + sqlSave(dta, table.um %>% select(-FECHA) %>% filter(!is.na(CODIGO)), tablename="NITROGEN", rownames=F) + } + if (input$dbtype == "OV"){ + ## Copia de backup + + if (!dir.exists(NitroRoute)){ + dir.create(NitroRoute) + print(paste0("Back Up directory ", NitroRoute, " created")) + } + + write.xlsx( + sqlFetch(dta, "NITROGEN"), + file=paste0(NitroRoute, format(Sys.time(), format="%Y%m%d"),"-","OV-Nitrogen.xlsx") + ) + + ## Lectura del excel + table<-read.xlsx(paste0(gsub("/BU_NITRO/", "", NitroRoute),"/Nitrogen_ICO.xlsx")) + + table.ov<-table %>% filter(grepl("OV",Nombre)) + table.ov<-filter(table.ov, !grepl("OVA",Nombre)) + + table.ov<-add_column(table.ov,.before=1, "CODIGO"=str_extract(table.ov$Nombre, "OV[0-9]{4}")) + table.ov[table.ov$Nombre == "Ascitis OV","CODIGO"]<-"OV2105" + + table.ov<-table.ov %>% add_column(SampType=NA, .after=1) + table.ov[grepl("TIL",table.ov$Nombre, ignore.case = T),"SampType"]<-"TILs" + table.ov[grepl("frag",table.ov$Nombre, ignore.case = T)|grepl("frag",table.ov$Observaciones, ignore.case = T),"SampType"]<-"FRAG" + table.ov[grepl("slide",table.ov$Nombre, ignore.case = T)|grepl("slide",table.ov$Observaciones, ignore.case = T),"SampType"]<-"SLIDE" + table.ov[(is.na(table.ov$SampType) | !(table.ov$SampType == "TILs")) & + (grepl("disg|diss",table.ov$Nombre, ignore.case = T)| + grepl("disg|diss",table.ov$Observaciones, ignore.case = T)),"SampType"]<-"DISG" + table.ov[table.ov$Nombre == "Ascitis OV", "SampType"]<-"ASC" + table.ov[20:25,"SampType"]<-"DISG" + table.ov[63:68,"SampType"]<-"DISG" + + ## Actualización + + sqlDrop(dta, "NITROGEN") + sqlSave(dta, table.ov, tablename="NITROGEN", rownames=F) + } + + }) + ## scRNAseq }