Skip to content

Conversation

@kylebaron
Copy link
Collaborator

@kylebaron kylebaron commented Oct 14, 2025

This PR provides adds check between modeled infusions duration (D) or rate (R) and the rate column in the input data set, going the opposite way of what we have now.

For dosing records, if there is a positive infusion duration and data set rate is not -2, an error will be issued. If there is a positive infusion rate and data set rate is not -1, a similar error will be issued.

This will be the default behavior (do the check and issue the error). Original behavior can be restored by turning off these checks both by a block option (@!check_modeled_infusions) or through the CHECK_MODELED_INSUSIONS macro available in $PREAMBLE).

@kylebaron
Copy link
Collaborator Author

kylebaron commented Oct 14, 2025

Developed this code to extend dosing_cmts , but I think I'll revert to the old code until we need these extra outputs. The addition pulls in not only the compartment names, but also what type of feature is implemented (lag time, infusion rate etc).

dosing_cmts <- function(x, what) {
  ans <- list(
    cmt = character(0), 
    model_rate = character(0), 
    model_dur = character(0)
  )
  if(!is.character(x)) return(ans)
  x <- strsplit(x, "\n", fixed = TRUE)
  x <- unlist(x, use.names = FALSE)
  m <- regexpr("(ALAG|F|R|D)\\_[^= ]+", x, perl = TRUE)
  m <- regmatches(x, m)
  m <- trimws(m)
  m <- strsplit(m, "_", fixed = TRUE)
  if(!length(m)) return(ans)
  op <- s_pick(m, 1)
  cmt <- s_pick(m, 2) 
  keep <- cmt %in% what
  op <- op[keep]
  cmt <- cmt[keep]
  ans$cmt <- unique(cmt)
  ans$model_rate <- unique(cmt[op=="R"])
  ans$model_dur <- unique(cmt[op=="D"])
  return(ans)
}

@kylebaron kylebaron changed the title Strict infusion Code / data consistency checking for modeled infusions Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants