[Experimental]

Calculates medicines from ATC from the National Prescribed Drug Register.

create_medvar(
  atc,
  medvar = ATC,
  medname,
  cohortdata,
  meddata,
  id = "lopnr",
  valsclass = "num",
  fromdate,
  indexdate,
  metatime = "-5mo-14days"
)

Arguments

atc

String of ATC as a regular expression defining the medicine. Default is ATC.

medvar

Name of variable where ATC are found.

medname

Name of resulting variable (with prefix sos_lm_).

cohortdata

Data to add medvar to.

meddata

Data where ATC codes are found.

id

Vector of post identifier (meds for each post). Default is lopnr.

valsclass

optional argument specifying the class of the meds. Allowed values are "num" (numeric: 1, 0), "char" (character: "Yes", "No"), "fac" (factor: "Yes", "No"). Default is "num".

fromdate

Optional date where post with a indexdate prior to this are set to NA (e.g. prior to start of DDR + x months).

indexdate

If fromdate is given, variable were indexdate is found.

metatime

For what time span are the meds selected in data? Printed in metalm. Default text is "-5mo-14days".

Value

cohortdata with column containing medicine. Also dataset metalm that writes directly to global enviroment with information on constructed variables.

Examples


if (FALSE) {
lmtmp <- left_join(
  rsdata %>%
    select(LopNr, shf_indexdtm),
  lmsel,
  by = "LopNr"
) %>%
  mutate(diff = as.numeric(EDATUM - shf_indexdtm)) %>%
  filter(diff >= -30.5 * 5, diff <= 14) %>%
  select(LopNr, shf_indexdtm, EDATUM, ATC)

rsdata <- create_medvar(atc = "^C07A", medname = "bbl", cohortdata = rsdata, meddata = lmtmp, id = c("LopNr", "shf_indexdtm"))
}