|
@ -47,23 +47,37 @@ sqlShowSamples<-function(conn=dta, nhcs=nhc.test, verb=F, dbtype){ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sqlGenOVID<-function(conn=dta, nhcs=nhc.test, verb=T, sinc=F){ |
|
|
|
|
|
ovid<-sqlFetch(conn,"OVID") |
|
|
|
|
|
|
|
|
sqlGenOVID<-function(conn=dta, nhcs=nhc.test, verb=T, sinc=F, dbtype){ |
|
|
|
|
|
if (dbtype == "OV"){ |
|
|
|
|
|
db<-c("dbcode"="OVID") |
|
|
|
|
|
} |
|
|
|
|
|
if (dbtype == "UM"){ |
|
|
|
|
|
db<-c("dbcode"="UMID") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dbid<-sqlFetch(conn,db["dbcode"]) |
|
|
|
|
|
|
|
|
new.nhc<-nhcs[!nhcs %in% ovid$NHC] |
|
|
|
|
|
next.num<-gsub("OVID","",ovid$OVID) %>% as.numeric %>% max(na.rm=T)+1 |
|
|
|
|
|
|
|
|
new.nhc<-nhcs[!nhcs %in% dbid$NHC] |
|
|
|
|
|
next.num<-gsub(db["dbcode"],"",dbid[,db["dbcode"]]) %>% as.numeric %>% max(na.rm=T)+1 |
|
|
last.num<-next.num+(length(new.nhc)-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) %>% mutate(NHC=as.character(NHC)) |
|
|
|
|
|
|
|
|
newtab<-data.frame("NHC"=new.nhc, "ID"=sprintf("%s%04d",db["dbcode"],next.num:last.num)) %>% rename(!!db["dbcode"]:="ID") |
|
|
|
|
|
if(dbtype=="OV"){ |
|
|
|
|
|
dbid<-rbind(dbid,newtab) |
|
|
|
|
|
} |
|
|
|
|
|
if(dbtype=="UM"){ |
|
|
|
|
|
dbid<-merge(dbid, newtab, all=T) %>% select(Id,NHC,UMID) %>% arrange(Id) |
|
|
|
|
|
dbid$Id<-rownames(dbid) |
|
|
|
|
|
} |
|
|
|
|
|
rownames(dbid)<-as.character(1:nrow(dbid)) |
|
|
|
|
|
dbid<-filter(dbid, NHC %in% new.nhc) %>% mutate(NHC=as.character(NHC)) |
|
|
|
|
|
|
|
|
if (sinc){ |
|
|
if (sinc){ |
|
|
### !! Atención, esto cambia la base de datos: |
|
|
### !! Atención, esto cambia la base de datos: |
|
|
sqlSave(conn, upd.ovid, tablename="OVID", append = T) |
|
|
|
|
|
|
|
|
sqlSave(conn, dbid, tablename=db["dbcode"], append = T) |
|
|
print("La base ha sido actualizada.") |
|
|
print("La base ha sido actualizada.") |
|
|
} |
|
|
} |
|
|
if (verb){ |
|
|
if (verb){ |
|
|
return(upd.ovid) |
|
|
|
|
|
|
|
|
return(dbid) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -149,3 +163,21 @@ sqlSincBD<-function(conn=dta, filetemp="QueryOV.xlsx", sinc.samples=F, sinc.clin |
|
|
print("Tabla CLINICS sincronizada.") |
|
|
print("Tabla CLINICS sincronizada.") |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sqlMultiSamples<-function(kbl=F, NHC=F){ |
|
|
|
|
|
query<-sqlQuery(dta, "SELECT M.UMID,U.NHC,M.FECHA_RECEPCION,M.CODIGO,C.CODIGO,R.CODIGO |
|
|
|
|
|
FROM ((MUESTRAS M |
|
|
|
|
|
LEFT OUTER JOIN CNAG C ON M.CODIGO=C.CODIGO) |
|
|
|
|
|
LEFT OUTER JOIN RNADNA R ON M.CODIGO=R.CODIGO) |
|
|
|
|
|
LEFT OUTER JOIN UMID U ON U.UMID=M.UMID") %>% rename("CNAG"="CODIGO.1","RNADNA"="CODIGO.2") |
|
|
|
|
|
|
|
|
|
|
|
query<-query %>% mutate( |
|
|
|
|
|
CNAG=case_when(!is.na(CNAG)~"X",TRUE~""), |
|
|
|
|
|
RNADNA=case_when(!is.na(RNADNA)~"X",TRUE~"") |
|
|
|
|
|
) |
|
|
|
|
|
if (kbl==T){ |
|
|
|
|
|
query %>% kableExtra::kbl() %>% kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped")) |
|
|
|
|
|
}else{ |
|
|
|
|
|
return(query) |
|
|
|
|
|
} |
|
|
|
|
|
} |