SQL: Default Appointment Types per Patient

About

This report shows active patients, their default sick and well appointment types, and all future scheduled appointments.

A sample image of this SQL report run in the Database Viewer is shown below:

Caveats

  • Only patients with the ACTIVE status are shown here.
  • Patients will show multiple times based on the number of appointments. For example, a patient will show twice if the patient has two future appointments, three times for three future appointments, etc.

Code

To highlight and copy the code below to your clipboard, simply click the Copy button.

select register.patno, fname, lname, birthdat, sick_appt_type, well_appt_type, appt_date as future_appt_date, code1 as future_appt_type
from register
left outer join (select patno, appt_date, code1 from schedule where appt_date >= cast('today' as date) and visit_status is null) s on s.patno = register.patno
where status_pat = 'ACTIVE' and register.patno >99