Let’s draw it out:
Index Event: |--------------------|
Target Event: |-------------------------|
Let’s say your index is for Medicine A, and your target is Medicine B. Any overlap would be:
index.starts between all days before and 0 days before target ends
and index ends between 0 days after and all days after target starts
But since you want 30d overlap, that means the index starts at least 30d before the target ends:
index.starts between all days before and 30 days before target ends
and index ends between 0 days after and all days after target starts
To add the additional criteria that the disease C occurred after medication B started:
a drug era of Medicine B
having all of the following criteria:
At least one occurrence of Condition C starting between 1 day after and all days after index start date
Note: index start date is referring to Medicine B, because this is nested criteria)
Putting it all together, you can make your Cohort Entry Events as:
A drug era of Medicine A
having all of the following criteria:
at least 1 occurrence of a drug era of Medicine B
having all of the following criteria
at least 1 occurrence of a condition occurrence of Condition C
event starts between 1 day after and all days after index start date (index = Medicine B)
index.starts between all days before and 30 days before target ends
and index ends between 0 days after and all days after target starts (index = Medicine A)
Hope that helps.
Edit: I think you wanted your index date to be the date of the switch, so, you’ll have to rework the logic above so that the Target medication is the index event and the index event is the target (such that when the new drug is found in an overlap, that new drug start date is when they switched. Thie form I gave you will identify the start of the era that a switch happened, but I think you want the actual drug that was switched to.