This function splits data by the date of the clinical event and shows the data recorded before or after the clinical event, and calculates the period between the record date and index date based on a self-defined window gap.

splitDataByDate(
  dxDataFile,
  idColName,
  icdColName,
  dateColName,
  indexDateFile,
  gap = 30
)

Arguments

dxDataFile

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.

idColName

Column name of ID column in dxDataFile. Data type of this argumant should be string without quotation marks.

icdColName

Column name of ICD column in dxDataFile. Data type of this argumant should be string without quotation marks.

dateColName

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.

indexDateFile

A data frame contained index dates for each patient in an observed period. The column names should be 'ID' and 'indexDate'.

gap

Gap length of the window. Default is 30 (data will be seperated every 30 days).

Value

A new data.table based on dxDataFile and classified by indexDateFile for each patient

Details

In most condition, users need to extract data by a specific clinical event (e.g., first diagnosis dates of chronic diseases). Users can define a table of clinical index dates of each patient. The date can be generated by selectCases or first/last admission date by getEligiblePeriod.

See also

Other data integration functions: selectCases, getEligiblePeriod, getConditionEra

Examples

# sample file for example

SampleforCertainPatient <- sampleDxFile[grepl("A0|B0|C0|D0",ID),]

head(SampleforCertainPatient)
#>    ID   ICD       Date Version
#> 1: A0  5855 2013-12-20       9
#> 2: A0 V4511 2012-04-05       9
#> 3: A0  V560 2010-03-28       9
#> 4: A0  5853 2010-10-29       9
#> 5: A0  5856 2009-07-25       9
#> 6: B0  N185 2021-07-16      10

# Defined index date of patient A0,B0,C0 and D0

indexDateTable <- data.frame(ID = c("A0","B0","C0","D0"),
                             indexDate = c("2023-08-12", "2024-02-12",
                                           "2015-12-05", "2017-01-29"),
                             stringsAsFactors = FALSE)
indexDateTable
#>   ID  indexDate
#> 1 A0 2023-08-12
#> 2 B0 2024-02-12
#> 3 C0 2015-12-05
#> 4 D0 2017-01-29
# Split data by index date for each patient

splitedData <- splitDataByDate(SampleforCertainPatient, ID, ICD, Date,
                               indexDateFile = indexDateTable,
                               gap = 30)
splitedData[15:19,]
#>    ID  ICD       Date  indexDate timeTag window
#> 1: B0 N183 2023-08-28 2024-02-12       B      6
#> 2: B0  N19 2023-11-18 2024-02-12       B      3
#> 3: B0  N19 2024-02-12 2024-02-12       A      1
#> 4: C0 C671 2015-12-05 2015-12-05       A      1
#> 5: C0 C048 2016-07-05 2015-12-05       A      8