% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_death_registry}
\alias{derive_death_registry}
\title{Derive a binary disease flag from UKB death registry}
\usage{
derive_death_registry(
  data,
  name,
  icd10,
  match = c("prefix", "exact", "regex"),
  primary_cols = NULL,
  secondary_cols = NULL,
  date_cols = NULL
)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data containing
death registry fields.}

\item{name}{(character) Output column prefix, e.g. \code{"disease"} produces
\code{disease_death} and \code{disease_death_date}.}

\item{icd10}{(character) ICD-10 code(s) to match.  For \code{"prefix"}
and \code{"exact"}, supply a vector such as \code{c("L20", "L21")}.
For \code{"regex"}, supply a single regex string.}

\item{match}{(character) Matching strategy: \code{"prefix"} (default),
\code{"exact"}, or \code{"regex"}.}

\item{primary_cols}{(character or NULL) Names of primary cause columns
(\code{p40001_i*}).  \code{NULL} = auto-detect via field 40001.}

\item{secondary_cols}{(character or NULL) Names of secondary cause
columns (\code{p40002_i*_a*}).  \code{NULL} = auto-detect via field
40002.}

\item{date_cols}{(character or NULL) Names of death date columns
(\code{p40000_i*}).  \code{NULL} = auto-detect via field 40000.}
}
\value{
The input \code{data} with two new columns added in-place:
\code{{name}_death} (logical) and \code{{name}_death_date} (IDate).
Always returns a \code{data.table}.
}
\description{
Death registry records store the underlying (primary) cause of death in
field \code{p40001} and contributory (secondary) causes in field
\code{p40002}, both coded in ICD-10.  The date of death is in field
\code{p40000}.  All three fields have an instance dimension (\code{i0},
\code{i1}) reflecting potential amendments; \code{p40002} additionally
has an array dimension (\code{a0}, \code{a1}, \ldots).
}
\details{
\describe{
\item{\code{{name}_death}}{Logical flag: \code{TRUE} if any death
registry record (primary or secondary cause) contains a matching
ICD-10 code.}
\item{\code{{name}_death_date}}{Earliest death date across matching
instances (\code{IDate}).  Note: this is the \emph{date of death},
not onset date.}
}
}
\examples{
\donttest{
dt <- ops_toy(n = 100)
derive_death_registry(dt, name = "mi",   icd10 = "I21")
derive_death_registry(dt, name = "lung", icd10 = "C34")
}
}
