GEMINI-Medicine / Rgemini

A custom R package that provides a variety of functions to perform data analyses with GEMINI data
https://gemini-medicine.github.io/Rgemini/
Other
3 stars 0 forks source link

Apply buffer window in `hospitalizations_last_n_days` #138

Open loffleraSMH opened 1 month ago

loffleraSMH commented 1 month ago

New Feature Request

hospitalizations_last_n_days calculates the number of hospitalizations a patient had within the last n days. Similar to readmission, we should apply a buffer window, but (as opposed to readmission), the buffer needs to be applied at the start of the data availability timeline. Specifically, if a genc_id was admitted during the first 30 days of data (e.g., admission_date_time = "2015-04-10 00:00"), by definition, we can't check for any hospitalizations within the previous 30 days, so those genc_ids should be returned as n_hospitalizations = NA.

The issue is if users pre-filter the cohort (e.g., to check for previous hospitalizations with the same diagnosis category, so their cohort would only include encounters that meet a diagnosis inclusion criterion): In that case, the earliest date in the cohort input might not align with the actual earliest date that is available in our DB (i.e., the buffer would be too conservative). I think the best way to handle this might be for users to provide a dbcon input and the function could then check for the earliest available discharge date-time in admdad and then apply the buffer based on that (note: that's basically how this is handled in the readmission function).

Please note that the buffer should be applied by hospital_num (see readmission function) to make sure phase-1 vs. phase-2 sites are handled correctly (and in case there will be differences in data timelines across hospitals in future DB versions).