% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_cancer_registry}
\alias{derive_cancer_registry}
\title{Derive a binary disease flag from UKB cancer registry}
\usage{
derive_cancer_registry(
  data,
  name,
  icd10 = NULL,
  histology = NULL,
  behaviour = NULL,
  code_cols = NULL,
  hist_cols = NULL,
  behv_cols = NULL,
  date_cols = NULL
)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data containing
cancer registry fields.}

\item{name}{(character) Output column prefix, e.g. \code{"outcome_invasive"}
produces \code{outcome_invasive_cancer} and
\code{outcome_invasive_cancer_date}.}

\item{icd10}{(character or NULL) Regular expression matched against the
ICD-10 code column (\code{p40006}).  \code{NULL} = no ICD-10 filter.
Examples: \code{"^C44"}, \code{"^(C44|D04)"}.}

\item{histology}{(integer vector or NULL) Histology codes to retain
(\code{p40011}).  \code{NULL} = no histology filter.
Example: \code{c(8070:8078, 8083, 8084)}.}

\item{behaviour}{(integer vector or NULL) Behaviour codes to retain
(\code{p40012}).  \code{NULL} = no behaviour filter.
Typical values: \code{3L} (invasive / malignant),
\code{2L} (in situ).}

\item{code_cols}{(character or NULL) Names of ICD-10 code columns
(\code{p40006_i*}).  \code{NULL} = auto-detect via field 40006.}

\item{hist_cols}{(character or NULL) Names of histology columns
(\code{p40011_i*}).  \code{NULL} = auto-detect via field 40011.}

\item{behv_cols}{(character or NULL) Names of behaviour columns
(\code{p40012_i*}).  \code{NULL} = auto-detect via field 40012.}

\item{date_cols}{(character or NULL) Names of diagnosis date columns
(\code{p40005_i*}).  \code{NULL} = auto-detect via field 40005.}
}
\value{
The input \code{data} with two new columns added in-place:
\code{{name}_cancer} (logical) and \code{{name}_cancer_date} (IDate).
Always returns a \code{data.table}.
}
\description{
The UK Biobank cancer registry links each participant's cancer diagnoses
from national cancer registries.  Each diagnosis is stored as a separate
instance with four parallel fields: ICD-10 code (\code{p40006}), histology
code (\code{p40011}), behaviour code (\code{p40012}), and diagnosis date
(\code{p40005}).  Unlike HES or self-report data, each instance holds
exactly one record - there is no array (\code{a*}) dimension.
}
\details{
All three filter arguments (\code{icd10}, \code{histology},
\code{behaviour}) are applied with AND logic: a record must satisfy
every non-\code{NULL} filter to be counted.  For OR conditions (e.g.\
D04 \emph{or} C44 with specific histology), call the function twice and
combine the resulting columns downstream.

\describe{
\item{\code{{name}_cancer}}{Logical flag: \code{TRUE} if any cancer
registry record satisfies all supplied filters.}
\item{\code{{name}_cancer_date}}{Earliest matching diagnosis date
(\code{IDate}).}
}
}
\examples{
\donttest{
dt <- ops_toy(n = 100)
derive_cancer_registry(dt, name = "skin",     icd10 = "^C44")
derive_cancer_registry(dt, name = "invasive", icd10 = "^C", behaviour = 3L)
}
}
