Created
July 27, 2016 00:27
-
-
Save Zhang/d7290f1145bbbfa1df0b64a8e56eaf5c to your computer and use it in GitHub Desktop.
payers
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) | |
let patients = patients(type, id, range, filters) | |
var activePayers = [payer: count] | |
for patient in patients { | |
let patientPayers = patient.patient_payers | |
for payer in patientPayers { | |
if payerIsActiveInRange(payer, range) { | |
if activePayers[payer] == nil { | |
activePayers[payer] = 1 | |
} else { | |
activePayers[payer] += 1 | |
} | |
} | |
} | |
} | |
} | |
return activePayers | |
end | |
def payerIsActiveInRange(payer, range) | |
let history = payer.active_history | |
var previous = false | |
for update in history { | |
if update.updated_at > range.start && previous == true { | |
return true | |
} | |
if update.updated_at > range.start && update.updated_at < range.end && update.value == true { | |
return true | |
} | |
if update.updated_at > range.end { | |
return false | |
} | |
previous = update.value | |
} | |
return previous | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment