## ----setup--------------------------------------------------------------------
library(dplyr)
library(readr)
library(knitr)
library(kableExtra)

# Path to the directory containing pipeline outputs.
# Adjust this to match your project layout if rendering from a different location.
output_dir <- "data-raw/anztox/raw"


## ----tbl-db-differences-------------------------------------------------------
tibble::tribble(
  ~Aspect, ~`toxicityvalue2000`, ~`toxicityvalue2016`,
  "Chronic/acute flag",     "`testtype_id` join → `testtype` text field",           "`ischronic` boolean — direct, no join needed",
  "`concentrationused`",    "Some NA — filter on `!is.na()`",                        "All rows populated — no filter needed",
  "Endpoint field",         "`endpoint_id` → `endpoint.name`",                       "`endpointmeasurement_id` + `endpointfrompaper_id`, coalesced",
  "Endpoint vocabulary",    "Standardised 2000 codes (`MORT`, `GRO`, etc.)",          "Free-text 2016 labels — mapped to 2000 codes via `endpoint_2016_to_2000_lookup`",
  "Reference / status",     "`reference_id`, `status_id` joins",                     "Not present — `datasource` text field instead, very limited coverage",
  "Water chemistry fields", "`temperature`, `ph`, `hardness` present",               "Not present",
  "`guidelinegroup_id`",    "Not present",                                            "Present — links to pre-computed guideline values"
) |>
  kable(booktabs = TRUE) |>
  kable_styling(full_width = TRUE, font_size = 12) |>
  column_spec(1, width = "22%", bold = TRUE) |>
  column_spec(2, width = "39%") |>
  column_spec(3, width = "39%")


## ----tbl-testtype-------------------------------------------------------------
tibble::tribble(
  ~`Test class`, ~`testtype values matched`,
  "`chronic`",    '`"chronic"`',
  "`subchronic`", '`"sub-chronic"`, `"subchronic"` (regex)',
  "`acute`",      '`"acute"`',
  "`other`",      "anything else"
) |>
  kable(booktabs = TRUE) |>
  kable_styling(full_width = FALSE)


## ----tbl-dgv-summary----------------------------------------------------------
dgv_summary_path <- file.path(output_dir, "summary_2000_dgvs_combined.csv")

if (file.exists(dgv_summary_path)) {
  dgv_summary <- read_csv(dgv_summary_path, show_col_types = FALSE)
  dgv_summary |>
    kable(
      col.names = c("Category", "Count"),
      booktabs  = TRUE,
      caption   = "DGV matching summary (from summary_2000_dgvs_combined.csv)"
    ) |>
    kable_styling(full_width = FALSE) |>
    row_spec(0, bold = TRUE) |>
    row_spec(1, bold = TRUE, background = "#f0f0f0")
} else {
  cat(
    "> **Note:** `summary_2000_dgvs_combined.csv` not found at `",
    dgv_summary_path,
    "`. Run `DATASET.R` to generate it, then re-render this document.",
    sep = ""
  )
}

