Skip to content

Instantly share code, notes, and snippets.

@Zhang
Created July 27, 2016 00:27
Show Gist options
  • Save Zhang/d7290f1145bbbfa1df0b64a8e56eaf5c to your computer and use it in GitHub Desktop.
Save Zhang/d7290f1145bbbfa1df0b64a8e56eaf5c to your computer and use it in GitHub Desktop.
payers
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