The first part of the query before not in runs and gives me a list of
not in
I believe you need to specify the column that the not in is looking at. So according to your script I think you would want and Patient.patientid not in
and Patient.patientid not in