R/stdzRoute.R

Defines functions stdzRoute

Documented in stdzRoute

#' Standardize Route Entity
#'
#' This function standardizes the route entity.
#'
#' @param x character vector of extracted route values
#'
#' @return character vector
#'
#' @examples
#' stdzRoute(c('oral', 'po', 'subcut'))
#' @export

stdzRoute <- function(x) {
  rte <- gsub('[[:space:].]', '', tolower(x))
  urte <- unique(rte)
  useUnq <- length(urte) != length(rte)
  if(useUnq) {
    mix <- match(rte, urte)
    rte <- urte
  }
  rte[grep('skin', rte)] <- 'transdermal'
  rte[grep('iv|intravenous', rte)] <- 'iv'
  rte[grep('mouth|oral|po', rte)] <- 'orally'
  rte[grep('subcut|sq', rte)] <- 'sq'
  rte[nchar(rte) == 0] <- NA
  if(useUnq) {
    rte <- rte[mix]
  }
  rte
}

Try the EHR package in your browser

Any scripts or data that you put into this service are public.

EHR documentation built on Dec. 28, 2022, 1:31 a.m.