Uncategorized

pandas – Calculating Readmission Metrics in Python


I need to compute some Hospital Readmission Variables using Python.

I would need to compute the following metrics:

  • Simple Readmission:
    Compute variables for different periods 3, 7, 14 30 and 45 days after discharge from index admission.
    Rule:Readmission is possible the day after discharge from index admission – at the earliest. This means that if a patient is discharged and admitted on the same day, it is considered a transfer and not a readmission.

I was able to calculate this by using:

df = df.sort_values(['ID','Admission_Date'])

df[['Admission_Date','Discharge_Date']] = df[['Admission_Date','Discharge_Date']].apply(lambda x: pd.to_datetime(x))

df['Readmit3']=df.groupby('ID').apply(lambda x: (((x['Admission_Date'].shift(-1)-x['Discharge_Date']).dt.days.shift(1).le(3))).astype(int)).values
df['Readmit7']=df.groupby('ID').apply(lambda x: (((x['Admission_Date'].shift(-1)-x['Discharge_Date']).dt.days.shift(1).le(7))).astype(int)).values
df['Readmit14']=df.groupby('ID').apply(lambda x: (((x['Admission_Date'].shift(-1)-x['Discharge_Date']).dt.days.shift(1).le(14))).astype(int)).values
df['Readmit30']=df.groupby('ID').apply(lambda x: (((x['Admission_Date'].shift(-1)-x['Discharge_Date']).dt.days.shift(1).le(30))).astype(int)).values
df['Readmit45']=df.groupby('ID').apply(lambda x: (((x['Admission_Date'].shift(-1)-x['Discharge_Date']).dt.days.shift(1).le(45))).astype(int)).values

However, I am facing difficulties with:

  1. Hospital Readmission
    Variable indicating if readmission is to the same hospital or not (yes/no) within 3, 7, 14 30 and 45 days from discharge from the index admission.

  2. Variable indicating if readmission is to a list of specific hospitals. List Hospital: [3,34]. These hospitals are not in the snippet but just as toy example.

  3. Variable indicating if readmission is with the same diagnosis or not, within 3, 7, 14 30 and 45 days from discharge from the index admission (yes/no).

Here is the data snippet CSV snippet https://pastebin.com/LPPX687s

The variables needed for the variables are:

  • ID: Patient ID
  • Date Admission: Date of entrance to hospital
  • Date Discharge: Date of exit from hospital
  • Diagnosis: type of disease the person has
  • Hospital. It is an ID of the hospital.

I do not know what to try, still a beginner.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *