def for_each_facility(self, data, combination, previous_cycle_data=None): df1_records = get_consumption_records(data, combination[CONSUMPTION_QUERY]) values = values_for_records(self.fields, df1_records) all_cells_not_negative = pydash.every(values, lambda x: x is None or x >= 0) if len(df1_records) == 0: return NOT_REPORTING return YES if all_cells_not_negative else NO
def test_consumption_records(self): data = {} data[C_RECORDS] = [{FORMULATION: "A", "openingBalance": 3}, {FORMULATION: "B", "openingBalance": 3}, {FORMULATION: "A", "openingBalance": 12}] check = ConsumptionAndPatientsQualityCheck() records = get_consumption_records(data, "A") assert records == [{FORMULATION: "A", "openingBalance": 3}, {FORMULATION: "A", "openingBalance": 12}]
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_records(self): data = {} data[C_RECORDS] = [{ FORMULATION: "A", "openingBalance": 3 }, { FORMULATION: "B", "openingBalance": 3 }, { FORMULATION: "A", "openingBalance": 12 }] check = ConsumptionAndPatientsQualityCheck() records = get_consumption_records(data, "A") assert records == [{ FORMULATION: "A", "openingBalance": 3 }, { FORMULATION: "A", "openingBalance": 12 }]