-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_data.R
105 lines (92 loc) · 3.8 KB
/
fake_data.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
library(magrittr)
simul_line_base <- function(n, line_base, ...) {
linebase <- line_base[unique(sample(1:length(line_base), length(line_base), TRUE))]
res <- paste0(linebase, collapse = ",")
rep(res, n)
}
calc_startend_periods <- function(n, lastseen, linenumber) {
max_end_date <- max(as.Date(lastseen))
min_start_date <- max_end_date - sample(365:(5*365), 1)
dates_sample <- sort(sample(seq(min_start_date, max_end_date, by = "day"), 2 * n))
end_dates <- dates_sample[2*(1:n)]
start_dates <- dates_sample[-2*(1:n)]
return(paste0(start_dates, ",", end_dates))
}
gen_visit <- function(n, startend) {
date_ranges <- as.Date(unlist(strsplit(startend, ",")))
min_date <- min(date_ranges)
max_date <- max(date_ranges)
sample(seq(min_date, max_date, by = "day"), n, TRUE)
}
DataFakeR::set_faker_opts(
opt_default_table = DataFakeR::opt_default_table(nrows = DataFakeR::nrows_simul_ratio(0.25, 10000))
)
sch <- DataFakeR::schema_source("schema.yml")
set.seed(123)
sch <- DataFakeR::schema_simulate(sch)
datasets_fake <- list(
demographics = DataFakeR::schema_get_table(sch, "demographics") %>%
dplyr::select(-dplyr::starts_with("tmp")) %>%
dplyr::mutate(random_date = lastseen - sample(365 * 1:5, 1)),
visit = DataFakeR::schema_get_table(sch, "visit") %>%
dplyr::select(-dplyr::starts_with("tmp")),
indications = DataFakeR::schema_get_table(sch, "indications") %>%
dplyr::select(-dplyr::starts_with("tmp")) %>% dplyr::distinct(),
line_of_therapy = DataFakeR::schema_get_table(sch, "line_of_therapy") %>%
dplyr::select(-dplyr::starts_with("tmp"))
)
library(shiny)
ui <- fluidPage(
shinyTimelines::shiny_timelines_ui("timeln")
)
server <- function(input, output, session) {
mod_data <- reactiveValues(
demographics = datasets_fake$demographics,
lineoftherapy = datasets_fake$line_of_therapy,
visits = datasets_fake$visit,
indications = datasets_fake$indications,
)
callModule(
shinyTimelines::shiny_timelines_server,
id = "timeln",
session = session,
extra_data = c("Extra col" = "random_date"),
columns_mapping = list(
"single_case" = list(
"demographics" = list("patientid" = "patientid",
"dateofdeath" = "dateofdeath",
"lastseen" = "lastseen",
"indexdate" = "diagnosisdate"),
"lineoftherapy" = list("patientid" = "patientid",
"linename" = "linename",
"linenumber" = "linenumber",
"startdate" = "startdate",
"enddate" = "enddate"),
"visits" = list("patientid" = "patientid",
"visitdate" = "visitdate",
"visittype" = "visittype")
),
"multiple_case" = list(
"demographics" = list("patientid" = "patientid",
"dateofdeath" = "dateofdeath",
"lastseen" = "lastseen",
"random_date"= "random_date"),
"lineoftherapy" = list("patientid" = "patientid",
"linename" = "linename",
"linenumber" = "linenumber",
"startdate" = "startdate",
"enddate" = "enddate",
"indication" = "indication"),
"visits" = list("patientid" = "patientid",
"visitdate" = "visitdate",
"visittype" = "visittype",
"indication" = "indication"),
"indications" = list("patientid" = "patientid",
"indication" = "indication",
"indexdate" = "diagnosisdate")
)
),
.list = mod_data
)
}
shinyApp(ui, server)