instruction: when was the last time that patient 006-161415 had a maximum heartrate on the first icu visit.
response: SELECT vitalperiodic.observationtime FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-161415') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.heartrate DESC, vitalperiodic.observationtime DESC LIMIT 1