calc_hosp_days: Calculate Hospitalization Days Overlapping with Drug...

View source: R/calc_hosp_days.R

calc_hosp_daysR Documentation

Calculate Hospitalization Days Overlapping with Drug Purchases

Description

Calculates the total number of hospitalization days ('hosp_days_all') and the number of hospitalization days that started during the drug exposure ('hosp_days_exp') for each purchase period. The calculation is based on overlapping time windows between purchase events and hospitalization periods, taking into account the discharge date (which is not included in the hospital stay).

Usage

calc_hosp_days(
  pre_id,
  pre_atc,
  curr_purc_start,
  exp_end,
  next_start,
  hosp_id,
  hosp_in,
  hosp_out
)

Arguments

pre_id

Integer or character vector. Person identifier in drug purchases data.

pre_atc

Character vector. ATC codes for each purchase.

curr_purc_start

Integer or Date vector. Start date of the drug purchase period.

exp_end

Integer or Date vector. End date of the drug exposure period.

next_start

Integer or Date vector. Start date of the next purchase period (may be NA for the last purchase).

hosp_id

Integer or character vector. IDs for each hospitalization (should match 'pre_id').

hosp_in

Integer or Date vector. Admission date for each hospitalization.

hosp_out

Integer or Date vector. Discharge date for each hospitalization.

Details

The function merges drug purchase and hospitalization data by person ID, then calculates the overlap between purchase periods and hospitalizations. Hospital discharge date is not included in the total stay. Hospitalization days are summed for each purchase period.

Value

A data.table with two columns:

hosp_days_all

Total number of hospitalization days between purchase and next purchase (not including discharge date).

hosp_days_exp

Number of hospitalization days that started during drug exposure.


piavat/PRE2DUP-R documentation built on June 11, 2025, 11:42 a.m.