1
- get_raw_impact_details <- function (con , meta1 , burden_outcome , is_under5 = FALSE , countries_to_extract = NULL ){
1
+ get_raw_impact_details <- function (con , meta1 , burden_outcome , is_under5 = FALSE , countries_to_extract = NULL , age_specific = FALSE ){
2
2
# verify parameters
3
3
stopifnot(nrow(meta1 ) == 2L )
4
4
stopifnot(burden_outcome %in% c(" deaths" , " cases" , " dalys" , " yll" ,
5
5
" deaths_cwyx" , " cases_cwyx" , " dalys_cwyx" , " yll_cwyx" )) # _cwyx outcomes are MenA specific.
6
6
stopifnot(is_under5 %in% c(TRUE , FALSE ))
7
7
8
- # preparation
9
- # determine burden outcome, k will be used to determine burden outcome ids
10
- if (burden_outcome == " deaths" ){
11
- k <- 1
12
- } else if (burden_outcome == " cases" ){
13
- k <- 2
14
- } else if (burden_outcome == " dalys" ){
15
- k <- 3
16
- } else if (burden_outcome == " yll" ){
17
- k <- 4
18
- } else if (burden_outcome == " deaths_cwyx" ){
19
- k <- 5
20
- } else if (burden_outcome == " cases_cwyx" ){
21
- k <- 6
22
- } else if (burden_outcome == " dalys_cwyx" ){
23
- k <- 7
24
- } else if (burden_outcome == " yll_cwyx" ){
25
- k <- 8
26
- } else {
27
- stop(" Can only take burden outcome as one of deaths, cases, dalys, yll, deaths_cwyx, cases_cwyx, dalys_cwyx, yll_cwyx" )
28
- }
29
-
30
8
# determine whether a recipe is for routine or campaign vaccine delivery
31
9
# routine or campaign matters for method2a in terms of the shape of burden estimates to extract
32
10
# if routine, by year of birth
@@ -56,13 +34,22 @@ get_raw_impact_details <- function(con, meta1, burden_outcome, is_under5 = FALSE
56
34
57
35
# set up db extraction sql queries
58
36
if ((meta1 $ method [1 ] == " method0" ) || (meta1 $ method [1 ] == " method2a" && any(j ))){
59
- sql <- paste(" SELECT country, year AS time, sum(value) AS value" ,
60
- " FROM burden_estimate" ,
61
- " WHERE burden_estimate_set = %s" ,
62
- " AND burden_outcome IN %s" ,
63
- age_constrain ,
64
- country_constrain ,
65
- " GROUP BY country, year" )
37
+ if (meta1 $ method [1 ] == " method0" & age_specific ){
38
+ sql <- paste(" SELECT country, year AS time, age, value" ,
39
+ " FROM burden_estimate" ,
40
+ " WHERE burden_estimate_set = %s" ,
41
+ " AND burden_outcome IN %s" ,
42
+ age_constrain ,
43
+ country_constrain )
44
+ } else {
45
+ sql <- paste(" SELECT country, year AS time, sum(value) AS value" ,
46
+ " FROM burden_estimate" ,
47
+ " WHERE burden_estimate_set = %s" ,
48
+ " AND burden_outcome IN %s" ,
49
+ age_constrain ,
50
+ country_constrain ,
51
+ " GROUP BY country, year" )
52
+ }
66
53
} else if ((meta1 $ method [1 ] == " method1" ) || (meta1 $ method [1 ] == " method2a" && any(i )) || (meta1 $ method [1 ] == " method2b" )){
67
54
sql <- paste(" SELECT country, (year-age) AS time, sum(value)AS value" ,
68
55
" FROM burden_estimate" ,
@@ -75,18 +62,23 @@ get_raw_impact_details <- function(con, meta1, burden_outcome, is_under5 = FALSE
75
62
76
63
# get burden outcome ids
77
64
i <- meta1 $ meta_type == " focal"
78
- ii <- unlist(strsplit(meta1 $ burden_outcome_id [i ], " ;" ))
65
+ ss_id <- unlist(strsplit(meta1 $ burden_outcome_id [i ], " ;" ))
66
+ ss_code <- unlist(strsplit(meta1 $ burden_outcome [i ], " ;" ))
67
+ ii <- ss_id [ss_code == burden_outcome ]
68
+
79
69
j <- meta1 $ meta_type == " baseline"
80
- jj <- unlist(strsplit(meta1 $ burden_outcome_id [j ], " ;" ))
70
+ ss_id <- unlist(strsplit(meta1 $ burden_outcome_id [j ], " ;" ))
71
+ ss_code <- unlist(strsplit(meta1 $ burden_outcome [j ], " ;" ))
72
+ jj <- ss_id [ss_code == burden_outcome ]
81
73
82
74
# extract burden estimates
83
75
d_baseline <- DBI :: dbGetQuery(con , sprintf(sql ,
84
76
sql_in(meta1 $ burden_estimate_set [j ], text_item = FALSE ),
85
- sql_in(jj [ k ] , text_item = FALSE )))
77
+ sql_in(jj , text_item = FALSE )))
86
78
87
79
d_focal <- DBI :: dbGetQuery(con , sprintf(sql ,
88
80
sql_in(meta1 $ burden_estimate_set [i ], text_item = FALSE ),
89
- sql_in(ii [ k ] , text_item = FALSE )))
81
+ sql_in(ii , text_item = FALSE )))
90
82
if (meta1 $ disease [1 ] == " HepB" && (nrow(d_focal ) == 0L || nrow(d_baseline ) == 0L )) {
91
83
# when you are extracting data for HepB - IC and CDA models - for specific countries
92
84
# you may end out with 0 rows for d_baseline or d_focal
0 commit comments