-
Notifications
You must be signed in to change notification settings - Fork 0
/
fct_process_regimentext.R
51 lines (51 loc) · 1.72 KB
/
fct_process_regimentext.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
#' Generate regimen text
#'
#' @description
#' Generates regimen text to appear above the table based on dosing regimen
#' input. Adds additional breaks below the regimen text for current output based
#' on the number of rows of the regimen text for the other output and vice versa.
#'
#' @param reg Regimen data from output in list format
#' @param other Regimen data from other output in list format
#'
#' @return Text describing the regimen with appropriate spacing
#' @keywords internal
#' @export
#'
fct_process_regimentext <- function(reg, other) {
if (!is.null(reg)) {
seq_along(reg$amt) %>%
purrr::map(function(i) {
dur_txt <- paste0("Day", ifelse(reg$dur[[i]] > 1, "s ", " "))
dur_val <- reg$dur %>%
purrr::when(
.[[i]] == 1 & i == 1 ~ "1",
.[[i]] != 1 & i == 1 ~ paste("1", .[[i]], sep = "-"),
.[[i]] == 1 & i != 1 ~ paste(.[[i-1]] + 1),
.[[i]] != 1 & i != 1 ~ paste(.[[i-1]] + 1, .[[i-1]] + .[[i]], sep = "-")
) # when
dur_str <- paste0(dur_txt, dur_val, ":")
amt_str <- paste(reg$amt[[i]], "mg")
int_str <- paste("every", reg$int[[i]], "hours")
paste(dur_str, amt_str, int_str)
}) %>% # map
purrr::map(strong) %>%
purrr::map(h5) %>%
purrr::when(
is.null(other) ~ .,
length(.) >= length(other$amt) ~ .,
length(.) < length(other$amt) ~ list(.,
purrr::map(
seq(length(reg$amt) + 1, length(other$amt), by = 1), ~ h5(br()))) %>%
unlist(recursive = FALSE)
) %>% # when
return()
} else if (!is.null(other)) {
seq_along(other$amt) %>%
purrr::map(~ h5(br())) %>%
return()
} else {
return("")
}
}