--look up flag values on your EPIC site and adapt
select *
From ZC_BPA_TRIGGER_FYI;
/* UCLA values to exclude are
1018 Control
1053 Restricted Data -Permanent
8 Restricted Data
9 Test Patient
6 Tracked
*/
--This script selected patients that have to excluded
SELECT DISTINCT p.pat_id
FROM patient p
LEFT JOIN patient_fyi_flags flags on p.pat_id = flags.patient_id
LEFT JOIN patient_3 on p.pat_id = patient_3.pat_id
WHERE
patient_3.is_test_pat_yn = 'Y'
OR flags.PAT_FLAG_TYPE_C in (6,8,9,1018,1053);
Restricted patients are not to be contacted