count the number of medicines that patient 31696 has been prescribed on their last hospital encounter.
select count(*) from prescriptions where prescriptions.hadm_id in ( select admissions.hadm_id from admissions where admissions.subject_id = 31696 and admissions.dischtime is not null order by admissions.admittime desc limit 1 )