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

## ----echo=FALSE, message=FALSE, warning=FALSE---------------------------------
library(dplyr)
library(gt)
x <- OmopConstructor:::achillesAnalisisDetails |>
  mutate(Group = paste0(
    if_else(is_minimal, "minimal; ", ""),
    if_else(is_default, "default; ", ""),
    tolower(category)
  )) |>
  select(
    "ID" = "analysis_id", "Name" = "analysis_name", "1" = "stratum_1_name",
    "2" = "stratum_2_name", "3" = "stratum_3_name", "4" = "stratum_4_name",
    "5" = "stratum_5_name", "Group", "category"
  ) |>
  mutate(across(c("1", "2", "3", "4", "5"), \(x) coalesce(x, "-")))
xt <- x |>
  inner_join(
    x |>
      group_by(category) |>
      summarise(min = min(ID)),
    by = "category"
  ) |>
  arrange(min) |>
  select(!"min") |>
  group_by(category) |>
  gt() |>
  tab_spanner(label = "Analysis", columns = c("ID", "Name")) |>
  tab_spanner(label = "Stratum", columns = c("1", "2", "3", "4", "5")) |>
  tab_style(
    style = cell_text(align = "center", weight = "bold"),
    locations = cells_column_labels()
  ) |>
  tab_style(
    style = cell_text(align = "center", weight = "bold"),
    locations = cells_column_spanners()
  ) |>
  tab_style(
    style = cell_fill(color = "#4E6D8C", alpha = 0.1),
    locations = cells_body(columns = c("ID", "Name"))
  ) |>
  tab_style(
    style = cell_fill(color = "#4E6D8C", alpha = 0.5),
    locations = cells_column_labels(columns = c("ID", "Name"))
  ) |>
  tab_style(
    style = cell_fill(color = "#4E6D8C", alpha = 0.5),
    locations = cells_column_spanners(spanners = c("Analysis"))
  ) |>
  tab_style(
    style = cell_fill(color = "#2A9D8F", alpha = 0.1),
    locations = cells_body(columns = c("1", "2", "3", "4", "5"))
  ) |>
  tab_style(
    style = cell_fill(color = "#2A9D8F", alpha = 0.5),
    locations = cells_column_labels(columns = c("1", "2", "3", "4", "5"))
  ) |>
  tab_style(
    style = cell_fill(color = "#2A9D8F", alpha = 0.5),
    locations = cells_column_spanners(spanners = "Stratum")
  ) |>
  tab_style(
    style = cell_fill(color = "#E9C46A", alpha = 0.1),
    locations = cells_body(columns = c("Group"))
  ) |>
  tab_style(
    style = cell_fill(color = "#E9C46A", alpha = 0.5),
    locations = cells_column_labels(columns = c("Group"))
  ) |>
  tab_style(
    style = cell_fill(color = "#D1D5DB", alpha = 0.1),
    locations = cells_row_groups()
  ) 

## ----echo=FALSE---------------------------------------------------------------
xt

## -----------------------------------------------------------------------------
library(omock)
library(OmopConstructor)

cdm <- mockCdmFromDataset(datasetName = "GiBleed", source = "duckdb")
cdm

cdm <- buildAchillesTables(cdm = cdm, achillesId = "minimal")
cdm

cdm$achilles_results

