Some readmissions are part of the plan: a patient on chemotherapy comes back every three weeks for the next cycle. Readmission measures set planned readmissions aside, so a scheduled treatment does not read as a stay that went wrong. In the data, planned = true marks them.
The rule applies to the readmission, not the index stay. Read the next stay's flag with LEAD and test it:
LEAD(planned) OVER (PARTITION BY patient_id
ORDER BY admit_date) AS next_planned
...
COUNT(*) FILTER (WHERE next_admit_date - discharge_date <= 30
AND NOT next_planned) AS readmissions
A planned chemotherapy stay is still an index stay: if the patient comes back unplanned ten days later with an infection, that is a readmission. As in the CMS measures, only the first admission after the discharge is looked at.
The pitfalls: dropping planned stays from the index stays (the real readmissions after planned care disappear), filtering planned stays out before LEAD (the next admission changes), and not excluding planned readmissions at all.
Readmissions with planned ones set aside.