Skip to content
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Imports:
ggplot2 (>= 3.2),
ggpubr,
grid,
here,
httr,
jpeg,
jsonlite,
Expand All @@ -44,7 +45,6 @@ Imports:
tidyr,
Suggests:
devtools,
here,
rsconnect,
testthat,
yaml,
Expand Down
10 changes: 5 additions & 5 deletions R/getDrugPK.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Get the pharmacokinetic and pharmacodynamic value for a drug based on
# patient covariates
getDrugPK <- function(
drug = "propofol",
weight = 70,
height = 170,
age = 50,
sex = "male",
drug,
weight,
height,
age,
sex,
drugDefaults
)
{
Expand Down
13 changes: 13 additions & 0 deletions R/globalVariables.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library(here)

facetFont <- c( 20, 18, 18, 16, 14, 14, 14, 13, 13, 12, 11, 10, 9, 9, 8, 8)
labelFont <- c( 16, 15, 14, 13, 12, 11, 9, 8, 8, 7, 6, 6, 5, 5, 5, 5)
Expand Down Expand Up @@ -57,3 +58,15 @@ maxtimes <- data.frame(
times = c(10, 30, 60, 90, 120, 180, 240, 300, 360, 480, 600, 720, 1440, 1680, 1920, 2880, 4320, 5760,7200, 1000000 ),
steps = c( 1, 5, 10, 15, 15, 30, 30, 60, 60, 60, 120, 120, 240, 240, 240, 480, 480, 720, 720, 1440)
)

eventDefaults <- read.csv(here("data", "Event Defaults.csv"), stringsAsFactors = FALSE)

drugUnitsExpand <- function(units) {
strsplit(units, ",")
}

drugDefaults_global <- (function() {
drugDefaults <- read.csv(here("data", "Drug Defaults.csv"), stringsAsFactors = FALSE, na.strings = "")
drugDefaults$Units <- drugUnitsExpand(drugDefaults$Units)
drugDefaults
})()
15 changes: 3 additions & 12 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ for (file in list.files("R", pattern = "\\.R$")) {
#CANCEL <- readPNG("www/cancel.png", native=TRUE)
enableBookmarking(store = "url")

eventDefaults_global <- read.csv("data/Event Defaults.csv", stringsAsFactors = FALSE)
eventDefaults <- eventDefaults_global

drugDefaults_global <- read.csv("data/Drug Defaults.csv", stringsAsFactors = FALSE, na.strings = "")
drugUnitsSimplify <- function(units) {
unlist(lapply(units, paste, collapse = ","))
}

# Load individual drug routines
for (drug in drugDefaults_global$Drug) {
Expand Down Expand Up @@ -88,14 +87,6 @@ nothingtoPlot <- staticPlot(
)
)

drugUnitsExpand <- function(units) {
strsplit(units, ",")
}
drugUnitsSimplify <- function(units) {
unlist(lapply(units, paste, collapse = ","))
}
drugDefaults_global$Units <- drugUnitsExpand(drugDefaults_global$Units)

blanks <- rep("", 6)
doseTableInit <- data.frame(
Drug = c("propofol","fentanyl","remifentanil","rocuronium", blanks),
Expand Down
111 changes: 111 additions & 0 deletions tests/testthat/test-getDrugPK.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
context("getDrugPKtest")

#library(shiny)
library(here)

source(here('data', 'drugs', 'propofol.R'))

test_that("it returns the same value", {
drug <- "propofol"
weight <- 70
height <- 170
age <- 50
sex <- "male"
drugDefaults <- drugDefaults_global
# drugDefaults <- shiny::reactiveVal(drugDefaults_global)/


actual <- getDrugPK(drug, weight, height, age, sex, drugDefaults)
expected <- list(
drug = "propofol",
PK = list(
default = list(
v1 = 6.283078,
v2 = 20.17078,
v3 = 1004.196,
cl1 = 1.551355,
cl2 = 1.516118,
cl3 = 2.97701,
k10 = 0.24691,
k12 = 0.2413017,
k13 = 0.473814,
k21 = 0.07516406,
k31 = 0.002964571,
ka_PO = 0,
bioavailability_PO = 0,
tlag_PO = 0,
ka_IM = 0,
bioavailability_IM = 0,
tlag_IM = 0,
ka_IN = 0,
bioavailability_IN = 0,
tlag_IN = 0,
customFunction = "",
lambda_1 = 0.9834275,
lambda_2 = 0.05572286,
lambda_3 = 0.001004003,
ke0 = 0.3973057,
p_coef_bolus_l1 = 0.1555113,
p_coef_bolus_l2 = 0.00321584,
p_coef_bolus_l3 = 0.0004304708,
e_coef_bolus_l1 = -0.1054142,
e_coef_bolus_l2 = 0.003740444,
e_coef_bolus_l3 = 0.0004315614,
e_coef_bolus_ke0 = 0.1012422,
p_coef_infusion_l1 = 0.158132,
p_coef_infusion_l2 = 0.05771132,
p_coef_infusion_l3 = 0.4287546,
e_coef_infusion_l1 = -0.1071906,
e_coef_infusion_l2 = 0.06712584,
e_coef_infusion_l3 = 0.4298409,
e_coef_infusion_ke0 = 0.2548219,
p_coef_PO_l1 = 0,
p_coef_PO_l2 = 0,
p_coef_PO_l3 = 0,
p_coef_PO_ka = 0,
e_coef_PO_l1 = 0,
e_coef_PO_l2 = 0,
e_coef_PO_l3 = 0,
e_coef_PO_ke0 = 0,
e_coef_PO_ka = 0,
p_coef_IM_l1 = 0,
p_coef_IM_l2 = 0,
p_coef_IM_l3 = 0,
p_coef_IM_ka = 0,
e_coef_IM_l1 = 0,
e_coef_IM_l2 = 0,
e_coef_IM_l3 = 0,
e_coef_IM_ke0 = 0,
e_coef_IM_ka = 0,
p_coef_IN_l1 = 0,
p_coef_IN_l2 = 0,
p_coef_IN_l3 = 0,
p_coef_IN_ka = 0,
e_coef_IN_l1 = 0,
e_coef_IN_l2 = 0,
e_coef_IN_l3 = 0,
e_coef_IN_ke0 = 0,
e_coef_IN_ka = 0
)
),
tPeak = 1.6,
pkEvents = "default",
reference = "Not Available",
weight = 70,
height = 170,
age = 50,
sex = "male",
upperTypical = drugDefaults$Upper,
lowerTypical = drugDefaults$Lower,
typical = drugDefaults$Typical,
MEAC = drugDefaults$MEAC,
Concentration.Units = drugDefaults$Concentration.Units,
Bolus.Units = drugDefaults$Bolus.Units,
Infusion.Units = drugDefaults$Infusion.Units,
Units = drugDefaults$Units,
Default.Units = drugDefaults$Default.Units,
emerge = drugDefaults$Emerge
)

expect_equal_rounded(actual, expected)
})