% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_icd10}
\alias{derive_icd10}
\title{Derive a unified ICD-10 disease flag across multiple UKB data sources}
\usage{
derive_icd10(
  data,
  name,
  icd10,
  source = c("hes", "death", "first_occurrence", "cancer_registry"),
  match = c("prefix", "exact", "regex"),
  fo_field = NULL,
  fo_col = NULL,
  histology = NULL,
  behaviour = NULL,
  hes_code_col = NULL,
  hes_date_cols = NULL,
  primary_cols = NULL,
  secondary_cols = NULL,
  death_date_cols = NULL,
  cr_code_cols = NULL,
  cr_hist_cols = NULL,
  cr_behv_cols = NULL,
  cr_date_cols = NULL
)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data.}

\item{name}{(character) Output column prefix, e.g. \code{"disease"} produces
\code{disease_icd10} and \code{disease_icd10_date}, plus intermediate columns
such as \code{disease_hes}, \code{disease_hes_date}, etc.}

\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.  When
\code{"cancer_registry"} is included in \code{source}, \code{icd10}
and \code{match} are automatically converted to a regex and passed to
\code{\link{derive_cancer_registry}}.}

\item{source}{(character) One or more of \code{"hes"},
\code{"death"}, \code{"first_occurrence"}, \code{"cancer_registry"}.
Defaults to all four.}

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

\item{fo_field}{(integer or character or NULL) UKB field ID for the
First Occurrence column (e.g. \code{131666L} for E11).  Required when
\code{"first_occurrence"} is in \code{source} and \code{fo_col} is
\code{NULL}.}

\item{fo_col}{(character or NULL) Column name of the First Occurrence
field in \code{data}.  Alternative to \code{fo_field}.}

\item{histology}{(integer vector or NULL) Passed to
\code{\link{derive_cancer_registry}}.  Ignored for other sources.}

\item{behaviour}{(integer vector or NULL) Passed to
\code{\link{derive_cancer_registry}}.  Ignored for other sources.}

\item{hes_code_col}{(character or NULL) Passed as \code{disease_cols}
to \code{\link{derive_hes}}.}

\item{hes_date_cols}{(character or NULL) Passed as \code{date_cols}
to \code{\link{derive_hes}}.}

\item{primary_cols}{(character or NULL) Passed to
\code{\link{derive_death_registry}}.}

\item{secondary_cols}{(character or NULL) Passed to
\code{\link{derive_death_registry}}.}

\item{death_date_cols}{(character or NULL) Passed as \code{date_cols}
to \code{\link{derive_death_registry}}.}

\item{cr_code_cols}{(character or NULL) Passed as \code{code_cols}
to \code{\link{derive_cancer_registry}}.}

\item{cr_hist_cols}{(character or NULL) Passed as \code{hist_cols}
to \code{\link{derive_cancer_registry}}.}

\item{cr_behv_cols}{(character or NULL) Passed as \code{behv_cols}
to \code{\link{derive_cancer_registry}}.}

\item{cr_date_cols}{(character or NULL) Passed as \code{date_cols}
to \code{\link{derive_cancer_registry}}.}
}
\value{
The input \code{data} with \code{{name}_icd10} (logical) and
\code{{name}_icd10_date} (IDate) added in-place, plus all intermediate
source columns.  Always returns a \code{data.table}.
}
\description{
A high-level wrapper that calls one or more of \code{\link{derive_hes}},
\code{\link{derive_death_registry}}, \code{\link{derive_first_occurrence}},
and \code{\link{derive_cancer_registry}} according to the \code{source}
argument, then combines their results into a single status flag and
earliest-date column.
}
\details{
All intermediate source columns (\code{{name}_hes}, \code{{name}_death},
\code{{name}_fo}, \code{{name}_cancer} and their \code{_date} counterparts)
are retained in \code{data} so that per-source contributions remain
traceable.

\describe{
\item{\code{{name}_icd10}}{Logical flag: \code{TRUE} if any selected
source contains a matching record.}
\item{\code{{name}_icd10_date}}{Earliest matching date across all
selected sources (\code{IDate}).}
}
}
\examples{
\donttest{
dt <- ops_toy(n = 100)
derive_icd10(dt, name = "htn",
             icd10  = "I10",
             source = c("hes", "death"))
derive_icd10(dt, name = "mi",
             icd10  = "I21",
             source = c("hes", "death", "first_occurrence"),
             fo_col = "p131742")
}
}
