def keep_last_labtest_instance(df):
    """
    select last instance of every type of test for a patient
    """
    df = df.sort_values('charttime', axis=0)
    df = df.drop_duplicates(subset=['hadm_id', 'itemid'], keep='last', ignore_index=True)
    return df