Created
August 12, 2016 22:22
-
-
Save Zhang/2b162fad67812dc3d30e677eaa808f5a 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
def is_payer_active_in_range(payer, range) | |
active_history = payer.active_history | |
# list of value and updated_at | |
prev_active = false | |
prev_time = 0 | |
# cases: updated during, updated only before, updated only after, updated before and after but not during | |
for update in active_history: | |
current_active = update.value | |
current_time = update.updated_at | |
if (current_active or prev_active) and range.start <= current_time and range.end > current_time: | |
return true | |
if prev_time < range.start and current_time > range.end: | |
return prev_active | |
prev_active = current_active | |
prev_time = current_time | |
return prev_active | |
end | |
# type: e.g. hospital, dept | |
# id: unique id for type | |
# range: date range | |
# filters: whatever | |
def patient_payers(type, id, range, filters) | |
patients = patients(type, id, range, filters) | |
payers_count = {} | |
for patient in patients: | |
patient_payers = patient.patient_payers() | |
for payer in patient_payers: | |
if is_payer_active_in_range(payer, range): | |
if payer not in payers_count: | |
payers_count[payer.name()] = 0 | |
payers_count[payer.name()] += 1 | |
return payers_count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment