分疫苗分针次接种率
Sys.setenv(NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
library(ROracle)
library(tidyverse)
library(dbplyr)
library(knitr)
library(magrittr)
library(stringr)
library(lubridate)
library(janitor)
ym_jzl <- function(csrq_begin,csrq_end,static_date,ymbm,jzzc,month,jcqk,czlx,level,condition) {
static_date <- if_else(condition,static_date - ddays(12*30),static_date)
temp <- con %>%
tbl(in_schema('ipvsdb','GRDA_ET')) %>%
filter(between(CSRQ,to_date(csrq_begin,"YYYY-MM-DD"),
to_date(csrq_end,"YYYY-MM-DD")) & JCQK==jcqk & CZLX==czlx) %>%
select(GRDA_ET_LSH,GLDW_BM,CSRQ)
jzjl <- con %>%
tbl(in_schema('ipvsdb','INOC_JZJL')) %>%
right_join(temp,by=c('GRDA_ET_LSH'='GRDA_ET_LSH')) %>%
select(CSRQ,YM_BM,JZ_ZC,GRDA_ET_LSH,GLDW_BM) %>%
collect() %>%
clean_names() %>%
mutate(csrq=as.Date(csrq)) %>%
mutate(yingzhong=if_else((static_date-csrq)>ddays(30*month),1,0)) %>%
filter(yingzhong==1) %>%
mutate(dzbm=str_sub(gldw_bm,1,level)) %>%
mutate(shizhong=if_else(str_sub(ym_bm,0,2)==ymbm & jz_zc==jzzc,1,0)) %>%
select(shizhong,ym_bm,jz_zc,grda_et_lsh,csrq,yingzhong,dzbm) %>%
group_by(dzbm) %>%
summarise(yz=n_distinct(grda_et_lsh),sz=sum(shizhong,na.rm = T)) %>%
drop_na(dzbm)
jzl <- con %>%
tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%
select(DZMC,DZBM) %>%
filter(str_length(DZBM)==level) %>%
collect() %>%
clean_names() %>%
right_join(jzjl,by = c("dzbm"="dzbm"))
jzl %<>%
add_row(dzmc='合计',yz=sum(jzl$yz,na.rm = t),
sz=sum(jzl$sz,na.rm = t)) %>%
mutate(prop=round(sz/yz*100,2)) %>%
arrange(dzbm) %>%
select('地区'=dzmc,'应种数'=yz,'实种数'=sz,'接种率'=prop)
return(jzl)
}
#CZLX:本地和流动
#JCQK:在册1
jcqk <- '1'
czlx <- '1'
#出生时间段,满1岁儿童
csrq_begin <- "2017-01-01"
csrq_end <- "2018-01-31"
#乙肝第3针
jzzc=3
#应种月龄
month <- 6
#疫苗大类
ymbm <- '02'
#统计日期
static_date <- ymd('2019-02-01')
#显示到县级6,显示到市级4
level <- 6
#应种满12个月不做为统计条件
condition <- FALSE
#condition <- TRUE
hbv3 <- ym_jzl(csrq_begin,csrq_end,static_date,ymbm,jzzc,month,jcqk,czlx,level,condition)
library(ROracle)
library(tidyverse)
library(dbplyr)
library(knitr)
library(magrittr)
library(stringr)
library(lubridate)
library(janitor)
ym_jzl <- function(csrq_begin,csrq_end,static_date,ymbm,jzzc,month,jcqk,czlx,level,condition) {
static_date <- if_else(condition,static_date - ddays(12*30),static_date)
temp <- con %>%
tbl(in_schema('ipvsdb','GRDA_ET')) %>%
filter(between(CSRQ,to_date(csrq_begin,"YYYY-MM-DD"),
to_date(csrq_end,"YYYY-MM-DD")) & JCQK==jcqk & CZLX==czlx) %>%
select(GRDA_ET_LSH,GLDW_BM,CSRQ)
jzjl <- con %>%
tbl(in_schema('ipvsdb','INOC_JZJL')) %>%
right_join(temp,by=c('GRDA_ET_LSH'='GRDA_ET_LSH')) %>%
select(CSRQ,YM_BM,JZ_ZC,GRDA_ET_LSH,GLDW_BM) %>%
collect() %>%
clean_names() %>%
mutate(csrq=as.Date(csrq)) %>%
mutate(yingzhong=if_else((static_date-csrq)>ddays(30*month),1,0)) %>%
filter(yingzhong==1) %>%
mutate(dzbm=str_sub(gldw_bm,1,level)) %>%
mutate(shizhong=if_else(str_sub(ym_bm,0,2)==ymbm & jz_zc==jzzc,1,0)) %>%
select(shizhong,ym_bm,jz_zc,grda_et_lsh,csrq,yingzhong,dzbm) %>%
group_by(dzbm) %>%
summarise(yz=n_distinct(grda_et_lsh),sz=sum(shizhong,na.rm = T)) %>%
drop_na(dzbm)
jzl <- con %>%
tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%
select(DZMC,DZBM) %>%
filter(str_length(DZBM)==level) %>%
collect() %>%
clean_names() %>%
right_join(jzjl,by = c("dzbm"="dzbm"))
jzl %<>%
add_row(dzmc='合计',yz=sum(jzl$yz,na.rm = t),
sz=sum(jzl$sz,na.rm = t)) %>%
mutate(prop=round(sz/yz*100,2)) %>%
arrange(dzbm) %>%
select('地区'=dzmc,'应种数'=yz,'实种数'=sz,'接种率'=prop)
return(jzl)
}
#CZLX:本地和流动
#JCQK:在册1
jcqk <- '1'
czlx <- '1'
#出生时间段,满1岁儿童
csrq_begin <- "2017-01-01"
csrq_end <- "2018-01-31"
#乙肝第3针
jzzc=3
#应种月龄
month <- 6
#疫苗大类
ymbm <- '02'
#统计日期
static_date <- ymd('2019-02-01')
#显示到县级6,显示到市级4
level <- 6
#应种满12个月不做为统计条件
condition <- FALSE
#condition <- TRUE
hbv3 <- ym_jzl(csrq_begin,csrq_end,static_date,ymbm,jzzc,month,jcqk,czlx,level,condition)
评论
发表评论