fixed sql for painMedication