ddediu / AdhereR

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

Encapsulate settings for default argument values and overrides based on CMA #63

Open Masswear opened 5 years ago

Masswear commented 5 years ago

For CMA_per_episode and CMA_sliding_windows (and most likely CMA_polypharmacy), the code for CMA-specific arguments is duplicated. This makes maintenance harder and can be a risk if new CMAs with specific default arguments are added.

A generic function that returns a list of arguments based on CMA , e.g.

# function that generates CMA-specific arguments
default.arguments <- function(CMA.to.apply){
if( CMA.to.apply %in% c("CMA1", "CMA2", "CMA3", "CMA4") )
  { default.arguments <- list(carry.only.for.same.medication = FALSE, ...) } 
...
return(default.arguments)
}

# generate CMA-specific arguments
params <- default.arguments(CMA.to.apply)

# call CMA.to.apply with the CMA-specific arguments
CMA <- do.call(CMA.to.apply, c(list(data = DATA), params))
ddediu commented 5 years ago

good idea: will do