Skip to content

Instantly share code, notes, and snippets.

@Zhang
Created July 28, 2016 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zhang/2f03d9529d2938c5b98a6d00c59798cf to your computer and use it in GitHub Desktop.
Save Zhang/2f03d9529d2938c5b98a6d00c59798cf to your computer and use it in GitHub Desktop.
def patient_payers(type, id, range, filters)
# get hospital's patients at the hospital during range
# by looking at admissions table
active_patients = patients(type, id, range, filters)
# using list of patient_ids, get list of patient-payer relationships
payers = set([])
count = Counter()
for patient in active_patients:
# using list of patient-payer relationships, calculate count of payers active during range
for payer_entry in patient.patient_payers:
active = false
for status_update in payer_entry.active_history:
if status_update.value == True and status_update.updated_at >= range.start and status_update.updated_at <= range.end:
active = True
break
#check for first update after end of range
if status_update.updated_at > range.end:
break
elif status_update.value == True:
active = True
elif status_update.value == False:
if status_update.updated_at > range.start and status_update.updated_at <= range.end:
active = True
break
else:
active = False
if active:
count[payer_entry.id] += 1
return count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment