% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_case}
\alias{derive_case}
\title{Combine self-report and ICD-10 sources into a unified case definition}
\usage{
derive_case(
  data,
  name,
  icd10_col = NULL,
  selfreport_col = NULL,
  icd10_date_col = NULL,
  selfreport_date_col = NULL
)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data.}

\item{name}{(character) Column prefix used both to locate the default
input columns and to name the output columns.  Defaults:
\code{{name}_icd10}, \code{{name}_selfreport},
\code{{name}_icd10_date}, \code{{name}_selfreport_date}.}

\item{icd10_col}{(character or NULL) Name of the ICD-10 status column.
\code{NULL} = \code{paste0(name, "_icd10")}.}

\item{selfreport_col}{(character or NULL) Name of the self-report status
column.  \code{NULL} = \code{paste0(name, "_selfreport")}.}

\item{icd10_date_col}{(character or NULL) Name of the ICD-10 date column.
\code{NULL} = \code{paste0(name, "_icd10_date")}.}

\item{selfreport_date_col}{(character or NULL) Name of the self-report date
column.  \code{NULL} = \code{paste0(name, "_selfreport_date")}.}
}
\value{
The input \code{data} with two new columns added in-place:
\code{{name}_status} (logical) and \code{{name}_date} (IDate).
Always returns a \code{data.table}.
}
\description{
Takes the self-report flag and ICD-10 flag produced by
\code{\link{derive_selfreport}} and \code{\link{derive_icd10}} (or any
pair of logical columns) and merges them into a single logical case status
and earliest date.
}
\details{
\describe{
\item{\code{{name}_status}}{Logical: \code{TRUE} if positive in at
least one source.}
\item{\code{{name}_date}}{Earliest diagnosis/report date across both
sources (\code{IDate}).}
}
}
\examples{
\donttest{
dt <- ops_toy(n = 100)
derive_selfreport(dt, name = "htn", regex = "hypertension",
                  field        = "noncancer",
                  disease_cols = paste0("p20002_i0_a", 0:4),
                  date_cols    = paste0("p20008_i0_a", 0:4),
                  visit_cols   = "p53_i0")
derive_icd10(dt, name = "htn", icd10 = "I10", source = c("hes", "death"))
derive_case(dt, name = "htn")
}
}
