Last active
May 31, 2016 21:43
-
-
Save michaelminter/cc2ba286444895ade1c099ce493396a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import athenahealthapi | |
import datetime | |
import csv | |
# Set up | |
key = 'FILTERED' | |
secret = 'FILTERED' | |
version = 'FILTERED' | |
practice_id = 123 | |
department_id = 1 | |
appointment_type_id = 1 | |
# Don't touch anything below this line | |
def format_date(date, format = '%m/%d/%Y'): | |
return date.strftime(format) | |
patients = [] | |
processed = 0 | |
today = datetime.date.today() | |
tomorrow = datetime.date.today() + datetime.timedelta(days = 1) | |
nextyear = today.replace(year = today.year + 1) | |
filename = 'mobile_list_%s.csv' % format_date(today, '%Y%m%d') | |
api = athenahealthapi.APIConnection(version, key, secret, practice_id) | |
# If you want to change which practice you're working with after initialization, this is how. | |
# api.practiceid = 000000 | |
# Get appointments | |
appointments = api.GET('/appointments/booked', { | |
'departmentid': department_id, | |
'startdate': format_date(today), | |
'enddate': format_date(nextyear), | |
'scheduledstartdate': format_date(today), | |
'scheduledenddate': format_date(tomorrow) | |
}) | |
print 'Found %s appointments between %s and %s...' % (appointments['totalcount'], today, nextyear) | |
# Get patients | |
for appointment in appointments['appointments']: | |
patient = api.GET('/patients/'+appointment['patientid'])[0] | |
if 'email' in patient: | |
if 'mobilephone' in patient or 'homephone' in patient: | |
processed = processed + 1 | |
patients.append([appointment['appointmentid'], appointment['scheduleddatetime'], patient['mobilephone'] if patient.has_key('mobilephone') else patient['homephone']]) | |
print 'Processing %s patients with available phone number...' % processed | |
# Will overwrite an existing file of the same name | |
with open(filename, 'wb') as csvfile: | |
spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) | |
for p in patients: | |
spamwriter.writerow(p) | |
print ' * %s' % p | |
print 'Saved %s.' % filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment