The method you want to use is inverse probability weighting for marginal structural models. See Robins, Hernan, & Brumback (2000) or Thoemmes & Ong (2016) for an introduction to the method.
Basically, at each time point, units can be assigned to any treatment. You want to mimic a sequentially randomized control trial (i.e., where each unit is randomly assigned to a treatment at each time point). With a sequential RCT, you could find the causal effect of any one pattern of drug assignments (e.g., drug at all time points vs. no drug at all time points, or drug at all time points. vs. drug at only the first few time points, etc.). You can also build a model that relates outcome to the number of time points where the drug was received, or the to the timing of drug receipt, etc.
In your situation, you might not have a sequential RCT; there may be confounding at each time point. What you need to do is generate weights that, when applied to your sample, mimic a sequential RCT, in that sense that at each time point, all covariates are balanced between the control and treated units. Then, a weighted analysis will give you an unbiased estimate of the causal effect of interest (assuming you have balanced all the relevant covariates at each time point).
The way you estimate the weights is the following: at each time point, model the probability of being treated based on all previously measured covariates (including previous treatments and intermediate outcomes). At time 1, your model will include baseline covariates. At time 2, your model will include baseline covariates, the time 1 treatment status, and any variables that may have changed values between time 1 and time 2 (e.g., a measure of disease progression after time 1 but before the next treatment was given). From each of these models, generate predicted probabilities (i.e., propensity scores), and the generate IPW weights by taking the inverse of the propensity score for treated units and the inverse of 1 minus the propensity score for control units. Then, for each unit, multiply all of their weights together. These are the weights that will balance your groups at each time point. Finally, do a weighted regression of your outcome on all the treatment variables using these weights. You can then interpret the parameters of the regression as causal (assuming assumptions are met).