I am working with medical claims data to create inpatient episodes. There isn't an 'episode identifier' column within the dataset. My intention is to create a unique identifier for each episode to tie the claims to, which I can handle after I can properly identify the correct admissions and discharge dates for each episode. To keep it simple, here is a table of fake data that reflects a situation that I'm struggling with:
| Patient ID | Admitted Date | Discharge Date |
|---|---|---|
| 810 | 2020-12-15 | 2020-12-16 |
| 810 | 2021-06-17 | 2021-06-19 |
| 810 | 2021-06-19 | 2021-06-27 |
| 810 | 2021-06-27 | 2021-07-03 |
With this example dataframe, the first row shows a simple inpatient episode. Lines two through four have admission dates and discharge dates that are tied together. This is due to patients switching hospital divisions, initiating a new REV code.
I had originally used an ifelse statement that inherently failed. I used that without thinking of situations like this, where there are more two lines needed to be grouped as an episode.
Does anyone have any recommendations for packages/resources to use in order to turn lines 2-4 into a single row saying
| Patient ID | Admitted Date | Discharge Date |
|---|---|---|
| 810 | 2020-12-15 | 2020-12-16 |
| 810 | 2021-06-17 | 2021-07-03 |
Thanks! Let me know if any further explanation is needed.