Validate constraints on diagnosis records, namely that the minimum variables are present, and that all icd_code values can be looked up in an ICD-10 reference table

validate_inpatient_diagnoses(diagnoses_data, diagnoses_lookup)

Arguments

diagnoses_data

a data frame containing clinical diagnoses, with, at minimum, variables patient_id, encounter_id, episode_number, icd_code, diagnosis_position

diagnoses_lookup

a data frame containing an ICD-10 reference look up table with, at minimum, variables icd_description, icd_display, category_code, category_description

Value

A logical value indicating success

Diagnoses mandatory variables

patient_id

a patient identifier with no missing value

encounter_id

a hospital encounter identifier with no missing value

episode_number

a strictly positive integer indicating the number of the episode within an admission. Must not be missing.

icd_code

a code corresponding to the International Classification of Diseases without a "." separator

diagnosis_position

an integer describing the diagnosis position on the discharge summary (1 = primary cause of admission

Diagnoses optional variables

Some record systems track dates when clinical diagnoses were first noted and when they were considered resolved (eg: problem lists). diagnosis_start and diagnosis_end should be used to store this information.

diagnosis_start

a vector of POSIXct timestamps when the clinical problems were first noted or manifested

diagnosis_end

a vector of POSIXct timestamp when the clinical problems were considered resolved

If no data are provided, Ramses functions such as therapy_timeline will use episode start and end dates from the inpatient_episodes table instead.

Diagnoses lookup mandatory variables

icd_code

character diagnosis codes corresponding to the International Classification of Diseases formatted without a "." separator (eg "A0101")

icd_display

laid-out diagnosis codes for display (eg: "A01.01")

icd_description

full text descriptions of the diagnoses

category_code

three-character heading codes (eg "A01")

category_description

full text descriptions of three-character heading codes

Note: import_icd() can produce this lookup data frame from a standard ICD release archive file.

Examples

data_icd <- dplyr::filter(Ramses::inpatient_diagnoses, !is.na(icd_code))
lookup_icd <- dplyr::distinct(data_icd, icd_code)
lookup_icd$icd_display <- lookup_icd$icd_code
lookup_icd$icd_description <- "ICD-10 code label text"
lookup_icd$category_code <- substr(lookup_icd$icd_code, 0, 3)
lookup_icd$category_description <- "ICD-10 category label text"
validate_inpatient_diagnoses(data_icd, lookup_icd)
#> [1] TRUE