R/fun_emr.R
, R/getEligiblePeriod.R
getEligiblePeriod.Rd
getEligiblePeriod
is a function to find the first and last clinical event for a given patient. The result can be index date in the folloing process such as splitDataByDate
.
getEligiblePeriod(dxDataFile, idColName, dateColName)
A data frame object of clinical diagnostic data with at least 3 columns: ID, ICD, and Date. As for date column, the data format should be YYYY/MM/DD or YYYY-MM-DD.
Column name of ID column in dxDataFile. Data type of this argumant should be string without quotation marks.
Column name of date column in dxDataFile, and the type of date column should be a date format in R or a string format with date information in YYYY/MM/DD or YYYY-MM-DD. Data type of this argumant should be string without quotation marks.
A new data.table
based on dxDataFile
with the earliest and latest admission date for each patient.
The function queries the earliest and latest admission date for each patient.
Other data integration functions: selectCases
, splitDataByDate
, getConditionEra
# sample file for example
head(sampleDxFile)
#> ID ICD Date Version
#> 1: A2 Z992 2020-05-22 10
#> 2: A5 Z992 2020-01-24 10
#> 3: A8 Z992 2015-10-27 10
#> 4: A13 Z992 2020-04-26 10
#> 5: A13 Z992 2025-02-02 10
#> 6: A15 Z992 2023-05-12 10
# Earliest and latest admission date for each patient
record <- getEligiblePeriod(sampleDxFile, ID, Date)
head(record)
#> ID firstRecordDate endRecordDate
#> 1: D6 2005-10-09 2025-01-05
#> 2: A12 2006-01-12 2022-06-12
#> 3: D1 2006-02-12 2024-04-04
#> 4: A13 2006-04-29 2025-02-02
#> 5: A9 2006-06-30 2023-12-10
#> 6: D2 2006-09-01 2025-08-11