Skip to content

Instantly share code, notes, and snippets.

@Zhang
Created August 12, 2016 20:54
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/3be3ee5f2a76e61f60b3797433bcaff7 to your computer and use it in GitHub Desktop.
Save Zhang/3be3ee5f2a76e61f60b3797433bcaff7 to your computer and use it in GitHub Desktop.
def patient_payers(type, id, range, filters)
Map<Integer, Integer> payerTable = new HashMap<>();
List<Patient> patientsInDateRange = patients(type, id, range, filters);
// Iterate on the patients
for (Patient patient : patientsInDataRange) {
// Iterate on the payers
for (Payer payer : patient.getPayers()) {
if (payer.isActive()) {
if (payerTable.containsKey(payer.Id)) {
payerTable.put(payer, 1);
} else {
Integer existingCount = payerTable.get(existing);
payerTable.put(payer, existingCount == null ? 1 : existingCount++);
}
}
}
}
return payerTable;
}
end
def isPayerActive(payer, range) {
PayerHistory[] histories = payer.active_history;
boolean isActive = false;
for (PayerHistory history : histories) {
PayerHistory trueBeforeRange = null;
if (history.beforeTime(range.begin)) {
if (history.value) {
trueBeforeRange = history;
} else {
}
} else {
if (trueBeforeRange != null) {
// We assume this is a false (we can assert it) so we have a true -> false range that includes the tranisiotn period.
return true;
}
// If before end of range and and true => return true
if (history.beforeTime(range.end) && history value) {
return true;
}
if (history.afterOrEqualTime(range.end)) {
return false;
}
}
}
return trueBeforeRange == null;
}
return isActive;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment