def aggregate_scores(user, test, cycles, formulation, keys, count_values, filters): scores_filter = {} if user: access_level = user.access_level access_area = user.access_area if access_level and access_area: scores_filter[access_level.lower()] = access_area if user.is_superuser: scores_filter = filters score_objects = Score.objects.filter(**scores_filter).values(test, "cycle") grouped_objects = pydash.group_by(score_objects, lambda x: x["cycle"]) def get_count_key(value): value_as_dict = json.loads(value[test]) return value_as_dict.get(formulation, None) if type(value_as_dict) is dict else None def agg(value): values = grouped_objects.get(value, []) result = {'cycle': value} total = len(values) yes_count_value = count_values[YES] no_count_value = count_values[NO] not_reporting_count_value = count_values[NOT_REPORTING] if total > 0: counts = pydash.count_by(values, get_count_key) yes_count = counts.get(yes_count_value, 0) no_count = counts.get(no_count_value, 0) not_reporting_count = counts.get(not_reporting_count_value, 0) result[keys[YES]] = (yes_count * 100 / float(total)) result[keys[NO]] = (no_count * 100 / float(total)) result[keys[NOT_REPORTING]] = (not_reporting_count * 100 / float(total)) else: result[keys[YES]] = 0 result[keys[NO]] = 0 result[keys[NOT_REPORTING]] = 0 return result return pydash.collect(cycles, agg)
def get_patient_records(data, combinations, is_adult=True): lower_case_combinations = pydash.collect(combinations, lambda x: x.lower()) records = data.get(A_RECORDS, []) if is_adult else data.get(P_RECORDS, []) return pydash.chain(records).select(lambda x: x[FORMULATION].strip().lower( ) in lower_case_combinations).value()
def persist_multiple_order_records(report): facilities_with_multiple_orders = pydash.reject(report.locs, lambda f: facility_has_single_order(f)) all = pydash.collect(facilities_with_multiple_orders, build_mof(report)) MultipleOrderFacility.objects.filter(cycle=report.cycle).delete() MultipleOrderFacility.objects.bulk_create(all)
def get_patient_records(data, combinations, is_adult=True): lower_case_combinations = pydash.collect(combinations, lambda x: x.lower()) records = data.get(A_RECORDS, []) if is_adult else data.get(P_RECORDS, []) return pydash.chain(records).select( lambda x: x[FORMULATION].strip().lower() in lower_case_combinations ).value()