ddediu / AdhereR

Computation of adherence to medications from Electronic Healthcare Data in R
26 stars 6 forks source link

Add treatment episode start and end dates as arguments to CMA_per_episode #53

Closed Masswear closed 5 years ago

Masswear commented 5 years ago

As an alternative to calculating CMA_per_episode based on gap lenght, give option to provide episode start and end dates as arguments, e.g.:

CMA_per_episode(CMA="CMA1",
                data=med.events,
                maximum.permissible.gap = NULL,
                episode.start.date = "start_episode",  #Name of variable containing episode start date as string or date object
                episode.end.date = "end_episode"; #Name of variable containing episode end date as string or date object
                date.format="%m/%d/%Y")
ddediu commented 5 years ago

I guess that means that I have to call your code? If so, could you pls give me skeleton example that I can expand on?

Masswear commented 5 years ago

No, it means that the user should be able to override the internal calculation of episodes with compute_internal_gaps by providing episode start- and end dates per patient per medication class. Either as separate variable in the dataset or as separate dataset.

ddediu commented 5 years ago

I've been looking at this: currently, the episodes do not explicitly care about medication class (i.e., only a change in medication class might trigger a new episode), so what I propose is:

In CMA_per_episode() if you pass me an extra argument treat.episodes of type data.frame and structure:

(i.e., in the same format as compute.treatment.episodes() would have returned), I can use it internally instead of calling compute.treatment.episodes().

Would this work for you?

Masswear commented 5 years ago

In principle yes, but the data.frame structure would ideally look like this:

This would reflect the situation in clinical practice, where medications are prescribed for specific durations, but durations don't need to be the same for each medication.

end.episode.gap.days is not known before CMA calculation and episode.duration is redundant when episode.start and episode.end are given.

Masswear commented 5 years ago

Users can now specify the parameter treat.epi for CMA_per_episode, in the form of a data.frame containing the treatment episodes. It must contain the patient ID (as given in ID.colname), the episode unique ID (increasing sequentially, episode.ID), the episode start date (episode.start), the episode duration in days (episode.duration), and the episode end date (episode.end).

If treat.epi is specified, it overrides the default computation of treatment episodes by gap days. The medication.class column is not required because CMA_per_episode should only be used for single treatments. This option would make sense for a polypharmacy version of the function.