Created
July 28, 2016 00:09
-
-
Save Zhang/2f03d9529d2938c5b98a6d00c59798cf to your computer and use it in GitHub Desktop.
This file contains 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
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