I have a table with the following schema:

```
CREATE TABLE Codes
(
    diagnosis_code CHAR,
    visit_date     DATE,
    visit_id       INT,
    patient_id     int
);

```

I would like to output the `patient_id`s where the patient is readmitted (so a different `visit_id`) with the same `diagnosis_code` within a certain time (say 15 days). For example, if I have the following entries in the table:

```
diagnosis_code visit_date visit_id    patient_id
-------------- ---------- ----------- -----------
A              2018-01-01 1           1
B              2018-01-01 1           1
A              2018-01-07 2           1
C              2018-01-01 3           2
D              2018-01-01 4           3
D              2018-01-20 5           3
E              2018-01-01 6           4
E              2018-01-01 6           4
A              2018-01-07 7           1

```

The query would return only `patient_id` = `1`, and the rationales are as follows:

1. `1`, because between `visit_id` `1` and `2`, this patient shared diagnosis code `A`.
2. **Not** `2` because this patient was only admitted once.
3. **Not** `3` because this patient, although readmitted for the same diagnosis, was not readmitted within 15 days of their initial visit.
4. **Not** `4` because this patient has a duplicated diagnosis code in the same visit.
5. Notice that `patient_id` = `1` is readmitted for the same diagnosis during `visit_id` = `7`, but he was already counted once before.