Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 blockr update #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Package: blockr.clinical.timelines
Title: Clinical Timeline Block
Version: 0.0.0.9000
Version: 0.0.1.9000
Authors@R:
c(
person(family = "Bristol Myers Squibb",
role = c("cph", "fnd")),
person(given = "John",
family = "Coene",
role = c("aut", "cre"),
email = "[email protected]")
email = "[email protected]"),
person(given = "David",
family = "Granjon",
role = c("ctb"),
email = "[email protected]")
)
Description: Create clinical timeline blocks.
License: GPL (>= 3)
Expand Down
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Generated by roxygen2: do not edit by hand

S3method(evaluate_block,clinical_timeline_block)
S3method(generate_server,clinical_timeline_block)
S3method(server_output,clinical_timeline_block)
S3method(uiOutputBlock,clinical_timeline_block)
export(clinical_timeline_block)
export(clinical_timeline_data_block)
export(new_clinical_timeline_block)
export(new_clinical_timeline_data_block)
import(blockr)
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# blockr.pharmaversesdtm 0.0.1.9000

## Documentation
- Updated readme example with new API.

## Breaking changes
- Change blocks constructor names to `new_*_block` according to `{blockr}` 0.0.2.
- Remove `data` parameter from constructor functions.

# blockr.clinical.timelines

* Initial GitHub release.
60 changes: 27 additions & 33 deletions R/core.R
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
new_clinical_timeline_block <- function(data, ...) {
#' Clinical timeline block
#'
#' Clinical timeline block
#'
#' @param ... Ignored.
#'
#' @import blockr
#' @export
new_clinical_timeline_block <- function(...) {
all_cols <- function(data) colnames(data)
usubjid_col <- function(data) {
cols <- colnames(data)

if("USUBJID" %in% cols)
if ("USUBJID" %in% cols) {
return("USUBJID")
}

if("SUBJID" %in% cols)
if ("SUBJID" %in% cols) {
return("SUBJID")
}

cols[1]
}

event_col <- function(data) {
cols <- colnames(data)

if("DOMAIN" %in% cols)
if ("DOMAIN" %in% cols) {
return("DOMAIN")
}

cols[1]
}

stdt_col <- function(data) {
cols <- colnames(data)

if("STDT" %in% cols)
if ("STDT" %in% cols) {
return("STDT")
}

if("STDTC" %in% cols)
if ("STDTC" %in% cols) {
return("STDTC")
}

cols[1]
}

endt_col <- function(data) {
cols <- colnames(data)

if("ENDT" %in% cols)
if ("ENDT" %in% cols) {
return("ENDT")
}

if("ENDTC" %in% cols)
if ("ENDTC" %in% cols) {
return("ENDTC")
}

cols[1]
}
Expand Down Expand Up @@ -95,44 +110,23 @@ new_clinical_timeline_block <- function(data, ...) {
)
}

#' Clinical timeline block
#'
#' Clinical timeline block
#'
#' @param data Dataset.
#' @param ... Ignored.
#'
#' @import blockr
#' @export
clinical_timeline_block <- function(data, ...){
blockr::initialize_block(new_clinical_timeline_block(data, ...), data)
}

#' @method server_output clinical_timeline_block
#' @export
server_output.clinical_timeline_block <- function (x, result, output) {
server_output.clinical_timeline_block <- function(x, result, output) {
clinical.timelines::renderClinical_timeline(result())
}

#' @method uiOutputBlock clinical_timeline_block
#' @export
uiOutputBlock.clinical_timeline_block <- function (x, ns) {
uiOutputBlock.clinical_timeline_block <- function(x, ns) {
shiny::div(
style = "overflow-y:auto",
clinical.timelines::clinical_timelineOutput(ns("res"), height = "70vh")
)
}

#' @method evaluate_block clinical_timeline_block
#' @export
evaluate_block.clinical_timeline_block <- function (x, data, ...) {
stopifnot(...length() == 0L)
eval(substitute(data %>% expr, list(expr = blockr::generate_code(x))),
list(data = data))
}

#' @method generate_server clinical_timeline_block
#' @export
generate_server.clinical_timeline_block <- function (...) {
generate_server.clinical_timeline_block <- function(...) {
blockr:::generate_server_block(...)
}
44 changes: 21 additions & 23 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
#' Clinical Timeline Data Block
#'
#'
#' This data block is used to create a clinical timeline data frame from the ADaM data sets.
#'
#'
#' @param ... Ignored.
#'
#'
#' @export
clinical_timeline_data_block <- function(...){
new_clinical_timeline_data_block <- function(...) {
blockr::new_block(
fields = list(),
expr = quote({
build <- function(
adex = pharmaverseadam::adex,
adcm = pharmaverseadam::adcm,
adae = pharmaverseadam::adae
){
build <- function(adex = pharmaverseadam::adex,
adcm = pharmaverseadam::adcm,
adae = pharmaverseadam::adae) {
cm <- adcm |>
dplyr::select(SUBJID, SITEID, CMSTDY, CMENDY, CMSTDTC, CMENDTC, CMDECOD, CMSEQ) |>
dplyr::rename(STDY = CMSTDY, ENDY = CMENDY, STDTC = CMSTDTC, ENDTC = CMENDTC, SEQ = CMSEQ, DECOD = CMDECOD) |>
dplyr::mutate(DOMAIN = "Concomitant Medications")

cm <- adcm |>
dplyr::select(SUBJID, SITEID, CMSTDY, CMENDY, CMSTDTC, CMENDTC, CMDECOD, CMSEQ) |>
dplyr::rename(STDY = CMSTDY, ENDY = CMENDY, STDTC = CMSTDTC, ENDTC = CMENDTC, SEQ = CMSEQ, DECOD = CMDECOD) |>
dplyr::mutate(DOMAIN = "Concomitant Medications")
ae <- adae |>
dplyr::select(SUBJID, SITEID, AESTDY, AEENDY, AESTDTC, AEENDTC, AEDECOD, AESEQ) |>
dplyr::rename(STDY = AESTDY, ENDY = AEENDY, STDTC = AESTDTC, ENDTC = AEENDTC, SEQ = AESEQ, DECOD = AEDECOD) |>
dplyr::mutate(DOMAIN = "Adverse Events")

ae <- adae |>
dplyr::select(SUBJID, SITEID, AESTDY, AEENDY, AESTDTC, AEENDTC, AEDECOD, AESEQ) |>
dplyr::rename(STDY = AESTDY, ENDY = AEENDY, STDTC = AESTDTC, ENDTC = AEENDTC, SEQ = AESEQ, DECOD = AEDECOD) |>
dplyr::mutate(DOMAIN = "Adverse Events")

ex <- adex |>
dplyr::select(SUBJID, SITEID, EXSTDY, EXENDY, EXSTDTC, EXENDTC, EXDOSE, EXDOSU, EXDOSFRQ, EXSEQ) |>
ex <- adex |>
dplyr::select(SUBJID, SITEID, EXSTDY, EXENDY, EXSTDTC, EXENDTC, EXDOSE, EXDOSU, EXDOSFRQ, EXSEQ) |>
dplyr::mutate(DOMAIN = "Exposure", EXDECOD = paste(EXDOSE, EXDOSU, EXDOSFRQ)) |>
dplyr::rename(STDY = EXSTDY, ENDY = EXENDY, STDTC = EXSTDTC, ENDTC = EXENDTC, SEQ = EXSEQ, DECOD = EXDECOD)

dplyr::bind_rows(ex, ae, cm) |>
dplyr::select(DOMAIN, SITEID, SUBJID, SEQ, STDY, ENDY, STDTC, ENDTC, DECOD) |>
dplyr::arrange(DOMAIN, SUBJID, SEQ, STDY) |>
dplyr::bind_rows(ex, ae, cm) |>
dplyr::select(DOMAIN, SITEID, SUBJID, SEQ, STDY, ENDY, STDTC, ENDTC, DECOD) |>
dplyr::arrange(DOMAIN, SUBJID, SEQ, STDY) |>
dplyr::filter(!is.na(STDY), !is.na(ENDY))
}

build()
}),
...,
class = c("clinical_timeline_data_block", "data_block")
)
}
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.onLoad <- \(...){
blockr::register_block(
clinical_timeline_block,
new_clinical_timeline_block,
"Clinical timeline",
"Visualise events over time",
input = "data.frame",
Expand All @@ -10,7 +10,7 @@
)

blockr::register_block(
clinical_timeline_data_block,
new_clinical_timeline_data_block,
"Clinical timeline data",
"Prepare data for clinical timeline visualisation",
input = NA_character_,
Expand Down
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,14 @@ remotes::install_github("blockr-org/blockr.clinical.timelines")
## Example

``` r
library(shiny)
library(blockr)
library(blockr.clinical.timelines)

stack <- blockr::new_stack(
clinical_timeline_data_block,
clinical_timeline_block
new_clinical_timeline_data_block,
new_clinical_timeline_block
)

ui <- fluidPage(
theme = bslib::bs_theme(5L),
generate_ui(stack)
)

server <- function(input, output, session) {
generate_server(stack)
}

shinyApp(ui, server)
serve_stack(stack)
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.