def test_consumption_totals(self): assert get_consumption_totals([NEW], [{ NEW: 10, EXISTING: 12 }, { NEW: None, EXISTING: 12 }]) == 10 assert get_consumption_totals([NEW], [{ NEW: None, EXISTING: 12 }, { NEW: 10, EXISTING: 12 }]) == 10 assert get_consumption_totals([EXISTING], [{ NEW: 10, EXISTING: 12 }, { NEW: None, EXISTING: 12 }]) == 24 assert get_consumption_totals([EXISTING, NEW], [{ NEW: 10, EXISTING: 12 }, { NEW: None, EXISTING: 12 }]) == 34
def for_each_facility(self, data, combination, previous_cycle_data=None): df1_records = get_consumption_records(data, combination[CONSUMPTION_QUERY]) df2_records = get_patient_records(data, combination[PATIENT_QUERY], combination[IS_ADULT]) df2_sum = get_patient_total(df2_records) df1_sum = get_consumption_totals(combination[FIELDS], df1_records) all_df1_blank = has_all_blanks(df1_records, combination[FIELDS]) all_df2_blank = has_all_blanks(df2_records, [NEW, EXISTING]) both_are_zero = (df1_sum == 0 and df2_sum == 0) if len(df1_records) == 0 and len(df2_records) == 0: return NOT_REPORTING adjusted_df1_sum = df1_sum / combination[RATIO] no_blanks = not all_df1_blank and not all_df2_blank divisible = df2_sum != 0 if no_blanks and (both_are_zero or (divisible and 0.7 < float(adjusted_df1_sum) / float(df2_sum) < 1.429)): return YES else: return NO
def test_consumption_totals(self): assert get_consumption_totals([NEW], [{NEW: 10, EXISTING: 12}, {NEW: None, EXISTING: 12}]) == 10 assert get_consumption_totals([NEW], [{NEW: None, EXISTING: 12}, {NEW: 10, EXISTING: 12}]) == 10 assert get_consumption_totals([EXISTING], [{NEW: 10, EXISTING: 12}, {NEW: None, EXISTING: 12}]) == 24 assert get_consumption_totals([EXISTING, NEW], [{NEW: 10, EXISTING: 12}, {NEW: None, EXISTING: 12}]) == 34