Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
breakoutModefull-width
/*Pulls current user status with program name and user_program_id. Latest upload time included. 
Validate by searching by phone number in Impact in the program the user is enrolled in 
Only as current as the day your last export came to you...
Phone number returned for searching user in Impact: https://help.validic.com/space/VCS/3310977025/Program+view+-+Searching+for+users*/
Select h.patient_id,p.validic_id,p.phone_number,pi.name as program_name,p.latest_upload_time,h.status,h.user_program_id
From patient_program_history as h
/*To get latest upload time */
Inner Join patient_info as p on p.user_program_id = h.user_program_id
/*To get program name */
Inner Join program_info as pi on pi.program_id = h.program_id
/*To isolate last status update timestamp for users_program_id*/
Inner Join 
  (Select user_program_id,max(updated_at) as updated_at 			From patient_program_history as h 			Group by user_program_id
			  ) as max on (max.user_program_id = h.user_program_id AND max.updated_at = h.updated_at)
/*To exclude user_program_id that isn't active or on the way to active*/
Where h.user_program_id not in (Select user_program_id 								From patient_program_history as h 								Where h.status in ('Unenrolled','Archived','Abandoned') 								Group by user_program_id)
/*edit below with patient_id or comment out to pull current enrollment on all users*/
and h.patient_id = '<Patient_Id>'
/*edit below with a program name from your org or comment it out to pull all programs*/
and pi.name = '<Program_Name>'
Group by h.patient_id,p.validic_id,p.latest_upload_time,h.status,h.user_program_id,pi.name,p.phone_number;

...