SELECT patient.Patient_ID, patient.Status, patient.Last_Name_M0040 AS PatientLast, patient.First_Name_M0040 AS PatientFirst,
Assessment_Forms.Assessment_Forms_ID, Assessment_Forms.Form_Type, Assessment_Forms.Date_Sent, patient.Primary_ReferringPhys_ID_M0072,
Assessment_Forms.Cert_Start_Item_3a, Assessment_Forms.Cert_End_Item_3b, Assessment_Forms.Record_Mod_Date,
Assessment_Forms.Cert_Start_Item_3a, Physician.Physician_ID,
Employee.Last_Name as LastName, Employee.First_Name as FirstName
FROM #Request.prefix_db_agency#.patient, #Request.prefix_db_agency#.Assessment_Forms, #Request.prefix_db_lookup#.Physician,#Request.prefix_db_lookup#.Employee
WHERE patient.Patient_ID = Assessment_Forms.Patient_ID
AND patient.Agency_ID = #session.AgencyID#
AND Physician.Physician_ID = patient.Primary_ReferringPhys_ID_M0072
AND patient.Status != 'deleted'
AND Employee.Employee_ID = Physician.Employee_ID
AND Assessment_Forms.Record_Created_By = Employee.Employee_ID
AND Employee.EmployeeType = 'Physician'
ORDER BY patient.Last_Name_M0040