## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)

## ----install-cran-------------------------------------------------------------
# # Install from CRAN
# # install.packages("rxref")

## ----install-dev--------------------------------------------------------------
# # install.packages("pak")
# # pak::pak("ssmithm/rxref")

## ----pkg-load-----------------------------------------------------------------
# library(rxref)
# library(dplyr)

## ----resolve------------------------------------------------------------------
# resolve(c(
#   "metformin 500 mg tablet",
#   "00093-1048-01",
#   "8610"
# ))

## ----get-props----------------------------------------------------------------
# ids <- c("860975", "860976")
# 
# get_properties(ids)

## ----map-to-rxcuis------------------------------------------------------------
# map_ndc_to_rxcui(c(
#   "00093-1048-01",
#   "00093-1048-10"
# ))

## ----map-to-ndcs--------------------------------------------------------------
# map_rxcui_to_ndc("860975")

## ----map-filtering------------------------------------------------------------
# map_rxcui_to_ndc("860975", status = "ACTIVE")

## ----find-ings----------------------------------------------------------------
# find_ingredients(c("metformin", "semaglutide", "lisinopril"))

## ----ings2--------------------------------------------------------------------
# ingredients <- find_ingredients(c("metformin", "semaglutide")) |>
#   filter(tty == "IN") |>
#   distinct(
#     ingredient_rxcui = rxcui,
#     ingredient_name = name
#   )
# 
# ingredients

## ----prods-for-ings-----------------------------------------------------------
# products <- products_for_ingredients(
#   ingredients$ingredient_rxcui,
#   concept_status = "active"
# )
# 
# products

## ----historical-prods---------------------------------------------------------
# products_historical <- products_for_ingredients(
#   ingredients$ingredient_rxcui,
#   concept_status = "active_and_historical"
# )
# 
# products_historical

## ----ttys---------------------------------------------------------------------
# product_ttys("default")
# product_ttys("extended_product")
# product_ttys("extended")

## ----extended-product-concepts------------------------------------------------
# products_extended <- products_for_ingredients(
#   ingredients$ingredient_rxcui,
#   ttys = product_ttys("extended_product"),
#   concept_status = "active"
# )
# 
# products_extended

## ----search-------------------------------------------------------------------
# search_drug(
#   term = "metformin",
#   return = "product",
#   route = "ORAL"
# )

## ----search-ndcs--------------------------------------------------------------
# search_drug(
#   term = "metformin",
#   return = "ndc",
#   route = "ORAL",
#   ndc_status = "ACTIVE"
# )

## ----search-concepts-ndcs-----------------------------------------------------
# search_drug(
#   term = "metformin",
#   return = "both",
#   route = "ORAL",
#   ndc_status = "ACTIVE"
# )

## ----search-historical--------------------------------------------------------
# search_drug(
#   term = "metformin",
#   return = "ndc",
#   route = "ORAL",
#   concept_status = "active_and_historical",
#   ndc_status = c("ACTIVE", "OBSOLETE", "UNSPECIFIED")
# )

## ----clin-attrs---------------------------------------------------------------
# attrs <- get_clinical_attributes(products$product_rxcui)
# 
# attrs

## ----clin-attrs-routes--------------------------------------------------------
# attrs |>
#   count(routes, dose_form_groups, sort = TRUE)

## ----clin-attrs-routes-fdcs---------------------------------------------------
# attrs |>
#   filter(n_ingredients > 1)

## ----filter-by-route----------------------------------------------------------
# oral_products <- products |>
#   filter_products_by_route(route = "ORAL")
# 
# oral_products

## ----cache_mem----------------------------------------------------------------
# rxref_conf(cache = cachem::cache_mem())

## ----adjust-delay-------------------------------------------------------------
# rxref_conf(rate_delay = 0.2)

