There are two versions of this SQL: Firebird and MySQL. The MySQL version only applies to clients who are have migrated to MySQL.. All other Practices should continue to use the Firebird version of this code. Click to expand and copy the code you need. If you are unsure which code to use, please check with your Practice Administrator. |
About
This SQL shows all contacts attached to a patient's chart (contact 1, 2, 3, 4, 5, etc), the contact Name, Role, Authority, which contact (DENORM_NO), and Home and Work emails.
Caveats
Contacts who are enumerated as #1 and #2 will be listed irrespective of their relationship to the patient. These may or may not be suitable to contact for your purposes! For example, a patient who is over 18 may have an emergency contact but it would not be appropriate to send information to the emergency contact. A child might have contact #1 = mother and contact #2 = grandfather for emergency purposes but only mother should be contacted about this particular child’s medical issues.
SQL Code: MySQL
To highlight and copy the code below to your clipboard, simply click the Copy button.
select patno, (first_name || ' ' || last_name) as contact_name, contact_role, contact_authority, denorm_no, home_email, work_email from register inner join register_contact on register.patno = register_contact.patno inner join contact on contact.id = register_contact.contact_id where patno is not null and patno >= 99 and lname not in ( 'TESTPATIENT','TEST-PATIENT') and status_pat = 'ACTIVE' and contact_role not in ('PRIOR_PHONE', 'PRIOR_ADDR') order by patno