diff --git a/DESCRIPTION b/DESCRIPTION
index 556a526..c52b353 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: SwissASR
Title: Automated Completion of the SwissEthics Annual Safety Report
-Version: 0.5.2
+Version: 0.5.3
Authors@R:
c(person(given = "Alan G.",
family = "Haynes",
diff --git a/NEWS.md b/NEWS.md
index fe15e73..dc35754 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,7 @@
+# SwissASR 0.5.3
+
+* Last updates to align with the latest template and add a warning for special characters causing a problem in producing the Word report from R.
+
# SwissASR 0.5.2
* Correction of template inputs, dates formatting and additional note for SAEs tables.
diff --git a/R/asr.R b/R/asr.R
index dfad182..7dbfd87 100644
--- a/R/asr.R
+++ b/R/asr.R
@@ -58,6 +58,7 @@
#' @param var_relation variable containing the relationship to randomized intervention
#' @param var_expected variable saying whether the SAE was expected
#' @param var_devdef variable containing whether the SAE is a device deficiency
+#' @param var_devdefcouldlead variable containing whether the device deficiency could have lead to an SAE
#' @param var_devattr variable containing whether the SAE is attributable to the device
#' @param var_devint variable containing whether the SAE is attributable to an intervention in the trial
#' @param var_safetymeasure variable containing whether the SAE required safety related measures
@@ -78,58 +79,6 @@
#' file <- tempfile("asr", fileext = ".docx")
#' asr(asr_sae, file)
#'
-#' # # more usual use will require passing more information:
-#' # asr(asr_sae, file,
-#' # # trial info
-#' # trial_title = "Example Trial Name",
-#' # protocol_number = "20221002130",
-#' # basec_number = "",
-#' # snctp_number = "202200458",
-#' # swissmedic_number = "....",
-#' # ec_name = "Kantonale Ethikskommision Bern",
-#' # tr_number = "",
-#' # product_name = "Drug name",
-#' # international = FALSE,
-#' # trial_type = "imp",
-#' # # Sponsor info
-#' # sponsor_contact = "Sponsor name, Sponsor phone number, Sponsor email",
-#' # inst_name_address = "Institute name, Institute address",
-#' # # site info
-#' # n_centers_t = 20, # total number
-#' # n_centers_p = "default", # planned
-#' # n_centers_c = "default", # closed
-#' # n_centers_o = "default", # open
-#' # # participant info
-#' # n_pat_t = 1000, # target
-#' # n_pat_e = 300, # enrolled
-#' # n_pat_c = 0, # complete
-#' # n_pat_p = 0, # prematurely terminated
-#' # # report info
-#' # report_date = format(Sys.Date(), format = "%d/%m/%Y"),
-#' # period_from = as.Date("2020-11-02"),
-#' # period_to = as.Date("2020-11-17"),
-#' # # variable mapping
-#' # var_class = "class",
-#' # var_sae_n = "sae_n", #sae ID
-#' # var_part_id = "record_id", #participant ID
-#' # var_age = "age",
-#' # var_sex ="sex",
-#' # var_country = "country",
-#' # var_site = "site",
-#' # var_sae = "sae",
-#' # var_date_onset = "sae_date",
-#' # var_trt = "trt",
-#' # var_date_trt_start = "sae_trtstart",
-#' # var_date_trt_stop = "sae_trtstop",
-#' # var_outcome = "outcome",
-#' # var_comment = "comment",
-#' # var_relation = "related",
-#' # var_expected = "expected",
-#' # var_safetymeasure = "safetymeasure"
-#' # )
-#'
-#'
-#'
asr <- function(data,
target = "tmp.docx",
@@ -184,6 +133,7 @@ asr <- function(data,
, var_relation = "related"
, var_expected = "expected"
, var_devdef = "devdef"
+ , var_devdefcouldlead = "devdefcouldlead"
, var_devattr = "devattr"
, var_devint = "devint"
, var_safetymeasure = "safetymeasure"
@@ -236,11 +186,12 @@ asr <- function(data,
# if(trial_type == "medical device"){
# names(data)[names(data) == var_expected] <- "expected"
# names(data)[names(data) == var_devdef] <- "devdef"
+ # names(data)[names(data) == var_devdefcouldlead] <- "devdefcouldlead"
# names(data)[names(data) == var_devattr] <- "devattr"
# names(data)[names(data) == var_devint] <- "devint"
# names(data)[names(data) == var_safetymeasure] <- "safetymeasure"
#
- # vars <- c("expected", "devdef", "devattr", "devint", "safetymeasure")
+ # vars <- c("expected", "devdef", "devdefcouldlead","devattr", "devint", "safetymeasure")
# if(!all(vars %in% names(data))){
# stop(paste(vars[!vars %in% names(data)], collapse = ", "), " not found in data")
# }
@@ -320,6 +271,23 @@ asr <- function(data,
# data$trt <- as.character(data$trt)
#
+# Check in the text inputs if any detected special character causing problems is present
+ for(string in c("trial_title",
+ "protocol_number",
+ "basec_number",
+ "snctp_number",
+ "swissmedic_number",
+ "ec_name",
+ "tr_number",
+ "product_name",
+ "sponsor_contact",
+ "inst_name_address")){
+ check_field_characters(get(string)) }
+
+# This check is for the arm names in case these are available and requested
+ if(!is.null(n_per_arm)){lapply(names(n_per_arm),check_field_characters)}
+
+
dfs <- asr_dataprep(data,
period_from = period_from,
period_to = period_to
@@ -341,6 +309,7 @@ asr <- function(data,
, var_relation = var_relation
, var_expected = var_expected
, var_devdef = var_devdef
+ , var_devdefcouldlead = var_devdefcouldlead
, var_devattr = var_devattr
, var_devint = var_devint
, var_safetymeasure = var_safetymeasure
@@ -353,36 +322,6 @@ asr <- function(data,
# report itself ----
doc <- read_docx(template)
-
-
- # ..general info, details of trial ----
- #
- # for(i in c("trial_title",
- # "protocol_number",
- # "basec_number",
- # "snctp_number",
- # "swissmedic_number",
- # "ec_name",
- # "tr_number",
- # "product_name",
- # "sponsor_contact",
- # "inst_name_address",
- # "report_date",
- # "period",
- # "n_centers_t",
- # "n_centers_p",
- # "n_centers_c",
- # "n_centers_o",
- # "n_pat_t",
- # "n_pat_e",
- # "n_pat_c",
- # "n_pat_p")){
- # x <- get(i)
- # doc <- doc %>%
- # cursor_bookmark(i) %>%
- # body_add_par(x, pos = "after")
- # }
-
# format the dates for the text
period_from_f <- format(period_from, format = "%d/%m/%Y")
period_to_f <- format(period_to, format = "%d/%m/%Y")
@@ -390,26 +329,26 @@ asr <- function(data,
period <- glue("{period_from_f} to {period_to_f}")
## New code to insert the fields instead of bookmarks
doc <- doc %>%
- set_doc_properties(trial_title = get("trial_title"),
- protocol_number = get("protocol_number"),
- basec_number = get("basec_number"),
- snctp_number = get("snctp_number"),
- swissmedic_number = get("swissmedic_number"),
- ec_name = get("ec_name"),
- tr_number = get("tr_number"),
- product_name = get("product_name"),
- sponsor_contact = get("sponsor_contact"),
- inst_name_address = get("inst_name_address"),
- report_date = get("report_date"),
- period = get("period"),
- n_centers_t = as.character(get("n_centers_t")),
- n_centers_p = as.character(get("n_centers_p")),
- n_centers_c = as.character(get("n_centers_c")),
- n_centers_o = as.character(get("n_centers_o")),
- n_centers_t_ch = as.character(get("n_centers_t_ch")),
- n_centers_p_ch = as.character(get("n_centers_p_ch")),
- n_centers_c_ch = as.character(get("n_centers_c_ch")),
- n_centers_o_ch = as.character(get("n_centers_o_ch")),
+ set_doc_properties(trial_title = "trial_title",
+ protocol_number = "protocol_number",
+ basec_number = "basec_number",
+ snctp_number = "snctp_number",
+ swissmedic_number = "swissmedic_number",
+ ec_name = "ec_name",
+ tr_number = "tr_number",
+ product_name = "product_name",
+ sponsor_contact = "sponsor_contact",
+ inst_name_address = "inst_name_address",
+ report_date = "report_date",
+ period = "period",
+ n_centers_t = as.character(n_centers_t),
+ n_centers_p = as.character(n_centers_p),
+ n_centers_c = as.character(n_centers_c),
+ n_centers_o = as.character(n_centers_o),
+ n_centers_t_ch = as.character(n_centers_t_ch),
+ n_centers_p_ch = as.character(n_centers_p_ch),
+ n_centers_c_ch = as.character(n_centers_c_ch),
+ n_centers_o_ch = as.character(n_centers_o_ch),
n_pat_t = as.character(n_pat_t),
n_pat_e = as.character(n_pat_e),
n_pat_c = as.character(n_pat_c),
@@ -427,13 +366,6 @@ asr <- function(data,
n_pat_e = n_pat_e,
n_per_arm = n_per_arm)
- # doc <- doc %>%
- # cursor_bookmark("partsafety_text")
- # for(i in 1:length(summ$txt)){
- # txt <- summ$txt[i]
- # doc <- doc %>% body_add_par(txt, style = "Text")
- # }
-
doc <- doc %>%
officer::set_doc_properties(partsafety_text = paste0(summ$txt, collapse = " ") )
@@ -498,7 +430,7 @@ asr <- function(data,
}
llist_ft <- flextable(llist) %>%
#add_header_lines("Line listing of SAEs, SADRs and SUSARs, including international cases
-#(code and version of used standard (e.g. MedDRA or CTCAE) should be indicated, details on SUSARs will be attached as appendices)") %>%
+ #(code and version of used standard (e.g. MedDRA or CTCAE) should be indicated, details on SUSARs will be attached as appendices)") %>%
border(border = fp_border(color = "#4FB4E0"), part="all") %>%
fontsize(size = 8, part = "all") %>%
font(fontname = "Helvetica", part = "all")
@@ -517,10 +449,3 @@ asr <- function(data,
docx_update(input = target)
}
-
-
-
-
-
-
-
diff --git a/R/asr_dataprep.R b/R/asr_dataprep.R
index 3901fc4..b0bc864 100644
--- a/R/asr_dataprep.R
+++ b/R/asr_dataprep.R
@@ -63,8 +63,8 @@
# class = msample(c("SAE", "SUSAR", "SADR")),
# expected = msample(c(TRUE, FALSE)),
# devdef = msample(c(TRUE, FALSE)),
+# devdefcouldlead = msample(c(TRUE, FALSE)),
# devattr = msample(c(TRUE, FALSE)),
-# devdef = msample(c(TRUE, FALSE)),
# devint = msample(c(TRUE, FALSE)),
# safetymeasure = msample(c(TRUE, FALSE))
# )
@@ -129,6 +129,7 @@ asr_dataprep <- function(data
, var_relation = "related"
, var_expected = "expected"
, var_devdef = "devdef"
+ , var_devdefcouldlead = "devdefcouldlead"
, var_devattr = "devattr"
, var_devint = "devint"
, var_safetymeasure = "safetymeasure"
@@ -182,6 +183,8 @@ asr_dataprep <- function(data
names(data)[names(data) == var_trt] <- "trt"
if(tx_var){
names(data)[names(data) == var_tx] <- "intervention"
+ }else{
+ data <- data[,!names(data) %in% "intervention"]
}
## relevant variables exist
@@ -205,11 +208,12 @@ asr_dataprep <- function(data
if(trial_type == "medical device"){
names(data)[names(data) == var_expected] <- "expected"
names(data)[names(data) == var_devdef] <- "devdef"
+ names(data)[names(data) == var_devdefcouldlead] <- "devdefcouldlead"
names(data)[names(data) == var_devattr] <- "devattr"
names(data)[names(data) == var_devint] <- "devint"
names(data)[names(data) == var_safetymeasure] <- "safetymeasure"
- vars <- c("expected", "devdef", "devattr", "devint", "safetymeasure")
+ vars <- c("expected", "devdef", "devdefcouldlead","devattr", "devint", "safetymeasure")
if(!all(vars %in% names(data))){
stop(paste(vars[!vars %in% names(data)], collapse = ", "), " not found in data")
}
diff --git a/R/asr_safety_summary.R b/R/asr_safety_summary.R
index 48e44a1..64c8ee7 100644
--- a/R/asr_safety_summary.R
+++ b/R/asr_safety_summary.R
@@ -51,6 +51,15 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
trial_type <- match.arg(trial_type, c("imp", "medical device", "other","trp"))
+ ## check whether the intervention variable has been defined
+ if("intervention" %in% names(data)){
+ check <- unique(data$intervention)
+
+ ## Check whether the treatment are defined correctly in the trt variable
+ if(all(!is.na(n_per_arm)))
+ if(!all(check %in% names(n_per_arm))) stop("The treatment groups in the data do not match those in 'n_par_arm'. \n",
+ "Please define the names of the treatment groups in the 'var_tx' variable or set 'n_par_arm' to NA.")
+ }
if(trial_type == "imp"){
# FOR IMP TRIALS
@@ -81,7 +90,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Suspected Unexpected Serious Adverse Reactions, SUSARs (only for IMPs)'),
stringsAsFactors = FALSE)
- if(all(!is.na(n_per_arm))){
+ if("intervention" %in% names(data)){
### define the values for the two interventional groups
grp <- names(n_per_arm)
@@ -90,32 +99,32 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
~desc, ~fatal, ~sae, ~sadr, ~susar,
# row 1
'Number of cases (during reporting period)',
- paste0("N = ", sum(period_data$outcome == "Fatal"),
- " (",sum(period_data$outcome == "Fatal" & period_data$intervention==grp[1]),",",
- sum(period_data$outcome == "Fatal" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$outcome != "Fatal"),
- " (",sum(period_data$outcome != "Fatal" & period_data$intervention==grp[1]),",",
- sum(period_data$outcome != "Fatal" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$class == "SADR"),
- " (",sum(period_data$class == "SADR" & period_data$intervention==grp[1]),",",
- sum(period_data$class == "SADR" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$class == "SUSAR"),
- " (",sum(period_data$class == "SUSAR" & period_data$intervention==grp[1]),",",
- sum(period_data$class == "SUSAR" & period_data$intervention==grp[2]),")"),
+ paste0("N = ", sum(period_data$outcome == "Fatal", na.rm=TRUE),
+ " (",sum(period_data$outcome == "Fatal" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$outcome == "Fatal" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$outcome != "Fatal", na.rm=TRUE),
+ " (",sum(period_data$outcome != "Fatal" & period_data$intervention==grp[1],na.rm=TRUE),",",
+ sum(period_data$outcome != "Fatal" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$class == "SADR", na.rm=TRUE),
+ " (",sum(period_data$class == "SADR" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$class == "SADR" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$class == "SUSAR", na.rm=TRUE),
+ " (",sum(period_data$class == "SUSAR" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$class == "SUSAR" & period_data$intervention==grp[2], na.rm=TRUE),")"),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- paste0("N = ", sum(data$outcome == "Fatal"),
- " (",sum(data$outcome == "Fatal" & data$intervention==grp[1]),",",
- sum(data$outcome == "Fatal" & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$outcome != "Fatal"),
- " (",sum(data$outcome != "Fatal" & data$intervention==grp[1]),",",
- sum(data$outcome != "Fatal" & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$class == "SADR"),
- " (",sum(data$class == "SADR" & data$intervention==grp[1]),",",
- sum(data$class == "SADR" & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$class == "SUSAR"),
- " (",sum(data$class == "SUSAR" & data$intervention==grp[1]),",",
- sum(data$class == "SUSAR" & data$intervention==grp[2]),")"),
+ paste0("N = ", sum(data$outcome == "Fatal", na.rm=TRUE),
+ " (",sum(data$outcome == "Fatal" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$outcome == "Fatal" & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$outcome != "Fatal", na.rm=TRUE),
+ " (",sum(data$outcome != "Fatal" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$outcome != "Fatal" & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$class == "SADR", na.rm=TRUE),
+ " (",sum(data$class == "SADR" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$class == "SADR" & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$class == "SUSAR", na.rm=TRUE),
+ " (",sum(data$class == "SUSAR" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$class == "SUSAR" & data$intervention==grp[2], na.rm=TRUE),")"),
)
} else {
@@ -123,16 +132,16 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
~desc, ~fatal, ~sae, ~sadr, ~susar,
# row 1
'Number of cases (during reporting period)',
- sum(period_data$outcome == "Fatal"),
- sum(period_data$outcome != "Fatal"),
- sum(period_data$class == "SADR"),
- sum(period_data$class == "SUSAR"),
+ sum(period_data$outcome == "Fatal", na.rm=TRUE),
+ sum(period_data$outcome != "Fatal", na.rm=TRUE),
+ sum(period_data$class == "SADR", na.rm=TRUE),
+ sum(period_data$class == "SUSAR", na.rm=TRUE),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- sum(data$outcome == "Fatal"),
- sum(data$outcome != "Fatal"),
- sum(data$class == "SADR"),
- sum(data$class == "SUSAR")
+ sum(data$outcome == "Fatal", na.rm=TRUE),
+ sum(data$outcome != "Fatal", na.rm=TRUE),
+ sum(data$class == "SADR", na.rm=TRUE),
+ sum(data$class == "SUSAR", na.rm=TRUE)
)
}
@@ -156,9 +165,9 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
glue("In {sum(period_data$devint)} of {nrow(period_data)} SAEs ({sprintf('%1.1f', sum(period_data$devint)/nrow(period_data)*100)} %) it cannot be excluded that the events are attributable to an intervention undertaken in the clinical trial."),
if(sum(period_data$class=="SAE")>0){glue("The most frequent SAEs documented were {most_freq}.")}else{glue(" ")},
glue("Occurrence of SAE in the trial arm versus control arm (if applicable)."),
- glue("With respect to the expectedness of the event, {sum(data$expected)} ({sprintf('%1.1f', sum(period_data$expected)/nrow(period_data)*100)} %) of the SADEs were expected/anticipated and {sum(!period_data$expected)} ({sprintf('%1.1f', sum(!period_data$expected)/nrow(period_data)*100)} %) were classified as unexpected/unanticipated."),
+ glue("With respect to the expectedness of the event, {sum(period_data$expected & period_data$related)} ({sprintf('%1.1f', sum(period_data$expected & period_data$related)/sum(period_data$related)*100)} %) of the SADEs were expected/anticipated and {sum(!period_data$expected & period_data$related)} ({sprintf('%1.1f', sum(!period_data$expected)/sum(period_data$related)*100)} %) were classified as unexpected/unanticipated."),
glue("{sum(period_data$devdef)} device deficiencies were observed (includes malfunctions, use errors, inadequacies in the information supplied by the manufacturer including labelling)."),
- if(sum(period_data$devdef)>0){glue("{sum(period_data$devdef)} out of {sum(period_data$devattr)} device deficiencies ({sprintf('%1.1f', sum(period_data$devdef)/sum(period_data$devdef)*100)} %) could have led to serious adverse events if suitable action had not been taken, intervention had not been made, or circumstances had been less fortunate (device deficiencies with a SAE potential).")}else{glue(" ")},
+ if(sum(period_data$devdef)>0){glue("{sum(period_data$devdefcouldlead)} out of {sum(period_data$devdef)} device deficiencies ({sprintf('%1.1f', sum(period_data$devdef)/sum(period_data$devdef)*100)} %) could have led to serious adverse events if suitable action had not been taken, intervention had not been made, or circumstances had been less fortunate (device deficiencies with a SAE potential).")}else{glue(" ")},
glue("{sum(period_data$safetymeasure)} health hazards that required safety-related measures occurred."),
glue("Safety and protective measures taken by the investigator/sponsor (including those requested by the ethics committee and Swissmedic and authorities abroad) taken in Switzerland and abroad: [free text]"))
@@ -168,9 +177,9 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
glue("In {sum(data$devint)} of {nrow(data)} SAEs ({sprintf('%1.1f', sum(data$devint)/nrow(data)*100)} %) it cannot be excluded that the events are attributable to an intervention undertaken in the clinical trial."),
if(sum(data$class=="SAE")>0){glue("The most frequent SAEs documented were {most_freq_all}.")}else{glue(" ")},
glue("Occurrence of SAE in the trial arm versus control arm (if applicable)."),
- glue("With respect to the expectedness of the event, {sum(data$expected)} ({sprintf('%1.1f', sum(data$expected)/nrow(data)*100)} %) of the SADEs were expected/anticipated and {sum(!data$expected)} ({sprintf('%1.1f', sum(!data$expected)/nrow(data)*100)} %) were classified as unexpected/unanticipated."),
+ glue("With respect to the expectedness of the event, {sum(data$expected & data$related)} ({sprintf('%1.1f', sum(data$expected & data$related)/sum(data$related)*100)} %) of the SADEs were expected/anticipated and {sum(!data$expected & data$related)} ({sprintf('%1.1f', sum(!data$expected)/sum(data$related)*100)} %) were classified as unexpected/unanticipated."),
glue("{sum(data$devdef)} device deficiencies were observed (includes malfunctions, use errors, inadequacies in the information supplied by the manufacturer including labelling)."),
- if(sum(data$devdef)>0){glue("{sum(data$devdef)} out of {sum(data$devdef)} device deficiencies ({sprintf('%1.1f', sum(data$devdef)/sum(data$devdef)*100)} %) could have led to serious adverse events if suitable action had not been taken, intervention had not been made, or circumstances had been less fortunate (device deficiencies with a SAE potential).")}else{glue(" ")},
+ if(sum(data$devdef)>0){glue("{sum(data$devdefcouldlead)} out of {sum(data$devdef)} device deficiencies ({sprintf('%1.1f', sum(data$devdef)/sum(data$devdef)*100)} %) could have led to serious adverse events if suitable action had not been taken, intervention had not been made, or circumstances had been less fortunate (device deficiencies with a SAE potential).")}else{glue(" ")},
glue("{sum(data$safetymeasure)} health hazards that required safety-related measures occurred."),
glue("Safety and protective measures taken by the investigator/sponsor (including those requested by the ethics committee and Swissmedic and authorities abroad) taken in Switzerland and abroad: [free text]"))
@@ -181,7 +190,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Safety and protective measures taken in Switzerland and abroad.'),
stringsAsFactors = FALSE)
- if(all(!is.na(n_per_arm))){
+ if("intervention" %in% names(data)){
### define the values for the two interventional groups
grp <- names(n_per_arm)
@@ -190,40 +199,40 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
~desc, ~sade ,~attr, ~measures,
# row 1
'Number of cases (during reporting period)',
- paste0("N = ", sum(period_data$class == "SADE"),
- " (",sum(period_data$class == "SADE" & period_data$intervention==grp[1]),",",
- sum(period_data$class == "SADE" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$devattr),
- " (",sum(period_data$devattr & period_data$intervention==grp[1]),",",
- sum(period_data$devattr & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$safetymeasure),
- " (",sum(period_data$safetymeasure & period_data$intervention==grp[1]),",",
- sum(period_data$safetymeasure & period_data$intervention==grp[2]),")"),
+ paste0("N = ", sum(period_data$class == "SADE", na.rm=TRUE),
+ " (",sum(period_data$class == "SADE" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$class == "SADE" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$devattr, na.rm=TRUE),
+ " (",sum(period_data$devattr & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$devattr & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$safetymeasure, na.rm=TRUE),
+ " (",sum(period_data$safetymeasure & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$safetymeasure & period_data$intervention==grp[2], na.rm=TRUE),")"),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- paste0("N = ", sum(data$class == "SADE"),
- " (",sum(data$class == "SADE" & data$intervention==grp[1]),",",
- sum(data$class == "SADE" & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$devattr),
- " (",sum(data$devattr & data$intervention==grp[1]),",",
- sum(data$devattr & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$safetymeasure),
- " (",sum(data$safetymeasure & data$intervention==grp[1]),",",
- sum(data$safetymeasure & data$intervention==grp[2]),")"),
+ paste0("N = ", sum(data$class == "SADE", na.rm=TRUE),
+ " (",sum(data$class == "SADE" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$class == "SADE" & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$devattr, na.rm=TRUE),
+ " (",sum(data$devattr & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$devattr & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$safetymeasure, na.rm=TRUE),
+ " (",sum(data$safetymeasure & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$safetymeasure & data$intervention==grp[2], na.rm=TRUE),")"),
)
}else{
tab <- tribble(
~desc, ~sade ,~attr, ~measures,
# row 1
'Number of cases (during reporting period)',
- sum(period_data$class == "SADE"),
- sum(period_data$devattr),
- sum(period_data$safetymeasure),
+ sum(period_data$class == "SADE", na.rm=TRUE),
+ sum(period_data$devattr, na.rm=TRUE),
+ sum(period_data$safetymeasure, na.rm=TRUE),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- sum(data$class == "SADE"),
- sum(data$devattr),
- sum(data$safetymeasure)
+ sum(data$class == "SADE", na.rm=TRUE),
+ sum(data$devattr, na.rm=TRUE),
+ sum(data$safetymeasure, na.rm=TRUE)
)
}
@@ -250,7 +259,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Other SAEs where a causality to the intervention cannot be excluded'),
stringsAsFactors = FALSE)
- if(all(!is.na(n_per_arm))){
+ if("intervention" %in% names(data)){
### define the values for the two interventional groups
grp <- names(n_per_arm)
@@ -259,20 +268,20 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
~desc, ~fatal, ~nfatal,
# row 1
'Number of cases (during reporting period)',
- paste0("N = ", sum(period_data$outcome == "Fatal" & period_data$related==1),
- " (",sum(period_data$outcome == "Fatal" & period_data$related==1 & period_data$intervention==grp[1]),",",
- sum(period_data$outcome == "Fatal" & period_data$related==1 & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$outcome != "Fatal" & period_data$related==1),
- " (",sum(period_data$outcome != "Fatal" & period_data$related==1 & period_data$intervention==grp[1]),",",
- sum(period_data$outcome != "Fatal" & period_data$related==1 & period_data$intervention==grp[2]),")"),
+ paste0("N = ", sum(period_data$outcome == "Fatal" & period_data$related==1, na.rm=TRUE),
+ " (",sum(period_data$outcome == "Fatal" & period_data$related==1 & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$outcome == "Fatal" & period_data$related==1 & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$outcome != "Fatal" & period_data$related==1, na.rm=TRUE),
+ " (",sum(period_data$outcome != "Fatal" & period_data$related==1 & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$outcome != "Fatal" & period_data$related==1 & period_data$intervention==grp[2], na.rm=TRUE),")"),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- paste0("N = ", sum(data$outcome == "Fatal" & data$related==1),
- " (",sum(data$outcome == "Fatal" & data$related==1 & data$intervention==grp[1]),",",
- sum(data$outcome == "Fatal" & data$related==1 & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$outcome != "Fatal" & data$related==1),
- " (",sum(data$outcome != "Fatal" & data$related==1 & data$intervention==grp[1]),",",
- sum(data$outcome != "Fatal" & data$related==1 & data$intervention==grp[2]),")"),
+ paste0("N = ", sum(data$outcome == "Fatal" & data$related==1, na.rm=TRUE),
+ " (",sum(data$outcome == "Fatal" & data$related==1 & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$outcome == "Fatal" & data$related==1 & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$outcome != "Fatal" & data$related==1, na.rm=TRUE),
+ " (",sum(data$outcome != "Fatal" & data$related==1 & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$outcome != "Fatal" & data$related==1 & data$intervention==grp[2], na.rm=TRUE),")"),
)
}else{
@@ -280,12 +289,12 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
~desc, ~fatal, ~nfatal,
# row 1
'Number of cases (during reporting period)',
- sum(period_data$outcome == "Fatal" & period_data$related==1),
- sum(period_data$outcome != "Fatal" & period_data$related==1),
+ sum(period_data$outcome == "Fatal" & period_data$related==1, na.rm=TRUE),
+ sum(period_data$outcome != "Fatal" & period_data$related==1, na.rm=TRUE),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- sum(data$outcome == "Fatal" & data$related==1),
- sum(data$outcome != "Fatal" & data$related==1),
+ sum(data$outcome == "Fatal" & data$related==1, na.rm=TRUE),
+ sum(data$outcome != "Fatal" & data$related==1, na.rm=TRUE),
)
}
@@ -323,7 +332,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Serious Adverse Drug Reactions, SADRs', 'Suspected Unexpected Serious Adverse Reactions, SUSARs'),
stringsAsFactors = FALSE)
- if(all(!is.na(n_per_arm))){
+ if("intervention" %in% names(data)){
grp <- names(n_per_arm)
@@ -331,56 +340,56 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
~desc, ~fatal, ~nfatal, ~nsadr, ~sadr, ~susar,
# row 1
'Number of cases (during reporting period)',
- paste0("N = ", sum(period_data$outcome == "Fatal" ),
- " (",sum(period_data$outcome == "Fatal" & period_data$intervention==grp[1]),",",
- sum(period_data$outcome == "Fatal"& period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$outcome != "Fatal" & period_data$related==1),
- " (",sum(period_data$outcome != "Fatal" & period_data$intervention==grp[1]),",",
- sum(period_data$outcome != "Fatal" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$class != "NSADR" ),
- " (",sum(period_data$class != "NSADR" & period_data$intervention==grp[1]),",",
- sum(period_data$class != "NSADR" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$class != "SADR" ),
- " (",sum(period_data$class != "SADR" & period_data$intervention==grp[1]),",",
- sum(period_data$class != "SADR" & period_data$intervention==grp[2]),")"),
- paste0("N = ", sum(period_data$class != "SUSAR" ),
- " (",sum(period_data$class != "SUSAR" & period_data$intervention==grp[1]),",",
- sum(period_data$class != "SUSAR" & period_data$intervention==grp[2]),")"),
+ paste0("N = ", sum(period_data$outcome == "Fatal" , na.rm=TRUE),
+ " (",sum(period_data$outcome == "Fatal" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$outcome == "Fatal"& period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$outcome != "Fatal" & period_data$related==1, na.rm=TRUE),
+ " (",sum(period_data$outcome != "Fatal" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$outcome != "Fatal" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$class != "NSADR", na.rm=TRUE),
+ " (",sum(period_data$class != "NSADR" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$class != "NSADR" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$class != "SADR", na.rm=TRUE),
+ " (",sum(period_data$class != "SADR" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$class != "SADR" & period_data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(period_data$class != "SUSAR", na.rm=TRUE),
+ " (",sum(period_data$class != "SUSAR" & period_data$intervention==grp[1], na.rm=TRUE),",",
+ sum(period_data$class != "SUSAR" & period_data$intervention==grp[2], na.rm=TRUE),")"),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- paste0("N = ", sum(data$outcome == "Fatal" ),
- " (",sum(data$outcome == "Fatal" & data$intervention==grp[1]),",",
- sum(data$outcome == "Fatal"& data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$outcome != "Fatal" ),
- " (",sum(data$outcome != "Fatal" & data$intervention==grp[1]),",",
- sum(data$outcome != "Fatal"& data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$class != "NSADR" ),
+ paste0("N = ", sum(data$outcome == "Fatal", na.rm=TRUE),
+ " (",sum(data$outcome == "Fatal" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$outcome == "Fatal"& data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$outcome != "Fatal", na.rm=TRUE),
+ " (",sum(data$outcome != "Fatal" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$outcome != "Fatal"& data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$class != "NSADR", na.rm=TRUE),
" (",sum(data$class != "NSADR" & data$intervention==grp[1]),",",
sum(data$class != "NSADR" & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$class != "SADR" ),
- " (",sum(data$class != "SADR" & data$intervention==grp[1]),",",
- sum(data$class != "SADR" & data$intervention==grp[2]),")"),
- paste0("N = ", sum(data$class != "SUSAR" ),
- " (",sum(data$class != "SUSAR" & data$intervention==grp[1]),",",
- sum(data$class != "SUSAR" & data$intervention==grp[2]),")"),
+ paste0("N = ", sum(data$class != "SADR", na.rm=TRUE),
+ " (",sum(data$class != "SADR" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$class != "SADR" & data$intervention==grp[2], na.rm=TRUE),")"),
+ paste0("N = ", sum(data$class != "SUSAR", na.rm=TRUE),
+ " (",sum(data$class != "SUSAR" & data$intervention==grp[1], na.rm=TRUE),",",
+ sum(data$class != "SUSAR" & data$intervention==grp[2], na.rm=TRUE),")"),
)
}else{
tab <- tribble(
~desc, ~fatal, ~nfatal, ~nsadr, ~sadr, ~susar,
# row 1
'Number of cases (during reporting period)',
- sum(period_data$outcome == "Fatal"),
- sum(period_data$outcome != "Fatal"),
- sum(period_data$class == "NSADR"),
- sum(period_data$class == "SADR"),
- sum(period_data$class == "SUSAR"),
+ sum(period_data$outcome == "Fatal", na.rm=TRUE),
+ sum(period_data$outcome != "Fatal", na.rm=TRUE),
+ sum(period_data$class == "NSADR", na.rm=TRUE),
+ sum(period_data$class == "SADR", na.rm=TRUE),
+ sum(period_data$class == "SUSAR", na.rm=TRUE),
# row 2
'Number of cases (cumulative) since the start of the clinical trial',
- sum(data$outcome == "Fatal"),
- sum(data$outcome != "Fatal"),
- sum(data$class == "NSADR"),
- sum(data$class == "SADR"),
- sum(data$class == "SUSAR")
+ sum(data$outcome == "Fatal", na.rm=TRUE),
+ sum(data$outcome != "Fatal", na.rm=TRUE),
+ sum(data$class == "NSADR", na.rm=TRUE),
+ sum(data$class == "SADR", na.rm=TRUE),
+ sum(data$class == "SUSAR", na.rm=TRUE)
)
}
diff --git a/R/asr_skeleton.R b/R/asr_skeleton.R
index aafd0b2..e85e5d0 100644
--- a/R/asr_skeleton.R
+++ b/R/asr_skeleton.R
@@ -58,7 +58,8 @@ asr_skeleton <- function(){
var_comment = "# variable containing any comment",
var_relation = "# variable containing the relationship to randomized intervention",
var_expected = "# variable saying whether the SAE was expected",
- var_devdef = "# variable containing whether the SAE is a device deficiency (MD trials only)",
+ var_devdef = "# variable containing whether there was a device deficiency (MD trials only)",
+ var_devdefcouldlead = "# variable containing whether the device deficiency could have lead to an SAE (MD trials only)",
var_devattr = "# variable containing whether the SAE is attributable to the device (MD trials only)",
var_devint = "# variable containing whether the SAE is attributable to an intervention in the trial",
var_safetymeasure = "# variable containing whether the SAE required safety related measures",
diff --git a/R/checks.R b/R/checks.R
index 4f98ec1..8504a01 100644
--- a/R/checks.R
+++ b/R/checks.R
@@ -54,3 +54,10 @@ check_listing_names <- function(names
}
+check_field_characters <- function(x){
+ if(grepl("&|
", x))
+ warning("Special character found in '", x, "'\n",
+ " Special characters or strings such as '&' and '
' may cause problems with Word.\n",
+ " We advise replacing them with other characters.")
+ return(NULL)
+}
diff --git a/R/data.R b/R/data.R
index 43d45e9..1869e32 100644
--- a/R/data.R
+++ b/R/data.R
@@ -18,6 +18,7 @@
#' \item{class}{SAE classification (SUSAR, SADR, ...)}
#' \item{expected}{Was the SAE expected}
#' \item{devdef}{(For device trials) was the SAE a device deficiency?}
+#' \item{devdefcouldlead}{(For device trials) whether the device deficiency could have lead to an SAE}
#' \item{devattr}{(For device trials) was the SAE attributable to the device?}
#' \item{devint}{(For device trials) was the SAE attributable to the intervention?}
#' \item{safetymeasure}{(For device trials) was the SAE a health hazards that required safety-related measures?}
diff --git a/data/asr_sae.rda b/data/asr_sae.rda
index b14e881..35f20c7 100644
Binary files a/data/asr_sae.rda and b/data/asr_sae.rda differ
diff --git a/data_raw/asr_sae_data.R b/data_raw/asr_sae_data.R
index 1f8d28a..7ea061a 100644
--- a/data_raw/asr_sae_data.R
+++ b/data_raw/asr_sae_data.R
@@ -25,6 +25,7 @@ sae_data <- data.frame(sae_date = last_report + msample(-20:20),
class = msample(c("SAE", "SUSAR", "SADR")),
expected = msample(c(TRUE, FALSE)),
devdef = msample(c(TRUE, FALSE)),
+ devdefcouldlead = msample(c(TRUE, FALSE)),
devattr = msample(c(TRUE, FALSE)),
devint = msample(c(TRUE, FALSE)),
safetymeasure = msample(c(TRUE, FALSE))
diff --git a/man/asr.Rd b/man/asr.Rd
index 050192c..c2d754e 100644
--- a/man/asr.Rd
+++ b/man/asr.Rd
@@ -58,6 +58,7 @@ asr(
var_relation = "related",
var_expected = "expected",
var_devdef = "devdef",
+ var_devdefcouldlead = "devdefcouldlead",
var_devattr = "devattr",
var_devint = "devint",
var_safetymeasure = "safetymeasure",
@@ -169,6 +170,8 @@ asr(
\item{var_devdef}{variable containing whether the SAE is a device deficiency}
+\item{var_devdefcouldlead}{variable containing whether the device deficiency could have lead to an SAE}
+
\item{var_devattr}{variable containing whether the SAE is attributable to the device}
\item{var_devint}{variable containing whether the SAE is attributable to an intervention in the trial}
diff --git a/man/asr_dataprep.Rd b/man/asr_dataprep.Rd
index c2645e1..74b3d8b 100644
--- a/man/asr_dataprep.Rd
+++ b/man/asr_dataprep.Rd
@@ -27,6 +27,7 @@ asr_dataprep(
var_relation = "related",
var_expected = "expected",
var_devdef = "devdef",
+ var_devdefcouldlead = "devdefcouldlead",
var_devattr = "devattr",
var_devint = "devint",
var_safetymeasure = "safetymeasure",
@@ -78,6 +79,8 @@ asr_dataprep(
\item{var_devdef}{variable containing whether the SAE is a device deficiency}
+\item{var_devdefcouldlead}{variable containing whether the device deficiency could have lead to an SAE}
+
\item{var_devattr}{variable containing whether the SAE is attributable to the device}
\item{var_devint}{variable containing whether the SAE is attributable to an intervention in the trial}
diff --git a/man/asr_sae.Rd b/man/asr_sae.Rd
index 5748936..a5942a0 100644
--- a/man/asr_sae.Rd
+++ b/man/asr_sae.Rd
@@ -21,6 +21,7 @@ A data frame with the following variables:
\item{class}{SAE classification (SUSAR, SADR, ...)}
\item{expected}{Was the SAE expected}
\item{devdef}{(For device trials) was the SAE a device deficiency?}
+\item{devdefcouldlead}{(For device trials) whether the device deficiency could have lead to an SAE}
\item{devattr}{(For device trials) was the SAE attributable to the device?}
\item{devint}{(For device trials) was the SAE attributable to the intervention?}
\item{safetymeasure}{(For device trials) was the SAE a health hazards that required safety-related measures?}