コード例 #1
0
def get_prevalence_of_stunting_sector_data(domain, config, loc_level, location_id, show_test=False,
                                           icds_feature_flag=False):
    group_by = ['%s_name' % loc_level]

    config['month'] = datetime(*config['month'])
    data = AggChildHealthMonthly.objects.filter(
        **config
    ).values(
        *group_by
    ).annotate(
        moderate=Sum(stunting_moderate_column(icds_feature_flag)),
        severe=Sum(stunting_severe_column(icds_feature_flag)),
        normal=Sum(stunting_normal_column(icds_feature_flag)),
        total=Sum('height_eligible'),
        total_measured=Sum(hfa_recorded_in_month_column(icds_feature_flag)),
    ).order_by('%s_name' % loc_level)

    if not show_test:
        data = apply_exclude(domain, data)
    if 'age_tranche' not in config:
        data = data.exclude(age_tranche=72)

    chart_data = {
        'blue': [],
    }

    tooltips_data = defaultdict(lambda: {
        'severe': 0,
        'moderate': 0,
        'total': 0,
        'normal': 0,
        'total_measured': 0
    })

    loc_children = get_child_locations(domain, location_id, show_test)
    result_set = set()

    for row in data:
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        result_set.add(name)

        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        row_values = {
            'severe': severe,
            'moderate': moderate,
            'total': total,
            'normal': normal,
            'total_measured': total_measured,
        }

        for prop, value in six.iteritems(row_values):
            tooltips_data[name][prop] += value

        value = (moderate + severe) / float(total_measured or 1)
        chart_data['blue'].append([
            name, value
        ])

    for sql_location in loc_children:
        if sql_location.name not in result_set:
            chart_data['blue'].append([sql_location.name, 0])

    chart_data['blue'] = sorted(chart_data['blue'])

    __, __, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag)
    )

    return {
        "tooltips_data": dict(tooltips_data),
        "info": _((
            "Of the children enrolled for Anganwadi services, whose height was measured, the percentage "
            "of children between {} who were moderately/severely stunted in the current month. "
            "<br/><br/>"
            "Stunting is a sign of chronic undernutrition and has long lasting harmful consequences on "
            "the growth of a child".format(chosen_filters)
        )),
        "chart_data": [
            {
                "values": chart_data['blue'],
                "key": "",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": MapColors.BLUE
            },
        ]
    }
コード例 #2
0
def get_prevalence_of_stunting_data_map(domain,
                                        config,
                                        loc_level,
                                        show_test=False,
                                        icds_feature_flag=False):
    def get_data_for(filters):
        filters['month'] = datetime(*filters['month'])
        queryset = AggChildHealthMonthly.objects.filter(**filters).values(
            '%s_name' % loc_level,
            '%s_map_location_name' % loc_level).annotate(
                moderate=Sum(stunting_moderate_column(icds_feature_flag)),
                severe=Sum(stunting_severe_column(icds_feature_flag)),
                normal=Sum(stunting_normal_column(icds_feature_flag)),
                total=Sum('height_eligible'),
                total_measured=Sum('height_measured_in_month'),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            if icds_feature_flag:
                queryset = queryset.exclude(age_tranche=72)
            else:
                queryset = queryset.exclude(age_tranche__in=[0, 6, 72])
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total': 0,
            'total_measured': 0,
            'original_name': []
        })

    moderate_total = 0
    severe_total = 0
    normal_total = 0
    all_total = 0
    measured_total = 0

    values_to_calculate_average = []
    for row in get_data_for(config):
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        numerator = moderate + severe
        values_to_calculate_average.append(numerator * 100 /
                                           (total_measured or 1))

        severe_total += severe
        moderate_total += moderate
        normal_total += normal
        all_total += total
        measured_total += total_measured

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 25:
            data_for_location.update({'fillKey': '0%-25%'})
        elif 25 <= value < 38:
            data_for_location.update({'fillKey': '25%-38%'})
        elif value >= 38:
            data_for_location.update({'fillKey': '38%-100%'})

    fills = OrderedDict()
    fills.update({'0%-25%': MapColors.PINK})
    fills.update({'25%-38%': MapColors.ORANGE})
    fills.update({'38%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Stunted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % ((sum(values_to_calculate_average)) /
                      float(len(values_to_calculate_average) or 1)),
            "info":
            _(("Percentage of children ({}) enrolled for Anganwadi Services with height-for-age below "
               "-2Z standard deviations of the WHO Child Growth Standards median."
               "<br/><br/>"
               "Stunting is a sign of chronic undernutrition and has long lasting harmful "
               "consequences on the growth of a child".format(age_label))),
            "extended_info": [{
                'indicator':
                'Total Children{} eligible to have height measured:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(all_total)
            }, {
                'indicator':
                'Total Children{} with height measured in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(measured_total)
            }, {
                'indicator':
                'Number of Children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(all_total - measured_total)
            }, {
                'indicator':
                '% children{} with severely stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (severe_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with moderate stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (moderate_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with normal stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (normal_total * 100 / float(measured_total or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
コード例 #3
0
def get_prevalence_of_stunting_sector_data(domain,
                                           config,
                                           loc_level,
                                           location_id,
                                           show_test=False,
                                           icds_feature_flag=False):
    group_by = ['%s_name' % loc_level]

    config['month'] = datetime(*config['month'])
    data = AggChildHealthMonthly.objects.filter(**config).values(
        *group_by).annotate(
            moderate=Sum(stunting_moderate_column(icds_feature_flag)),
            severe=Sum(stunting_severe_column(icds_feature_flag)),
            normal=Sum(stunting_normal_column(icds_feature_flag)),
            total=Sum('height_eligible'),
            total_measured=Sum(
                hfa_recorded_in_month_column(icds_feature_flag)),
        ).order_by('%s_name' % loc_level)

    if not show_test:
        data = apply_exclude(domain, data)
    if 'age_tranche' not in config:
        data = data.filter(age_tranche__lt=72)

    chart_data = {
        'blue': [],
    }

    tooltips_data = defaultdict(lambda: {
        'severe': 0,
        'moderate': 0,
        'total': 0,
        'normal': 0,
        'total_measured': 0
    })
    if icds_feature_flag:
        location_launched_status = get_location_launched_status(
            config, loc_level)
    else:
        location_launched_status = None
    for row in data:
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        total = row['total'] or 0
        name = row['%s_name' % loc_level]

        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        row_values = {
            'severe': severe,
            'moderate': moderate,
            'total': total,
            'normal': normal,
            'total_measured': total_measured,
        }

        for prop, value in row_values.items():
            tooltips_data[name][prop] += value

        value = (moderate + severe) / float(total_measured or 1)
        chart_data['blue'].append([name, value])

    chart_data['blue'] = sorted(chart_data['blue'])

    __, __, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        "tooltips_data":
        dict(tooltips_data),
        "info":
        _(("Of the children enrolled for Anganwadi services, whose height was measured, the percentage "
           "of children between {} who were moderately/severely stunted in the current month. "
           "<br/><br/>"
           "Stunting is a sign of chronic undernutrition and has long lasting harmful consequences on "
           "the growth of a child".format(chosen_filters))),
        "chart_data": [
            {
                "values": chart_data['blue'],
                "key": "",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": MapColors.BLUE
            },
        ]
    }
コード例 #4
0
def get_prevalence_of_stunting_data_map(domain, config, loc_level, show_test=False, icds_feature_flag=False):

    def get_data_for(filters):
        filters['month'] = datetime(*filters['month'])
        queryset = AggChildHealthMonthly.objects.filter(
            **filters
        ).values(
            '%s_name' % loc_level, '%s_map_location_name' % loc_level
        ).annotate(
            moderate=Sum(stunting_moderate_column(icds_feature_flag)),
            severe=Sum(stunting_severe_column(icds_feature_flag)),
            normal=Sum(stunting_normal_column(icds_feature_flag)),
            total=Sum('height_eligible'),
            total_measured=Sum(hfa_recorded_in_month_column(icds_feature_flag)),
        ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.exclude(age_tranche=72)
        return queryset

    data_for_map = defaultdict(lambda: {
        'moderate': 0,
        'severe': 0,
        'normal': 0,
        'total': 0,
        'total_measured': 0,
        'original_name': []
    })

    moderate_total = 0
    severe_total = 0
    normal_total = 0
    all_total = 0
    measured_total = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    for row in get_data_for(config):
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average['denominator'] += total_measured if total_measured else 0

        severe_total += severe
        moderate_total += moderate
        normal_total += normal
        all_total += total
        measured_total += total_measured

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 25:
            data_for_location.update({'fillKey': '0%-25%'})
        elif 25 <= value < 38:
            data_for_location.update({'fillKey': '25%-38%'})
        elif value >= 38:
            data_for_location.update({'fillKey': '38%-100%'})

    fills = OrderedDict()
    fills.update({'0%-25%': MapColors.PINK})
    fills.update({'25%-38%': MapColors.ORANGE})
    fills.update({'38%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )
    average = (
        (values_to_calculate_average['numerator'] * 100) /
        float(values_to_calculate_average['denominator'] or 1)
    )

    return {
        "slug": "severe",
        "label": "Percent of Children{gender} Stunted ({age})".format(
            gender=gender_label,
            age=age_label
        ),
        "fills": fills,
        "rightLegend": {
            "average": "%.2f" % average,
            "info": _((
                "Of the children enrolled for Anganwadi services, whose height was measured, the percentage of "
                "children between {} who were moderately/severely stunted in the current month. "
                "<br/><br/>"
                "Stunting is a sign of chronic undernutrition and has long lasting harmful consequences on "
                "the growth of a child".format(age_label)
            )),
            "extended_info": [
                {
                    'indicator': 'Total Children{} eligible to have height measured:'.format(chosen_filters),
                    'value': indian_formatted_number(all_total)
                },
                {
                    'indicator': 'Total Children{} with height measured in given month:'
                    .format(chosen_filters),
                    'value': indian_formatted_number(measured_total)
                },
                {
                    'indicator': 'Number of Children{} unmeasured:'.format(chosen_filters),
                    'value': indian_formatted_number(all_total - measured_total)
                },
                {
                    'indicator': '% children{} with severely stunted growth:'.format(chosen_filters),
                    'value': '%.2f%%' % (severe_total * 100 / float(measured_total or 1))
                },
                {
                    'indicator': '% children{} with moderate stunted growth:'.format(chosen_filters),
                    'value': '%.2f%%' % (moderate_total * 100 / float(measured_total or 1))
                },
                {
                    'indicator': '% children{} with normal stunted growth:'.format(chosen_filters),
                    'value': '%.2f%%' % (normal_total * 100 / float(measured_total or 1))
                }
            ]
        },
        "data": dict(data_for_map),
    }
コード例 #5
0
def get_prevalence_of_severe_sector_data(domain, config, loc_level, location_id, show_test=False,
                                         icds_feature_flag=False):
    group_by = ['%s_name' % loc_level]

    config['month'] = datetime(*config['month'])
    data = AggChildHealthMonthly.objects.filter(
        **config
    ).values(
        *group_by
    ).annotate(
        moderate=Sum(wasting_moderate_column(icds_feature_flag)),
        severe=Sum(wasting_severe_column(icds_feature_flag)),
        normal=Sum(wasting_normal_column(icds_feature_flag)),
        total_height_eligible=Sum('height_eligible'),
        total_weighed=Sum('nutrition_status_weighed'),
        total_measured=Sum(wfh_recorded_in_month_column(icds_feature_flag)),
    ).order_by('%s_name' % loc_level)

    if not show_test:
        data = apply_exclude(domain, data)
    if 'age_tranche' not in config:
        data = data.exclude(age_tranche=72)

    chart_data = {
        'blue': [],
    }

    tooltips_data = defaultdict(lambda: {
        'severe': 0,
        'moderate': 0,
        'total_height_eligible': 0,
        'normal': 0,
        'total_weighed': 0,
        'total_measured': 0
    })

    loc_children = get_child_locations(domain, location_id, show_test)
    result_set = set()

    for row in data:
        total_weighed = row['total_weighed'] or 0
        name = row['%s_name' % loc_level]
        result_set.add(name)

        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0
        total_height_eligible = row['total_height_eligible'] or 0

        tooltips_data[name]['severe'] += severe
        tooltips_data[name]['moderate'] += moderate
        tooltips_data[name]['total_weighed'] += total_weighed
        tooltips_data[name]['normal'] += normal
        tooltips_data[name]['total_measured'] += total_measured
        tooltips_data[name]['total_height_eligible'] += total_height_eligible

        value = (moderate + severe) / float(total_weighed or 1)
        chart_data['blue'].append([
            name, value
        ])

    for sql_location in loc_children:
        if sql_location.name not in result_set:
            chart_data['blue'].append([sql_location.name, 0])

    chart_data['blue'] = sorted(chart_data['blue'])

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )

    return {
        "tooltips_data": dict(tooltips_data),
        "info": _(wasting_help_text(age_label)),
        "chart_data": [
            {
                "values": chart_data['blue'],
                "key": "",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": MapColors.BLUE
            },
        ]
    }
コード例 #6
0
def get_prevalence_of_stunting_data_map(domain,
                                        config,
                                        loc_level,
                                        show_test=False,
                                        icds_feature_flag=False):
    config['month'] = datetime(*config['month'])

    def get_data_for(filters):
        queryset = AggChildHealthMonthly.objects.filter(**filters).values(
            '%s_name' % loc_level,
            '%s_map_location_name' % loc_level).annotate(
                moderate=Sum(stunting_moderate_column(icds_feature_flag)),
                severe=Sum(stunting_severe_column(icds_feature_flag)),
                normal=Sum(stunting_normal_column(icds_feature_flag)),
                total=Sum('height_eligible'),
                total_measured=Sum(
                    hfa_recorded_in_month_column(icds_feature_flag)),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.filter(age_tranche__lt=72)
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total': 0,
            'total_measured': 0,
            'original_name': []
        })

    moderate_total = 0
    severe_total = 0
    normal_total = 0
    all_total = 0
    measured_total = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}

    if icds_feature_flag:
        location_launched_status = get_location_launched_status(
            config, loc_level)
    else:
        location_launched_status = None

    for row in get_data_for(config):
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average[
            'denominator'] += total_measured if total_measured else 0

        severe_total += severe
        moderate_total += moderate
        normal_total += normal
        all_total += total
        measured_total += total_measured

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total'] += total
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in data_for_map.values():
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 25:
            data_for_location.update({'fillKey': '0%-25%'})
        elif 25 <= value < 38:
            data_for_location.update({'fillKey': '25%-38%'})
        elif value >= 38:
            data_for_location.update({'fillKey': '38%-100%'})

    fills = OrderedDict()
    fills.update({'0%-25%': MapColors.PINK})
    fills.update({'25%-38%': MapColors.ORANGE})
    fills.update({'38%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))
    average = ((values_to_calculate_average['numerator'] * 100) /
               float(values_to_calculate_average['denominator'] or 1))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Stunted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % average,
            "info":
            _(("Of the children enrolled for Anganwadi services, whose height was measured, the percentage of "
               "children between {} who were moderately/severely stunted in the current month. "
               "<br/><br/>"
               "Stunting is a sign of chronic undernutrition and has long lasting harmful consequences on "
               "the growth of a child".format(age_label))),
            "extended_info": [{
                'indicator':
                'Total Children{} eligible to have height measured:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(all_total)
            }, {
                'indicator':
                'Total Children{} with height measured in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(measured_total)
            }, {
                'indicator':
                'Number of Children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(all_total - measured_total)
            }, {
                'indicator':
                '% children{} with severely stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (severe_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with moderate stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (moderate_total * 100 / float(measured_total or 1))
            }, {
                'indicator':
                '% children{} with normal stunted growth:'.format(
                    chosen_filters),
                'value':
                '%.2f%%' % (normal_total * 100 / float(measured_total or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
コード例 #7
0
def get_prevalence_of_severe_sector_data(domain,
                                         config,
                                         loc_level,
                                         location_id,
                                         show_test=False,
                                         icds_feature_flag=False):
    group_by = ['%s_name' % loc_level]

    config['month'] = datetime(*config['month'])
    data = AggChildHealthMonthly.objects.filter(**config).values(
        *group_by).annotate(
            moderate=Sum(wasting_moderate_column(icds_feature_flag)),
            severe=Sum(wasting_severe_column(icds_feature_flag)),
            normal=Sum(wasting_normal_column(icds_feature_flag)),
            total_height_eligible=Sum('height_eligible'),
            total_weighed=Sum('nutrition_status_weighed'),
            total_measured=Sum(
                wfh_recorded_in_month_column(icds_feature_flag)),
        ).order_by('%s_name' % loc_level)

    if not show_test:
        data = apply_exclude(domain, data)
    if 'age_tranche' not in config:
        data = data.filter(age_tranche__lt=72)

    chart_data = {
        'blue': [],
    }

    tooltips_data = defaultdict(
        lambda: {
            'severe': 0,
            'moderate': 0,
            'total_height_eligible': 0,
            'normal': 0,
            'total_weighed': 0,
            'total_measured': 0
        })
    if icds_feature_flag:
        location_launched_status = get_location_launched_status(
            config, loc_level)
    else:
        location_launched_status = None
    for row in data:
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        total_weighed = row['total_weighed'] or 0
        name = row['%s_name' % loc_level]

        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0
        total_height_eligible = row['total_height_eligible'] or 0

        tooltips_data[name]['severe'] += severe
        tooltips_data[name]['moderate'] += moderate
        tooltips_data[name]['total_weighed'] += total_weighed
        tooltips_data[name]['normal'] += normal
        tooltips_data[name]['total_measured'] += total_measured
        tooltips_data[name]['total_height_eligible'] += total_height_eligible

        value = (moderate + severe) / float(total_weighed or 1)
        chart_data['blue'].append([name, value])

    chart_data['blue'] = sorted(chart_data['blue'])

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        "tooltips_data":
        dict(tooltips_data),
        "info":
        _(wasting_help_text(age_label)),
        "chart_data": [
            {
                "values": chart_data['blue'],
                "key": "",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": MapColors.BLUE
            },
        ]
    }
コード例 #8
0
def get_prevalence_of_severe_data_map(domain,
                                      config,
                                      loc_level,
                                      show_test=False,
                                      icds_feature_flag=False):
    def get_data_for(filters):
        filters['month'] = datetime(*filters['month'])
        queryset = AggChildHealthMonthly.objects.filter(**filters).values(
            '%s_name' % loc_level,
            '%s_map_location_name' % loc_level).annotate(
                moderate=Sum(wasting_moderate_column(icds_feature_flag)),
                severe=Sum(wasting_severe_column(icds_feature_flag)),
                normal=Sum(wasting_normal_column(icds_feature_flag)),
                total_height_eligible=Sum('height_eligible'),
                total_weighed=Sum('nutrition_status_weighed'),
                total_measured=Sum(
                    wfh_recorded_in_month_column(icds_feature_flag)),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)

        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            if icds_feature_flag:
                queryset = queryset.exclude(age_tranche=72)
            else:
                queryset = queryset.exclude(age_tranche__in=[0, 6, 72])
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total_weighed': 0,
            'total_measured': 0,
            'total_height_eligible': 0,
            'original_name': []
        })

    severe_for_all_locations = 0
    moderate_for_all_locations = 0
    normal_for_all_locations = 0
    weighed_for_all_locations = 0
    measured_for_all_locations = 0
    height_eligible_for_all_locations = 0

    values_to_calculate_average = []
    for row in get_data_for(config):
        total_weighed = row['total_weighed'] or 0
        total_height_eligible = row['total_height_eligible'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        numerator = moderate + severe
        values_to_calculate_average.append(numerator * 100 /
                                           (total_weighed or 1))

        severe_for_all_locations += severe
        moderate_for_all_locations += moderate
        normal_for_all_locations += normal
        weighed_for_all_locations += total_weighed
        measured_for_all_locations += total_measured
        height_eligible_for_all_locations += total_height_eligible

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total_weighed'] += total_weighed
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name][
            'total_height_eligible'] += total_height_eligible
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 5:
            data_for_location.update({'fillKey': '0%-5%'})
        elif 5 <= value <= 7:
            data_for_location.update({'fillKey': '5%-7%'})
        elif value > 7:
            data_for_location.update({'fillKey': '7%-100%'})

    fills = OrderedDict()
    fills.update({'0%-5%': MapColors.PINK})
    fills.update({'5%-7%': MapColors.ORANGE})
    fills.update({'7%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Wasted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % ((sum(values_to_calculate_average)) /
                      float(len(values_to_calculate_average) or 1)),
            "info":
            _(("Of the children enrolled for Anganwadi services, whose weight and height was measured, "
               "the percentage of children between {} who were moderately/severely wasted in the current month. "
               "<br/><br/>"
               "Severe Acute Malnutrition (SAM) or wasting in children is a symptom of acute undernutrition "
               "usually as a consequence of insufficient food intake or a high incidence of infectious diseases."
               .format(age_label))),
            "extended_info": [{
                'indicator':
                'Total Children{} weighed in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(weighed_for_all_locations)
            }, {
                'indicator':
                'Total Children{} with height measured in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(measured_for_all_locations)
            }, {
                'indicator':
                'Number of children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(height_eligible_for_all_locations -
                                        weighed_for_all_locations)
            }, {
                'indicator':
                '% Severely Acute Malnutrition{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (severe_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }, {
                'indicator':
                '% Moderately Acute Malnutrition{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (moderate_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }, {
                'indicator':
                '% Normal{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (normal_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
コード例 #9
0
def get_maternal_child_data(domain,
                            config,
                            show_test=False,
                            icds_feature_flag=False):
    def get_data_for_child_health_monthly(date, filters):

        age_filters = {
            'age_tranche': 72
        } if icds_feature_flag else {
            'age_tranche__in': [0, 6, 72]
        }

        moderately_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72}, 'nutrition_status_moderately_underweight')
        severely_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72}, 'nutrition_status_severely_underweight')
        wasting_moderate = exclude_records_by_age_for_column(
            age_filters, wasting_moderate_column(icds_feature_flag))
        wasting_severe = exclude_records_by_age_for_column(
            age_filters, wasting_severe_column(icds_feature_flag))
        stunting_moderate = exclude_records_by_age_for_column(
            age_filters, stunting_moderate_column(icds_feature_flag))
        stunting_severe = exclude_records_by_age_for_column(
            age_filters, stunting_severe_column(icds_feature_flag))
        nutrition_status_weighed = exclude_records_by_age_for_column(
            {'age_tranche': 72}, 'nutrition_status_weighed')
        height_measured_in_month = exclude_records_by_age_for_column(
            age_filters, hfa_recorded_in_month_column(icds_feature_flag))
        weighed_and_height_measured_in_month = exclude_records_by_age_for_column(
            age_filters, wfh_recorded_in_month_column(icds_feature_flag))

        queryset = AggChildHealthMonthly.objects.filter(
            month=date, **filters).values('aggregation_level').annotate(
                underweight=(Sum(moderately_underweight) +
                             Sum(severely_underweight)),
                valid=Sum(nutrition_status_weighed),
                wasting=Sum(wasting_moderate) + Sum(wasting_severe),
                stunting=Sum(stunting_moderate) + Sum(stunting_severe),
                height_measured_in_month=Sum(height_measured_in_month),
                weighed_and_height_measured_in_month=Sum(
                    weighed_and_height_measured_in_month),
                low_birth_weight=Sum('low_birth_weight_in_month'),
                bf_birth=Sum('bf_at_birth'),
                born=Sum('born_in_month'),
                weighed_and_born_in_month=Sum('weighed_and_born_in_month'),
                ebf=Sum('ebf_in_month'),
                ebf_eli=Sum('ebf_eligible'),
                cf_initiation=Sum('cf_initiation_in_month'),
                cf_initiation_eli=Sum('cf_initiation_eligible'))
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    def get_data_for_deliveries(date, filters):
        queryset = AggCcsRecordMonthly.objects.filter(
            month=date, **filters).values('aggregation_level').annotate(
                institutional_delivery=Sum('institutional_delivery_in_month'),
                delivered=Sum('delivered_in_month'))
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    current_month = datetime(*config['month'])
    previous_month = datetime(*config['prev_month'])
    del config['month']
    del config['prev_month']

    this_month_data = get_data_for_child_health_monthly(current_month, config)
    prev_month_data = get_data_for_child_health_monthly(previous_month, config)

    deliveries_this_month = get_data_for_deliveries(current_month, config)
    deliveries_prev_month = get_data_for_deliveries(previous_month, config)

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        'records':
        [[{
            'label':
            _('Underweight (Weight-for-Age)'),
            'help_text':
            underweight_children_help_text(),
            'percent':
            percent_diff('underweight', this_month_data, prev_month_data,
                         'valid'),
            'color':
            'red' if percent_diff('underweight', this_month_data,
                                  prev_month_data, 'valid') > 0 else 'green',
            'value':
            get_value(this_month_data, 'underweight'),
            'all':
            get_value(this_month_data, 'valid'),
            'format':
            'percent_and_div',
            'frequency':
            'month',
            'redirect':
            'maternal_and_child/underweight_children'
        }, {
            'label':
            _('Wasting (Weight-for-Height)'),
            'help_text':
            _(wasting_help_text(age_label)),
            'percent':
            percent_diff('wasting', this_month_data, prev_month_data,
                         'weighed_and_height_measured_in_month'),
            'color':
            'red' if percent_diff('wasting', this_month_data, prev_month_data,
                                  'weighed_and_height_measured_in_month') > 0
            else 'green',
            'value':
            get_value(this_month_data, 'wasting'),
            'all':
            get_value(this_month_data, 'weighed_and_height_measured_in_month'),
            'format':
            'percent_and_div',
            'frequency':
            'month',
            'redirect':
            'maternal_and_child/wasting'
        }],
         [{
             'label':
             _('Stunting (Height-for-Age)'),
             'help_text':
             _(stunting_help_text(age_label)),
             'percent':
             percent_diff('stunting', this_month_data, prev_month_data,
                          'height_measured_in_month'),
             'color':
             'red'
             if percent_diff('stunting', this_month_data, prev_month_data,
                             'height_measured_in_month') > 0 else 'green',
             'value':
             get_value(this_month_data, 'stunting'),
             'all':
             get_value(this_month_data, 'height_measured_in_month'),
             'format':
             'percent_and_div',
             'frequency':
             'month',
             'redirect':
             'maternal_and_child/stunting'
         }, {
             'label':
             _('Newborns with Low Birth Weight'),
             'help_text':
             _((new_born_with_low_weight_help_text(html=False))),
             'percent':
             percent_diff('low_birth_weight', this_month_data, prev_month_data,
                          'weighed_and_born_in_month'),
             'color':
             get_color_with_red_positive(
                 percent_diff('low_birth_weight', this_month_data,
                              prev_month_data, 'weighed_and_born_in_month')),
             'value':
             get_value(this_month_data, 'low_birth_weight'),
             'all':
             get_value(this_month_data, 'weighed_and_born_in_month'),
             'format':
             'percent_and_div',
             'frequency':
             'month',
             'redirect':
             'maternal_and_child/low_birth'
         }],
         [{
             'label':
             _('Early Initiation of Breastfeeding'),
             'help_text':
             early_initiation_breastfeeding_help_text(),
             'percent':
             percent_diff('bf_birth', this_month_data, prev_month_data,
                          'born'),
             'color':
             get_color_with_green_positive(
                 percent_diff('bf_birth', this_month_data, prev_month_data,
                              'born')),
             'value':
             get_value(this_month_data, 'bf_birth'),
             'all':
             get_value(this_month_data, 'born'),
             'format':
             'percent_and_div',
             'frequency':
             'month',
             'redirect':
             'maternal_and_child/early_initiation'
         }, {
             'label':
             _('Exclusive Breastfeeding'),
             'help_text':
             exclusive_breastfeeding_help_text(),
             'percent':
             percent_diff('ebf', this_month_data, prev_month_data, 'ebf_eli'),
             'color':
             get_color_with_green_positive(
                 percent_diff('ebf', this_month_data, prev_month_data,
                              'ebf_eli')),
             'value':
             get_value(this_month_data, 'ebf'),
             'all':
             get_value(this_month_data, 'ebf_eli'),
             'format':
             'percent_and_div',
             'frequency':
             'month',
             'redirect':
             'maternal_and_child/exclusive_breastfeeding'
         }],
         [{
             'label':
             _('Children initiated appropriate Complementary Feeding'),
             'help_text':
             children_initiated_appropriate_complementary_feeding_help_text(),
             'percent':
             percent_diff('cf_initiation', this_month_data, prev_month_data,
                          'cf_initiation_eli'),
             'color':
             get_color_with_green_positive(
                 percent_diff('cf_initiation', this_month_data,
                              prev_month_data, 'cf_initiation_eli')),
             'value':
             get_value(this_month_data, 'cf_initiation'),
             'all':
             get_value(this_month_data, 'cf_initiation_eli'),
             'format':
             'percent_and_div',
             'frequency':
             'month',
             'redirect':
             'maternal_and_child/children_initiated'
         }, {
             'label':
             _('Institutional Deliveries'),
             'help_text':
             institutional_deliveries_help_text(),
             'percent':
             percent_diff('institutional_delivery', deliveries_this_month,
                          deliveries_prev_month, 'delivered'),
             'color':
             get_color_with_green_positive(
                 percent_diff('institutional_delivery', deliveries_this_month,
                              deliveries_prev_month, 'delivered')),
             'value':
             get_value(deliveries_this_month, 'institutional_delivery'),
             'all':
             get_value(deliveries_this_month, 'delivered'),
             'format':
             'percent_and_div',
             'frequency':
             'month',
             'redirect':
             'maternal_and_child/institutional_deliveries'
         }]]
    }
コード例 #10
0
def get_prevalence_of_severe_data_map(domain,
                                      config,
                                      loc_level,
                                      show_test=False,
                                      icds_feature_flag=False):
    config['month'] = datetime(*config['month'])

    def get_data_for(filters):
        queryset = AggChildHealthMonthly.objects.filter(**filters).values(
            '%s_name' % loc_level,
            '%s_map_location_name' % loc_level).annotate(
                moderate=Sum(wasting_moderate_column(icds_feature_flag)),
                severe=Sum(wasting_severe_column(icds_feature_flag)),
                normal=Sum(wasting_normal_column(icds_feature_flag)),
                total_height_eligible=Sum('height_eligible'),
                total_weighed=Sum('nutrition_status_weighed'),
                total_measured=Sum(
                    wfh_recorded_in_month_column(icds_feature_flag)),
            ).order_by('%s_name' % loc_level,
                       '%s_map_location_name' % loc_level)

        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.filter(age_tranche__lt=72)
        return queryset

    data_for_map = defaultdict(
        lambda: {
            'moderate': 0,
            'severe': 0,
            'normal': 0,
            'total_weighed': 0,
            'total_measured': 0,
            'total_height_eligible': 0,
            'original_name': []
        })

    severe_for_all_locations = 0
    moderate_for_all_locations = 0
    normal_for_all_locations = 0
    weighed_for_all_locations = 0
    measured_for_all_locations = 0
    height_eligible_for_all_locations = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    if icds_feature_flag:
        location_launched_status = get_location_launched_status(
            config, loc_level)
    else:
        location_launched_status = None
    for row in get_data_for(config):
        if location_launched_status:
            launched_status = location_launched_status.get(row['%s_name' %
                                                               loc_level])
            if launched_status is None or launched_status <= 0:
                continue
        total_weighed = row['total_weighed'] or 0
        total_height_eligible = row['total_height_eligible'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average[
            'denominator'] += total_measured if total_measured else 0

        severe_for_all_locations += severe
        moderate_for_all_locations += moderate
        normal_for_all_locations += normal
        weighed_for_all_locations += total_weighed
        measured_for_all_locations += total_measured
        height_eligible_for_all_locations += total_height_eligible

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total_weighed'] += total_weighed
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name][
            'total_height_eligible'] += total_height_eligible
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in data_for_map.values():
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 5:
            data_for_location.update({'fillKey': '0%-5%'})
        elif 5 <= value <= 7:
            data_for_location.update({'fillKey': '5%-7%'})
        elif value > 7:
            data_for_location.update({'fillKey': '7%-100%'})

    fills = OrderedDict()
    fills.update({'0%-5%': MapColors.PINK})
    fills.update({'5%-7%': MapColors.ORANGE})
    fills.update({'7%-100%': MapColors.RED})
    if icds_feature_flag:
        fills.update({'Not Launched': MapColors.GREY})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    average = ((values_to_calculate_average['numerator'] * 100) /
               float(values_to_calculate_average['denominator'] or 1))

    return {
        "slug":
        "severe",
        "label":
        "Percent of Children{gender} Wasted ({age})".format(
            gender=gender_label, age=age_label),
        "fills":
        fills,
        "rightLegend": {
            "average":
            "%.2f" % average,
            "info":
            wasting_help_text(age_label),
            "extended_info": [{
                'indicator':
                'Total Children{} weighed in given month:'.format(
                    chosen_filters),
                'value':
                indian_formatted_number(weighed_for_all_locations)
            }, {
                'indicator':
                'Total Children{} with weight and height measured in given month:'
                .format(chosen_filters),
                'value':
                indian_formatted_number(measured_for_all_locations)
            }, {
                'indicator':
                'Number of children{} unmeasured:'.format(chosen_filters),
                'value':
                indian_formatted_number(height_eligible_for_all_locations -
                                        weighed_for_all_locations)
            }, {
                'indicator':
                '% Severely Acute Malnutrition{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (severe_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }, {
                'indicator':
                '% Moderately Acute Malnutrition{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (moderate_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }, {
                'indicator':
                '% Normal{}:'.format(chosen_filters),
                'value':
                '%.2f%%' % (normal_for_all_locations * 100 /
                            float(measured_for_all_locations or 1))
            }]
        },
        "data":
        dict(data_for_map),
    }
コード例 #11
0
ファイル: fact_sheets.py プロジェクト: kkrampa/commcare-hq
    def new_table_config(self):
        return [
            {
                'category': 'maternal_and_child_nutrition',
                'title': 'Maternal and Child Nutrition',
                'sections': [
                    {
                        'section_title': 'Nutrition Status of Children',
                        'slug': 'nutrition_status_of_children',
                        'order': 1,
                        'rows_config': [
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Weighing Efficiency (Children <5 weighed)',
                                'slug': 'status_weighed',
                                'average': [],
                                'format': 'percent',
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Height measurement efficiency (Children <5 measured)',
                                'slug': 'status_height_efficiency',
                                'average': [],
                                'format': 'percent',
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Total number of unweighed children (0-5 Years)',
                                'slug': 'nutrition_status_unweighed',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 0 - 5 years who are '
                                          'severely underweight (weight-for-age)',
                                'slug': 'severely_underweight',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 0-5 years who '
                                          'are moderately underweight (weight-for-age)',
                                'slug': 'moderately_underweight',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 0-5 years who are at normal weight-for-age',
                                'slug': 'status_normal',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Children from {} with severe acute '
                                    'malnutrition (weight-for-height)'.format(default_age_interval(self.beta))
                                ),
                                'slug': 'wasting_severe',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Children from {} with moderate acute '
                                    'malnutrition (weight-for-height)'.format(default_age_interval(self.beta))
                                ),
                                'slug': 'wasting_moderate',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Children from {} with normal '
                                    'weight-for-height'.format(default_age_interval(self.beta))
                                ),
                                'slug': 'wasting_normal',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Children from {} with severe stunting '
                                    '(height-for-age)'.format(default_age_interval(self.beta))
                                ),
                                'slug': 'stunting_severe',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Children from {} with moderate stunting '
                                    '(height-for-age)'.format(default_age_interval(self.beta))
                                ),
                                'slug': 'stunting_moderate',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Children from {} with normal '
                                    'height-for-age'.format(default_age_interval(self.beta))
                                ),
                                'slug': 'stunting_normal',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Percent of children born in month with low birth weight',
                                'slug': 'low_birth_weight',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True,
                            }
                        ]
                    }
                ]
            },
            {
                'category': 'interventions',
                'title': 'Interventions',
                'sections': [
                    {
                        'section_title': 'Nutrition Status of Children',
                        'slug': 'nutrition_status_of_children',
                        'order': 1,
                        'rows_config': [
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children 1 year+ who have recieved complete '
                                          'immunization required by age 1.',
                                'slug': 'fully_immunized',
                                'average': [],
                                'format': 'percent'
                            }
                        ]
                    },
                    {
                        'section_title': 'Nutrition Status of Pregnant Women',
                        'slug': 'nutrition_status_of_pregnant_women',
                        'order': 3,
                        'rows_config': [
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Pregnant women who are anemic',
                                'slug': 'severe_anemic',
                                'average': [],
                                'format': 'percent',
                                'reverseColors': True
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Pregnant women with tetanus completed',
                                'slug': 'tetanus_complete',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Pregnant women who had at least 1 ANC visit by delivery',
                                'slug': 'anc_1',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Pregnant women who had at least 2 ANC visits by delivery',
                                'slug': 'anc_2',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Pregnant women who had at least 3 ANC visits by delivery',
                                'slug': 'anc_3',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Pregnant women who had at least 4 ANC visits by delivery',
                                'slug': 'anc_4',
                                'average': [],
                                'format': 'percent'
                            }
                        ]
                    },
                    {
                        'section_title': 'AWC Infrastructure',
                        'slug': 'awc_infrastructure',
                        'order': 5,
                        'rows_config': [
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'AWCs reported medicine kit',
                                'slug': 'medicine_kits',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'AWCs reported weighing scale for infants',
                                'slug': 'baby_weighing_scale',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'AWCs reported weighing scale for mother and child',
                                'slug': 'adult_weighing_scale',
                                'average': [],
                                'format': 'percent'
                            }
                        ]
                    },
                ]
            },
            {
                'category': 'behavior_change',
                'title': 'Behavior Change',
                'sections': [
                    {
                        'section_title': 'Child Feeding Indicators',
                        'slug': 'child_feeding_indicators',
                        'order': 2,
                        'rows_config': [
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    'Percentage of children who were put to the breast within one hour of birth.'
                                ),
                                'slug': 'breastfed_at_birth',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Infants 0-6 months of age who '
                                          'are fed exclusively with breast milk.',
                                'slug': 'exclusively_breastfed',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': (
                                    "Children between 6 - 8 months given timely introduction to solid, "
                                    "semi-solid or soft food."
                                ),
                                'slug': 'cf_initiation',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 6 - 24 months complementary feeding',
                                'slug': 'complementary_feeding',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 6 - 24 months consuming at least 4 food groups',
                                'slug': 'diet_diversity',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 6 - 24 months consuming adequate food',
                                'slug': 'diet_quantity',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children from 6 - 24 months '
                                          'whose mothers handwash before feeding',
                                'slug': 'handwashing',
                                'average': [],
                                'format': 'percent'
                            }
                        ]
                    },
                    {
                        'section_title': 'Nutrition Status of Pregnant Women',
                        'slug': 'nutrition_status_of_pregnant_women',
                        'order': 3,
                        "rows_config": [
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Women resting during pregnancy',
                                'slug': 'resting',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': 'Women eating an extra meal during pregnancy',
                                'slug': 'extra_meal',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggCCSRecordMonthlyDataSource',
                                'header': (
                                    "Pregnant women in 3rd trimester counselled "
                                    "on immediate and exclusive "
                                    "breastfeeding during home visit"
                                ),
                                'slug': 'trimester',
                                'average': [],
                                'format': 'percent'
                            }
                        ]
                    }
                ]
            },
            {
                'category': 'water_sanitation_and_hygiene',
                'title': 'Water Sanitation And Hygiene',
                "sections": [
                    {
                        'section_title': 'AWC Infrastructure',
                        'slug': 'awc_infrastructure',
                        'order': 5,
                        'rows_config': [
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'AWCs reported clean drinking water',
                                'slug': 'clean_water',
                                'average': [],
                                'format': 'percent'
                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'AWCs reported functional toilet',
                                'slug': 'functional_toilet',
                                'average': [],
                                'format': 'percent'
                            }
                        ]
                    }
                ]
            },
            {
                'category': 'demographics',
                'title': 'Demographics',
                'sections': [
                    {
                        'section_title': 'Demographics',
                        'slug': 'demographics',
                        'order': 4,
                        'rows_config': [
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Number of Households',
                                'slug': 'cases_household',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total Number of Household Members',
                                'slug': 'cases_person_all',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total number of members enrolled at AWC',
                                'slug': self.person_is_beneficiary_column,
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Percent Aadhaar-seeded beneficiaries',
                                'slug': 'aadhar',
                                'format': 'percent',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total pregnant women ',
                                'slug': 'cases_ccs_pregnant_all',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total pregnant women enrolled for services at AWC',
                                'slug': 'cases_ccs_pregnant',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total lactating women',
                                'slug': 'cases_ccs_lactating_all',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total lactating women registered for services at AWC',
                                'slug': 'cases_ccs_lactating',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total children (0-6 years)',
                                'slug': 'cases_child_health_all',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Total chldren (0-6 years) enrolled for Anganwadi Services',
                                'slug': 'cases_child_health',
                                'average': [],

                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children (0-28 days)  enrolled for Anganwadi Services',
                                'slug': 'zero',
                                'average': [],
                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children (28 days - 6 months)  enrolled for Anganwadi Services',
                                'slug': 'one',
                                'average': [],

                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children (6 months - 1 year)  enrolled for Anganwadi Services',
                                'slug': 'two',
                                'average': [],

                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children (1 year - 3 years)  enrolled for Anganwadi Services',
                                'slug': 'three',
                                'average': [],

                            },
                            {
                                'data_source': 'AggChildHealthMonthlyDataSource',
                                'header': 'Children (3 years - 6 years)  enrolled for Anganwadi Services',
                                'slug': 'four',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Adolescent girls (11-14 years)',
                                'slug': 'cases_person_adolescent_girls_11_14_all',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Adolescent girls (15-18 years)',
                                'slug': 'cases_person_adolescent_girls_15_18_all',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Adolescent girls (11-14 years)  enrolled for Anganwadi Services',
                                'slug': 'cases_person_adolescent_girls_11_14',
                                'average': [],

                            },
                            {
                                'data_source': 'AggAWCMonthlyDataSource',
                                'header': 'Adolescent girls (15-18 years)  enrolled for Anganwadi Services',
                                'slug': 'cases_person_adolescent_girls_15_18',
                                'average': [],

                            }
                        ]
                    },
                ]
            }
        ]
コード例 #12
0
def get_awc_reports_maternal_child(domain,
                                   config,
                                   month,
                                   prev_month,
                                   show_test=False,
                                   icds_feature_flag=False):
    def get_data_for(date):
        age_filters = {
            'age_tranche': 72
        } if icds_feature_flag else {
            'age_tranche__in': [0, 6, 72]
        }

        moderately_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72}, 'nutrition_status_moderately_underweight')
        severely_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72}, 'nutrition_status_severely_underweight')
        wasting_moderate = exclude_records_by_age_for_column(
            age_filters, wasting_moderate_column(icds_feature_flag))
        wasting_severe = exclude_records_by_age_for_column(
            age_filters, wasting_severe_column(icds_feature_flag))
        stunting_moderate = exclude_records_by_age_for_column(
            age_filters, stunting_moderate_column(icds_feature_flag))
        stunting_severe = exclude_records_by_age_for_column(
            age_filters, stunting_severe_column(icds_feature_flag))
        nutrition_status_weighed = exclude_records_by_age_for_column(
            {'age_tranche': 72}, 'nutrition_status_weighed')
        height_measured_in_month = exclude_records_by_age_for_column(
            age_filters, hfa_recorded_in_month_column(icds_feature_flag))
        weighed_and_height_measured_in_month = exclude_records_by_age_for_column(
            age_filters, wfh_recorded_in_month_column(icds_feature_flag))

        queryset = AggChildHealthMonthly.objects.filter(
            month=date,
            **config).values('month', 'aggregation_level').annotate(
                underweight=(Sum(moderately_underweight) +
                             Sum(severely_underweight)),
                valid_weighed=Sum(nutrition_status_weighed),
                immunized=(Sum('fully_immunized_on_time') +
                           Sum('fully_immunized_late')),
                eligible=Sum('fully_immunized_eligible'),
                wasting=Sum(wasting_moderate) + Sum(wasting_severe),
                height_measured_in_month=Sum(height_measured_in_month),
                weighed_and_height_measured_in_month=Sum(
                    weighed_and_height_measured_in_month),
                stunting=Sum(stunting_moderate) + Sum(stunting_severe),
                low_birth=Sum('low_birth_weight_in_month'),
                birth=Sum('bf_at_birth'),
                born=Sum('born_in_month'),
                weighed_and_born_in_month=Sum('weighed_and_born_in_month'),
                month_ebf=Sum('ebf_in_month'),
                ebf=Sum('ebf_eligible'),
                month_cf=Sum('cf_initiation_in_month'),
                cf=Sum('cf_initiation_eligible'))
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    def get_weight_efficiency(date):
        queryset = AggAwcMonthly.objects.filter(month=date, **config).values(
            'month', 'aggregation_level',
            'awc_name').annotate(wer_weight=Sum('wer_weighed'),
                                 wer_eli=Sum('wer_eligible'))
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    def get_institutional_delivery_data(date):
        queryset = AggCcsRecordMonthly.objects.filter(
            month=date, **config).values(
                'month', 'aggregation_level', 'awc_name').annotate(
                    institutional_delivery_in_month_sum=Sum(
                        'institutional_delivery_in_month'),
                    delivered_in_month_sum=Sum('delivered_in_month'))
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    this_month_data = get_data_for(datetime(*month))
    prev_month_data = get_data_for(datetime(*prev_month))

    this_month_data_we = get_weight_efficiency(datetime(*month))
    prev_month_data_we = get_weight_efficiency(datetime(*prev_month))

    this_month_institutional_delivery_data = get_institutional_delivery_data(
        datetime(*month))
    prev_month_institutional_delivery_data = get_institutional_delivery_data(
        datetime(*prev_month))

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        'kpi':
        [[
            {
                'label':
                _('Underweight (Weight-for-Age)'),
                'help_text':
                _(("Of the total children weighed, the percentage of children between 0-5 years who were "
                   "moderately/severely underweight in the current month. Children who are moderately or "
                   "severely underweight have a higher risk of mortality. ")),
                'percent':
                percent_diff('underweight', this_month_data, prev_month_data,
                             'valid_weighed'),
                'color':
                'red' if percent_diff('underweight', this_month_data,
                                      prev_month_data, 'valid_weighed') > 0
                else 'green',
                'value':
                get_value(this_month_data, 'underweight'),
                'all':
                get_value(this_month_data, 'valid_weighed'),
                'format':
                'percent_and_div',
                'frequency':
                'month'
            },
            {
                'label':
                _('Wasting (Weight-for-Height)'),
                'help_text':
                wasting_help_text(age_label),
                'percent':
                percent_diff('wasting', this_month_data, prev_month_data,
                             'weighed_and_height_measured_in_month'),
                'color':
                'red'
                if percent_diff('wasting', this_month_data, prev_month_data,
                                'weighed_and_height_measured_in_month') > 0
                else 'green',
                'value':
                get_value(this_month_data, 'wasting'),
                'all':
                get_value(this_month_data,
                          'weighed_and_height_measured_in_month'),
                'format':
                'percent_and_div',
                'frequency':
                'month'
            },
        ],
         [
             {
                 'label':
                 _('Stunting (Height-for-Age)'),
                 'help_text':
                 stunting_help_text(age_label),
                 'percent':
                 percent_diff('stunting', this_month_data, prev_month_data,
                              'height_measured_in_month'),
                 'color':
                 'red'
                 if percent_diff('stunting', this_month_data, prev_month_data,
                                 'height_measured_in_month') > 0 else 'green',
                 'value':
                 get_value(this_month_data, 'stunting'),
                 'all':
                 get_value(this_month_data, 'height_measured_in_month'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
             {
                 'label':
                 _('Weighing Efficiency'),
                 'help_text':
                 _("Of the children between the ages of 0-5 years who are enrolled for Anganwadi Services, "
                   "the percentage who were weighed in the given month. "),
                 'percent':
                 percent_diff('wer_weight', this_month_data_we,
                              prev_month_data_we, 'wer_eli'),
                 'color':
                 'green'
                 if percent_diff('wer_weight', this_month_data_we,
                                 prev_month_data_we, 'wer_eli') > 0 else 'red',
                 'value':
                 get_value(this_month_data_we, 'wer_weight'),
                 'all':
                 get_value(this_month_data_we, 'wer_eli'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
         ],
         [
             {
                 'label':
                 _('Newborns with Low Birth Weight'),
                 'help_text':
                 _("Of all the children born in the current month, the percentage that had a birth weight "
                   "less than 2500 grams. Newborns with Low Birth Weight are closely associated wtih foetal "
                   "and neonatal mortality and morbidity, inhibited growth and cognitive development, "
                   "and chronic diseases later in life."),
                 'percent':
                 percent_diff('low_birth', this_month_data, prev_month_data,
                              'weighed_and_born_in_month'),
                 'color':
                 'red'
                 if percent_diff('low_birth', this_month_data, prev_month_data,
                                 'weighed_and_born_in_month') > 0 else 'green',
                 'value':
                 get_value(this_month_data, 'low_birth'),
                 'all':
                 get_value(this_month_data, 'weighed_and_born_in_month'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
             {
                 'label':
                 _('Early Initiation of Breastfeeding'),
                 'help_text':
                 _("Of the children born in the last month, the percentage whose "
                   "breastfeeding was initiated within 1 hour of delivery. Early initiation "
                   "of breastfeeding ensure the newborn recieves the \"first milk\" rich "
                   "in nutrients and encourages exclusive breastfeeding practice"
                   ),
                 'percent':
                 percent_diff('birth', this_month_data, prev_month_data,
                              'born'),
                 'color':
                 'green'
                 if percent_diff('birth', this_month_data, prev_month_data,
                                 'born') > 0 else 'red',
                 'value':
                 get_value(this_month_data, 'birth'),
                 'all':
                 get_value(this_month_data, 'born'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
         ],
         [
             {
                 'label':
                 _('Exclusive breastfeeding'),
                 'help_text':
                 _("Of the total children between the ages of 0 to 6 months, the percentage that was "
                   "exclusively fed with breast milk. An infant is exclusively breastfed if they receive "
                   "only breastmilk with no additional food or liquids (even water), ensuring optimal "
                   "nutrition and growth between 0 - 6 months"),
                 'percent':
                 percent_diff('month_ebf', this_month_data, prev_month_data,
                              'ebf'),
                 'color':
                 'green'
                 if percent_diff('month_ebf', this_month_data, prev_month_data,
                                 'ebf') > 0 else 'red',
                 'value':
                 get_value(this_month_data, 'month_ebf'),
                 'all':
                 get_value(this_month_data, 'ebf'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
             {
                 'label':
                 _('Children initiated appropriate Complementary Feeding'),
                 'help_text':
                 _("Of the total children between the ages of 6 to 8 months, the percentage that was "
                   "given a timely introduction to solid, semi-solid or soft food. Timely intiation of "
                   "complementary feeding in addition to breastmilk at 6 months of age is a key feeding "
                   "practice to reduce malnutrition"),
                 'percent':
                 percent_diff('month_cf', this_month_data, prev_month_data,
                              'cf'),
                 'color':
                 'green' if percent_diff('month_cf', this_month_data,
                                         prev_month_data, 'cf') > 0 else 'red',
                 'value':
                 get_value(this_month_data, 'month_cf'),
                 'all':
                 get_value(this_month_data, 'cf'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
         ],
         [
             {
                 'label':
                 _('Immunization Coverage (at age 1 year)'),
                 'help_text':
                 _(("Of the total number of children enrolled for Anganwadi Services who are over a year old, "
                    "the percentage of children who have received the complete immunization as per the "
                    "National Immunization Schedule of India that is required by age 1."
                    "<br/><br/> "
                    "This includes the following immunizations:<br/> "
                    "If Pentavalent path: Penta1/2/3, OPV1/2/3, BCG, Measles, VitA1<br/> "
                    "If DPT/HepB path: DPT1/2/3, HepB1/2/3, OPV1/2/3, BCG, Measles, VitA1"
                    )),
                 'percent':
                 percent_diff('immunized', this_month_data, prev_month_data,
                              'eligible'),
                 'color':
                 'green'
                 if percent_diff('immunized', this_month_data, prev_month_data,
                                 'eligible') > 0 else 'red',
                 'value':
                 get_value(this_month_data, 'immunized'),
                 'all':
                 get_value(this_month_data, 'eligible'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
             {
                 'label':
                 _('Institutional Deliveries'),
                 'help_text':
                 _(("Of the total number of women who gave birth in the last month, the percentage who "
                    "delivered in a public or private medical facility. Delivery in medical instituitions "
                    "is associated with a decrease in maternal mortality rate"
                    )),
                 'percent':
                 percent_diff('institutional_delivery_in_month_sum',
                              this_month_institutional_delivery_data,
                              prev_month_institutional_delivery_data,
                              'delivered_in_month_sum'),
                 'color':
                 'green'
                 if percent_diff('institutional_delivery_in_month_sum',
                                 this_month_institutional_delivery_data,
                                 prev_month_institutional_delivery_data,
                                 'delivered_in_month_sum') > 0 else 'red',
                 'value':
                 get_value(this_month_institutional_delivery_data,
                           'institutional_delivery_in_month_sum'),
                 'all':
                 get_value(this_month_institutional_delivery_data,
                           'delivered_in_month_sum'),
                 'format':
                 'percent_and_div',
                 'frequency':
                 'month'
             },
         ]]
    }
コード例 #13
0
def get_maternal_child_data(domain, config, show_test=False, icds_feature_flag=False):

    def get_data_for_child_health_monthly(date, filters):

        age_filters = {'age_tranche': 72} if icds_feature_flag else {'age_tranche__in': [0, 6, 72]}

        moderately_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72},
            'nutrition_status_moderately_underweight'
        )
        severely_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72},
            'nutrition_status_severely_underweight'
        )
        wasting_moderate = exclude_records_by_age_for_column(
            age_filters,
            wasting_moderate_column(icds_feature_flag)
        )
        wasting_severe = exclude_records_by_age_for_column(
            age_filters,
            wasting_severe_column(icds_feature_flag)
        )
        stunting_moderate = exclude_records_by_age_for_column(
            age_filters,
            stunting_moderate_column(icds_feature_flag)
        )
        stunting_severe = exclude_records_by_age_for_column(
            age_filters,
            stunting_severe_column(icds_feature_flag)
        )
        nutrition_status_weighed = exclude_records_by_age_for_column(
            {'age_tranche': 72},
            'nutrition_status_weighed'
        )
        height_measured_in_month = exclude_records_by_age_for_column(
            age_filters,
            hfa_recorded_in_month_column(icds_feature_flag)
        )
        weighed_and_height_measured_in_month = exclude_records_by_age_for_column(
            age_filters,
            wfh_recorded_in_month_column(icds_feature_flag)
        )

        queryset = AggChildHealthMonthly.objects.filter(
            month=date, **filters
        ).values(
            'aggregation_level'
        ).annotate(
            underweight=(
                Sum(moderately_underweight) + Sum(severely_underweight)
            ),
            valid=Sum(nutrition_status_weighed),
            wasting=Sum(wasting_moderate) + Sum(wasting_severe),
            stunting=Sum(stunting_moderate) + Sum(stunting_severe),
            height_measured_in_month=Sum(height_measured_in_month),
            weighed_and_height_measured_in_month=Sum(weighed_and_height_measured_in_month),
            low_birth_weight=Sum('low_birth_weight_in_month'),
            bf_birth=Sum('bf_at_birth'),
            born=Sum('born_in_month'),
            weighed_and_born_in_month=Sum('weighed_and_born_in_month'),
            ebf=Sum('ebf_in_month'),
            ebf_eli=Sum('ebf_eligible'),
            cf_initiation=Sum('cf_initiation_in_month'),
            cf_initiation_eli=Sum('cf_initiation_eligible')
        )
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    def get_data_for_deliveries(date, filters):
        queryset = AggCcsRecordMonthly.objects.filter(
            month=date, **filters
        ).values(
            'aggregation_level'
        ).annotate(
            institutional_delivery=Sum('institutional_delivery_in_month'),
            delivered=Sum('delivered_in_month')
        )
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    current_month = datetime(*config['month'])
    previous_month = datetime(*config['prev_month'])
    del config['month']
    del config['prev_month']

    this_month_data = get_data_for_child_health_monthly(current_month, config)
    prev_month_data = get_data_for_child_health_monthly(previous_month, config)

    deliveries_this_month = get_data_for_deliveries(current_month, config)
    deliveries_prev_month = get_data_for_deliveries(previous_month, config)

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )

    return {
        'records': [
            [
                {
                    'label': _('Underweight (Weight-for-Age)'),
                    'help_text': _((
                        "Of the total children enrolled for Anganwadi services and weighed, the percentage "
                        "of children between 0-5 years who were moderately/severely underweight in the current "
                        "month. Children who are moderately or severely underweight have a higher risk "
                        "of mortality. "
                    )),
                    'percent': percent_diff(
                        'underweight',
                        this_month_data,
                        prev_month_data,
                        'valid'
                    ),
                    'color': 'red' if percent_diff(
                        'underweight',
                        this_month_data,
                        prev_month_data,
                        'valid'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'underweight'),
                    'all': get_value(this_month_data, 'valid'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'underweight_children'
                },
                {
                    'label': _('Wasting (Weight-for-Height)'),
                    'help_text': _(wasting_help_text(age_label)),
                    'percent': percent_diff(
                        'wasting',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_height_measured_in_month'
                    ),
                    'color': 'red' if percent_diff(
                        'wasting',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_height_measured_in_month'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'wasting'),
                    'all': get_value(this_month_data, 'weighed_and_height_measured_in_month'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'wasting'
                }
            ],
            [
                {
                    'label': _('Stunting (Height-for-Age)'),
                    'help_text': _(stunting_help_text(age_label)),
                    'percent': percent_diff(
                        'stunting',
                        this_month_data,
                        prev_month_data,
                        'height_measured_in_month'
                    ),
                    'color': 'red' if percent_diff(
                        'stunting',
                        this_month_data,
                        prev_month_data,
                        'height_measured_in_month'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'stunting'),
                    'all': get_value(this_month_data, 'height_measured_in_month'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'stunting'
                },
                {
                    'label': _('Newborns with Low Birth Weight'),
                    'help_text': _((
                        "Of all the children born in the current month and enrolled for Anganwadi services, "
                        "the percentage that had a birth weight less than 2500 grams. Newborns with Low Birth "
                        "Weight are closely associated wtih foetal and neonatal mortality and morbidity, "
                        "inhibited growth and cognitive development, and chronic diseases later in life. ")),
                    'percent': percent_diff(
                        'low_birth_weight',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_born_in_month'
                    ),
                    'color': 'red' if percent_diff(
                        'low_birth_weight',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_born_in_month'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'low_birth_weight'),
                    'all': get_value(this_month_data, 'weighed_and_born_in_month'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'low_birth'
                }
            ],
            [
                {
                    'label': _('Early Initiation of Breastfeeding'),
                    'help_text': _((
                        "Of the children born in the last month and enrolled for Anganwadi services, "
                        "the percentage whose breastfeeding was initiated within 1 hour of delivery. "
                        "Early initiation of breastfeeding ensure the newborn recieves the \"first milk\" "
                        "rich in nutrients and encourages exclusive breastfeeding practice")
                    ),
                    'percent': percent_diff(
                        'bf_birth',
                        this_month_data,
                        prev_month_data,
                        'born'
                    ),
                    'color': 'green' if percent_diff(
                        'bf_birth',
                        this_month_data,
                        prev_month_data,
                        'born'
                    ) > 0 else 'red',
                    'value': get_value(this_month_data, 'bf_birth'),
                    'all': get_value(this_month_data, 'born'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'early_initiation'
                },
                {
                    'label': _('Exclusive Breastfeeding'),
                    'help_text': _((
                        "Of the total children enrolled for Anganwadi services between the ages of 0 to 6 months, "
                        "the percentage that was exclusively fed with breast milk. An infant is exclusively "
                        "breastfed if they receive only breastmilk with no additional food or liquids "
                        "(even water), ensuring optimal nutrition and growth between 0 - 6 months")
                    ),
                    'percent': percent_diff(
                        'ebf',
                        this_month_data,
                        prev_month_data,
                        'ebf_eli'
                    ),
                    'color': 'green' if percent_diff(
                        'ebf',
                        this_month_data,
                        prev_month_data,
                        'ebf_eli'
                    ) > 0 else 'red',
                    'value': get_value(this_month_data, 'ebf'),
                    'all': get_value(this_month_data, 'ebf_eli'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'exclusive_breastfeeding'
                }
            ],
            [
                {
                    'label': _('Children initiated appropriate Complementary Feeding'),
                    'help_text': _((
                        "Of the total children enrolled for Anganwadi services between the ages of 6 to 8 months, "
                        "the percentage that was given a timely introduction to solid, semi-solid or soft food. "
                        "Timely intiation of complementary feeding in addition to breastmilk at 6 months of age "
                        "is a key feeding practice to reduce malnutrition")
                    ),
                    'percent': percent_diff(
                        'cf_initiation',
                        this_month_data,
                        prev_month_data,
                        'cf_initiation_eli'
                    ),
                    'color': 'green' if percent_diff(
                        'cf_initiation',
                        this_month_data,
                        prev_month_data,
                        'cf_initiation_eli'
                    ) > 0 else 'red',
                    'value': get_value(this_month_data, 'cf_initiation'),
                    'all': get_value(this_month_data, 'cf_initiation_eli'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'children_initiated'
                },
                {
                    'label': _('Institutional Deliveries'),
                    'help_text': _((
                        "Of the total number of women enrolled for Anganwadi services who gave birth in the last "
                        "month, the percentage who delivered in a public or private medical facility. Delivery "
                        "in medical instituitions is associated with a decrease in maternal mortality rate")
                    ),
                    'percent': percent_diff(
                        'institutional_delivery',
                        deliveries_this_month,
                        deliveries_prev_month,
                        'delivered'
                    ),
                    'color': 'green' if percent_diff(
                        'institutional_delivery',
                        deliveries_this_month,
                        deliveries_prev_month,
                        'delivered'
                    ) > 0 else 'red',
                    'value': get_value(deliveries_this_month, 'institutional_delivery'),
                    'all': get_value(deliveries_this_month, 'delivered'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'institutional_deliveries'
                }
            ]
        ]
    }
コード例 #14
0
def get_prevalence_of_stunting_sector_data(domain,
                                           config,
                                           loc_level,
                                           location_id,
                                           show_test=False,
                                           icds_feature_flag=False):
    group_by = ['%s_name' % loc_level]

    config['month'] = datetime(*config['month'])
    data = AggChildHealthMonthly.objects.filter(**config).values(
        *group_by).annotate(
            moderate=Sum(stunting_moderate_column(icds_feature_flag)),
            severe=Sum(stunting_severe_column(icds_feature_flag)),
            normal=Sum(stunting_normal_column(icds_feature_flag)),
            total=Sum('height_eligible'),
            total_measured=Sum('height_measured_in_month'),
        ).order_by('%s_name' % loc_level)

    if not show_test:
        data = apply_exclude(domain, data)
    if 'age_tranche' not in config:
        if icds_feature_flag:
            data = data.exclude(age_tranche=72)
        else:
            data = data.exclude(age_tranche__in=[0, 6, 72])

    chart_data = {
        'blue': [],
    }

    tooltips_data = defaultdict(lambda: {
        'severe': 0,
        'moderate': 0,
        'total': 0,
        'normal': 0,
        'total_measured': 0
    })

    loc_children = get_child_locations(domain, location_id, show_test)
    result_set = set()

    for row in data:
        total = row['total'] or 0
        name = row['%s_name' % loc_level]
        result_set.add(name)

        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        row_values = {
            'severe': severe,
            'moderate': moderate,
            'total': total,
            'normal': normal,
            'total_measured': total_measured,
        }

        for prop, value in six.iteritems(row_values):
            tooltips_data[name][prop] += value

        value = (moderate + severe) / float(total_measured or 1)
        chart_data['blue'].append([name, value])

    for sql_location in loc_children:
        if sql_location.name not in result_set:
            chart_data['blue'].append([sql_location.name, 0])

    chart_data['blue'] = sorted(chart_data['blue'])

    __, __, chosen_filters = chosen_filters_to_labels(
        config, default_interval=default_age_interval(icds_feature_flag))

    return {
        "tooltips_data":
        dict(tooltips_data),
        "info":
        _(("Percentage of children{} enrolled for Anganwadi Services with height-for-age below "
           "-2Z standard deviations of the WHO Child Growth Standards median."
           "<br/><br/>"
           "Stunting is a sign of chronic undernutrition and has long lasting harmful "
           "consequences on the growth of a child".format(chosen_filters))),
        "chart_data": [
            {
                "values": chart_data['blue'],
                "key": "",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": MapColors.BLUE
            },
        ]
    }
コード例 #15
0
def get_prevalence_of_severe_data_map(domain, config, loc_level, show_test=False, icds_feature_flag=False):

    def get_data_for(filters):
        filters['month'] = datetime(*filters['month'])
        queryset = AggChildHealthMonthly.objects.filter(
            **filters
        ).values(
            '%s_name' % loc_level, '%s_map_location_name' % loc_level
        ).annotate(
            moderate=Sum(wasting_moderate_column(icds_feature_flag)),
            severe=Sum(wasting_severe_column(icds_feature_flag)),
            normal=Sum(wasting_normal_column(icds_feature_flag)),
            total_height_eligible=Sum('height_eligible'),
            total_weighed=Sum('nutrition_status_weighed'),
            total_measured=Sum(wfh_recorded_in_month_column(icds_feature_flag)),
        ).order_by('%s_name' % loc_level, '%s_map_location_name' % loc_level)

        if not show_test:
            queryset = apply_exclude(domain, queryset)
        if 'age_tranche' not in config:
            queryset = queryset.exclude(age_tranche=72)
        return queryset

    data_for_map = defaultdict(lambda: {
        'moderate': 0,
        'severe': 0,
        'normal': 0,
        'total_weighed': 0,
        'total_measured': 0,
        'total_height_eligible': 0,
        'original_name': []
    })

    severe_for_all_locations = 0
    moderate_for_all_locations = 0
    normal_for_all_locations = 0
    weighed_for_all_locations = 0
    measured_for_all_locations = 0
    height_eligible_for_all_locations = 0

    values_to_calculate_average = {'numerator': 0, 'denominator': 0}
    for row in get_data_for(config):
        total_weighed = row['total_weighed'] or 0
        total_height_eligible = row['total_height_eligible'] or 0
        name = row['%s_name' % loc_level]
        on_map_name = row['%s_map_location_name' % loc_level] or name
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0
        total_measured = row['total_measured'] or 0

        values_to_calculate_average['numerator'] += moderate if moderate else 0
        values_to_calculate_average['numerator'] += severe if severe else 0
        values_to_calculate_average['denominator'] += total_measured if total_measured else 0

        severe_for_all_locations += severe
        moderate_for_all_locations += moderate
        normal_for_all_locations += normal
        weighed_for_all_locations += total_weighed
        measured_for_all_locations += total_measured
        height_eligible_for_all_locations += total_height_eligible

        data_for_map[on_map_name]['severe'] += severe
        data_for_map[on_map_name]['moderate'] += moderate
        data_for_map[on_map_name]['normal'] += normal
        data_for_map[on_map_name]['total_weighed'] += total_weighed
        data_for_map[on_map_name]['total_measured'] += total_measured
        data_for_map[on_map_name]['total_height_eligible'] += total_height_eligible
        data_for_map[on_map_name]['original_name'].append(name)

    for data_for_location in six.itervalues(data_for_map):
        numerator = data_for_location['moderate'] + data_for_location['severe']
        value = numerator * 100 / (data_for_location['total_measured'] or 1)
        if value < 5:
            data_for_location.update({'fillKey': '0%-5%'})
        elif 5 <= value <= 7:
            data_for_location.update({'fillKey': '5%-7%'})
        elif value > 7:
            data_for_location.update({'fillKey': '7%-100%'})

    fills = OrderedDict()
    fills.update({'0%-5%': MapColors.PINK})
    fills.update({'5%-7%': MapColors.ORANGE})
    fills.update({'7%-100%': MapColors.RED})
    fills.update({'defaultFill': MapColors.GREY})

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )

    average = (
        (values_to_calculate_average['numerator'] * 100) /
        float(values_to_calculate_average['denominator'] or 1)
    )

    return {
        "slug": "severe",
        "label": "Percent of Children{gender} Wasted ({age})".format(
            gender=gender_label,
            age=age_label
        ),
        "fills": fills,
        "rightLegend": {
            "average": "%.2f" % average,
            "info": wasting_help_text(age_label),
            "extended_info": [
                {
                    'indicator': 'Total Children{} weighed in given month:'.format(chosen_filters),
                    'value': indian_formatted_number(weighed_for_all_locations)
                },
                {
                    'indicator': 'Total Children{} with height measured in given month:'
                    .format(chosen_filters),
                    'value': indian_formatted_number(measured_for_all_locations)
                },
                {
                    'indicator': 'Number of children{} unmeasured:'.format(chosen_filters),
                    'value': indian_formatted_number(height_eligible_for_all_locations - weighed_for_all_locations)
                },
                {
                    'indicator': '% Severely Acute Malnutrition{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (severe_for_all_locations * 100 / float(measured_for_all_locations or 1))
                },
                {
                    'indicator': '% Moderately Acute Malnutrition{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (moderate_for_all_locations * 100 / float(measured_for_all_locations or 1))
                },
                {
                    'indicator': '% Normal{}:'.format(chosen_filters),
                    'value': '%.2f%%' % (normal_for_all_locations * 100 / float(measured_for_all_locations or 1))
                }
            ]
        },
        "data": dict(data_for_map),
    }
コード例 #16
0
 def new_table_config(self):
     return [{
         'category':
         'maternal_and_child_nutrition',
         'title':
         'Maternal and Child Nutrition',
         'sections': [{
             'section_title':
             'Nutrition Status of Children',
             'slug':
             'nutrition_status_of_children',
             'order':
             1,
             'rows_config': [{
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header': 'Weighing Efficiency (Children <5 weighed)',
                 'slug': 'status_weighed',
                 'average': [],
                 'format': 'percent',
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header':
                 'Height measurement efficiency (Children <5 measured)',
                 'slug': 'status_height_efficiency',
                 'average': [],
                 'format': 'percent',
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header': 'Total number of unweighed children (0-5 Years)',
                 'slug': 'nutrition_status_unweighed',
                 'reverseColors': True,
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header': 'Children from 0 - 5 years who are '
                 'severely underweight (weight-for-age)',
                 'slug': 'severely_underweight',
                 'average': [],
                 'format': 'percent',
                 'reverseColors': True,
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header': 'Children from 0-5 years who '
                 'are moderately underweight (weight-for-age)',
                 'slug': 'moderately_underweight',
                 'average': [],
                 'format': 'percent',
                 'reverseColors': True,
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header':
                 'Children from 0-5 years who are at normal weight-for-age',
                 'slug': 'status_normal',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header': ('Children from {} with severe acute '
                            'malnutrition (weight-for-height)'.format(
                                default_age_interval(self.beta))),
                 'slug':
                 'wasting_severe',
                 'average': [],
                 'format':
                 'percent',
                 'reverseColors':
                 True,
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header': ('Children from {} with moderate acute '
                            'malnutrition (weight-for-height)'.format(
                                default_age_interval(self.beta))),
                 'slug':
                 'wasting_moderate',
                 'average': [],
                 'format':
                 'percent',
                 'reverseColors':
                 True,
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header': ('Children from {} with normal '
                            'weight-for-height'.format(
                                default_age_interval(self.beta))),
                 'slug':
                 'wasting_normal',
                 'average': [],
                 'format':
                 'percent'
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header': ('Children from {} with severe stunting '
                            '(height-for-age)'.format(
                                default_age_interval(self.beta))),
                 'slug':
                 'stunting_severe',
                 'average': [],
                 'format':
                 'percent',
                 'reverseColors':
                 True,
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header': ('Children from {} with moderate stunting '
                            '(height-for-age)'.format(
                                default_age_interval(self.beta))),
                 'slug':
                 'stunting_moderate',
                 'average': [],
                 'format':
                 'percent',
                 'reverseColors':
                 True,
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header':
                 ('Children from {} with normal '
                  'height-for-age'.format(default_age_interval(self.beta))),
                 'slug':
                 'stunting_normal',
                 'average': [],
                 'format':
                 'percent'
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header':
                 'Percent of children born in month with low birth weight',
                 'slug': 'low_birth_weight',
                 'average': [],
                 'format': 'percent',
                 'reverseColors': True,
             }]
         }]
     }, {
         'category':
         'interventions',
         'title':
         'Interventions',
         'sections': [
             {
                 'section_title':
                 'Nutrition Status of Children',
                 'slug':
                 'nutrition_status_of_children',
                 'order':
                 1,
                 'rows_config': [{
                     'data_source':
                     'AggChildHealthMonthlyDataSource',
                     'header':
                     'Children 1 year+ who have recieved complete '
                     'immunization required by age 1.',
                     'slug':
                     'fully_immunized',
                     'average': [],
                     'format':
                     'percent'
                 }]
             },
             {
                 'section_title':
                 'Nutrition Status of Pregnant Women',
                 'slug':
                 'nutrition_status_of_pregnant_women',
                 'order':
                 3,
                 'rows_config': [{
                     'data_source': 'AggCCSRecordMonthlyDataSource',
                     'header': 'Pregnant women who are anemic',
                     'slug': 'severe_anemic',
                     'average': [],
                     'format': 'percent',
                     'reverseColors': True
                 }, {
                     'data_source': 'AggCCSRecordMonthlyDataSource',
                     'header': 'Pregnant women with tetanus completed',
                     'slug': 'tetanus_complete',
                     'average': [],
                     'format': 'percent'
                 }, {
                     'data_source': 'AggCCSRecordMonthlyDataSource',
                     'header':
                     'Pregnant women who had at least 1 ANC visit by delivery',
                     'slug': 'anc_1',
                     'average': [],
                     'format': 'percent'
                 }, {
                     'data_source': 'AggCCSRecordMonthlyDataSource',
                     'header':
                     'Pregnant women who had at least 2 ANC visits by delivery',
                     'slug': 'anc_2',
                     'average': [],
                     'format': 'percent'
                 }, {
                     'data_source': 'AggCCSRecordMonthlyDataSource',
                     'header':
                     'Pregnant women who had at least 3 ANC visits by delivery',
                     'slug': 'anc_3',
                     'average': [],
                     'format': 'percent'
                 }, {
                     'data_source': 'AggCCSRecordMonthlyDataSource',
                     'header':
                     'Pregnant women who had at least 4 ANC visits by delivery',
                     'slug': 'anc_4',
                     'average': [],
                     'format': 'percent'
                 }]
             },
             {
                 'section_title':
                 'AWC Infrastructure',
                 'slug':
                 'awc_infrastructure',
                 'order':
                 5,
                 'rows_config': [{
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'AWCs reported medicine kit',
                     'slug': 'medicine_kits',
                     'average': [],
                     'format': 'percent'
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'AWCs reported weighing scale for infants',
                     'slug': 'baby_weighing_scale',
                     'average': [],
                     'format': 'percent'
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header':
                     'AWCs reported weighing scale for mother and child',
                     'slug': 'adult_weighing_scale',
                     'average': [],
                     'format': 'percent'
                 }]
             },
         ]
     }, {
         'category':
         'behavior_change',
         'title':
         'Behavior Change',
         'sections': [{
             'section_title':
             'Child Feeding Indicators',
             'slug':
             'child_feeding_indicators',
             'order':
             2,
             'rows_config': [{
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header':
                 ('Percentage of children who were put to the breast within one hour of birth.'
                  ),
                 'slug':
                 'breastfed_at_birth',
                 'average': [],
                 'format':
                 'percent'
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header': 'Infants 0-6 months of age who '
                 'are fed exclusively with breast milk.',
                 'slug': 'exclusively_breastfed',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source':
                 'AggChildHealthMonthlyDataSource',
                 'header':
                 ("Children between 6 - 8 months given timely introduction to solid, "
                  "semi-solid or soft food."),
                 'slug':
                 'cf_initiation',
                 'average': [],
                 'format':
                 'percent'
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header':
                 'Children from 6 - 24 months complementary feeding',
                 'slug': 'complementary_feeding',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header':
                 'Children from 6 - 24 months consuming at least 4 food groups',
                 'slug': 'diet_diversity',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header':
                 'Children from 6 - 24 months consuming adequate food',
                 'slug': 'diet_quantity',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source': 'AggChildHealthMonthlyDataSource',
                 'header': 'Children from 6 - 24 months '
                 'whose mothers handwash before feeding',
                 'slug': 'handwashing',
                 'average': [],
                 'format': 'percent'
             }]
         }, {
             'section_title':
             'Nutrition Status of Pregnant Women',
             'slug':
             'nutrition_status_of_pregnant_women',
             'order':
             3,
             "rows_config": [{
                 'data_source': 'AggCCSRecordMonthlyDataSource',
                 'header': 'Women resting during pregnancy',
                 'slug': 'resting',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source': 'AggCCSRecordMonthlyDataSource',
                 'header': 'Women eating an extra meal during pregnancy',
                 'slug': 'extra_meal',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source':
                 'AggCCSRecordMonthlyDataSource',
                 'header': ("Pregnant women in 3rd trimester counselled "
                            "on immediate and exclusive "
                            "breastfeeding during home visit"),
                 'slug':
                 'trimester',
                 'average': [],
                 'format':
                 'percent'
             }]
         }]
     }, {
         'category':
         'water_sanitation_and_hygiene',
         'title':
         'Water Sanitation And Hygiene',
         "sections": [{
             'section_title':
             'AWC Infrastructure',
             'slug':
             'awc_infrastructure',
             'order':
             5,
             'rows_config': [{
                 'data_source': 'AggAWCMonthlyDataSource',
                 'header': 'AWCs reported clean drinking water',
                 'slug': 'clean_water',
                 'average': [],
                 'format': 'percent'
             }, {
                 'data_source': 'AggAWCMonthlyDataSource',
                 'header': 'AWCs reported functional toilet',
                 'slug': 'functional_toilet',
                 'average': [],
                 'format': 'percent'
             }]
         }]
     }, {
         'category':
         'demographics',
         'title':
         'Demographics',
         'sections': [
             {
                 'section_title':
                 'Demographics',
                 'slug':
                 'demographics',
                 'order':
                 4,
                 'rows_config': [{
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Number of Households',
                     'slug': 'cases_household',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Total Number of Household Members',
                     'slug': 'cases_person_all',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Total number of members enrolled at AWC',
                     'slug': self.person_is_beneficiary_column,
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Percent Aadhaar-seeded beneficiaries',
                     'slug': 'aadhar',
                     'format': 'percent',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Total pregnant women ',
                     'slug': 'cases_ccs_pregnant_all',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header':
                     'Total pregnant women enrolled for services at AWC',
                     'slug': 'cases_ccs_pregnant',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Total lactating women',
                     'slug': 'cases_ccs_lactating_all',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header':
                     'Total lactating women registered for services at AWC',
                     'slug': 'cases_ccs_lactating',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Total children (0-6 years)',
                     'slug': 'cases_child_health_all',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header':
                     'Total chldren (0-6 years) enrolled for Anganwadi Services',
                     'slug': 'cases_child_health',
                     'average': [],
                 }, {
                     'data_source': 'AggChildHealthMonthlyDataSource',
                     'header':
                     'Children (0-28 days)  enrolled for Anganwadi Services',
                     'slug': 'zero',
                     'average': [],
                 }, {
                     'data_source': 'AggChildHealthMonthlyDataSource',
                     'header':
                     'Children (28 days - 6 months)  enrolled for Anganwadi Services',
                     'slug': 'one',
                     'average': [],
                 }, {
                     'data_source': 'AggChildHealthMonthlyDataSource',
                     'header':
                     'Children (6 months - 1 year)  enrolled for Anganwadi Services',
                     'slug': 'two',
                     'average': [],
                 }, {
                     'data_source': 'AggChildHealthMonthlyDataSource',
                     'header':
                     'Children (1 year - 3 years)  enrolled for Anganwadi Services',
                     'slug': 'three',
                     'average': [],
                 }, {
                     'data_source': 'AggChildHealthMonthlyDataSource',
                     'header':
                     'Children (3 years - 6 years)  enrolled for Anganwadi Services',
                     'slug': 'four',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Adolescent girls (11-14 years)',
                     'slug': 'cases_person_adolescent_girls_11_14_all',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header': 'Adolescent girls (15-18 years)',
                     'slug': 'cases_person_adolescent_girls_15_18_all',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header':
                     'Adolescent girls (11-14 years)  enrolled for Anganwadi Services',
                     'slug': 'cases_person_adolescent_girls_11_14',
                     'average': [],
                 }, {
                     'data_source': 'AggAWCMonthlyDataSource',
                     'header':
                     'Adolescent girls (15-18 years)  enrolled for Anganwadi Services',
                     'slug': 'cases_person_adolescent_girls_15_18',
                     'average': [],
                 }]
             },
         ]
     }]
コード例 #17
0
ファイル: maternal_child.py プロジェクト: kkrampa/commcare-hq
def get_maternal_child_data(domain, config, show_test=False, icds_feature_flag=False):

    def get_data_for_child_health_monthly(date, filters):

        age_filters = {'age_tranche': 72} if icds_feature_flag else {'age_tranche__in': [0, 6, 72]}

        moderately_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72},
            'nutrition_status_moderately_underweight'
        )
        severely_underweight = exclude_records_by_age_for_column(
            {'age_tranche': 72},
            'nutrition_status_severely_underweight'
        )
        wasting_moderate = exclude_records_by_age_for_column(
            age_filters,
            wasting_moderate_column(icds_feature_flag)
        )
        wasting_severe = exclude_records_by_age_for_column(
            age_filters,
            wasting_severe_column(icds_feature_flag)
        )
        stunting_moderate = exclude_records_by_age_for_column(
            age_filters,
            stunting_moderate_column(icds_feature_flag)
        )
        stunting_severe = exclude_records_by_age_for_column(
            age_filters,
            stunting_severe_column(icds_feature_flag)
        )
        nutrition_status_weighed = exclude_records_by_age_for_column(
            {'age_tranche': 72},
            'nutrition_status_weighed'
        )
        height_measured_in_month = exclude_records_by_age_for_column(
            age_filters,
            hfa_recorded_in_month_column(icds_feature_flag)
        )
        weighed_and_height_measured_in_month = exclude_records_by_age_for_column(
            age_filters,
            wfh_recorded_in_month_column(icds_feature_flag)
        )

        queryset = AggChildHealthMonthly.objects.filter(
            month=date, **filters
        ).values(
            'aggregation_level'
        ).annotate(
            underweight=(
                Sum(moderately_underweight) + Sum(severely_underweight)
            ),
            valid=Sum(nutrition_status_weighed),
            wasting=Sum(wasting_moderate) + Sum(wasting_severe),
            stunting=Sum(stunting_moderate) + Sum(stunting_severe),
            height_measured_in_month=Sum(height_measured_in_month),
            weighed_and_height_measured_in_month=Sum(weighed_and_height_measured_in_month),
            low_birth_weight=Sum('low_birth_weight_in_month'),
            bf_birth=Sum('bf_at_birth'),
            born=Sum('born_in_month'),
            weighed_and_born_in_month=Sum('weighed_and_born_in_month'),
            ebf=Sum('ebf_in_month'),
            ebf_eli=Sum('ebf_eligible'),
            cf_initiation=Sum('cf_initiation_in_month'),
            cf_initiation_eli=Sum('cf_initiation_eligible')
        )
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    def get_data_for_deliveries(date, filters):
        queryset = AggCcsRecordMonthly.objects.filter(
            month=date, **filters
        ).values(
            'aggregation_level'
        ).annotate(
            institutional_delivery=Sum('institutional_delivery_in_month'),
            delivered=Sum('delivered_in_month')
        )
        if not show_test:
            queryset = apply_exclude(domain, queryset)
        return queryset

    current_month = datetime(*config['month'])
    previous_month = datetime(*config['prev_month'])
    del config['month']
    del config['prev_month']

    this_month_data = get_data_for_child_health_monthly(current_month, config)
    prev_month_data = get_data_for_child_health_monthly(previous_month, config)

    deliveries_this_month = get_data_for_deliveries(current_month, config)
    deliveries_prev_month = get_data_for_deliveries(previous_month, config)

    gender_label, age_label, chosen_filters = chosen_filters_to_labels(
        config,
        default_interval=default_age_interval(icds_feature_flag)
    )

    return {
        'records': [
            [
                {
                    'label': _('Underweight (Weight-for-Age)'),
                    'help_text': underweight_children_help_text(),
                    'percent': percent_diff(
                        'underweight',
                        this_month_data,
                        prev_month_data,
                        'valid'
                    ),
                    'color': 'red' if percent_diff(
                        'underweight',
                        this_month_data,
                        prev_month_data,
                        'valid'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'underweight'),
                    'all': get_value(this_month_data, 'valid'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/underweight_children'
                },
                {
                    'label': _('Wasting (Weight-for-Height)'),
                    'help_text': _(wasting_help_text(age_label)),
                    'percent': percent_diff(
                        'wasting',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_height_measured_in_month'
                    ),
                    'color': 'red' if percent_diff(
                        'wasting',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_height_measured_in_month'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'wasting'),
                    'all': get_value(this_month_data, 'weighed_and_height_measured_in_month'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/wasting'
                }
            ],
            [
                {
                    'label': _('Stunting (Height-for-Age)'),
                    'help_text': _(stunting_help_text(age_label)),
                    'percent': percent_diff(
                        'stunting',
                        this_month_data,
                        prev_month_data,
                        'height_measured_in_month'
                    ),
                    'color': 'red' if percent_diff(
                        'stunting',
                        this_month_data,
                        prev_month_data,
                        'height_measured_in_month'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'stunting'),
                    'all': get_value(this_month_data, 'height_measured_in_month'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/stunting'
                },
                {
                    'label': _('Newborns with Low Birth Weight'),
                    'help_text': _((
                        new_born_with_low_weight_help_text(html=False)
                    )),
                    'percent': percent_diff(
                        'low_birth_weight',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_born_in_month'
                    ),
                    'color': 'red' if percent_diff(
                        'low_birth_weight',
                        this_month_data,
                        prev_month_data,
                        'weighed_and_born_in_month'
                    ) > 0 else 'green',
                    'value': get_value(this_month_data, 'low_birth_weight'),
                    'all': get_value(this_month_data, 'weighed_and_born_in_month'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/low_birth'
                }
            ],
            [
                {
                    'label': _('Early Initiation of Breastfeeding'),
                    'help_text': early_initiation_breastfeeding_help_text(),
                    'percent': percent_diff(
                        'bf_birth',
                        this_month_data,
                        prev_month_data,
                        'born'
                    ),
                    'color': 'green' if percent_diff(
                        'bf_birth',
                        this_month_data,
                        prev_month_data,
                        'born'
                    ) > 0 else 'red',
                    'value': get_value(this_month_data, 'bf_birth'),
                    'all': get_value(this_month_data, 'born'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/early_initiation'
                },
                {
                    'label': _('Exclusive Breastfeeding'),
                    'help_text': exclusive_breastfeeding_help_text(),
                    'percent': percent_diff(
                        'ebf',
                        this_month_data,
                        prev_month_data,
                        'ebf_eli'
                    ),
                    'color': 'green' if percent_diff(
                        'ebf',
                        this_month_data,
                        prev_month_data,
                        'ebf_eli'
                    ) > 0 else 'red',
                    'value': get_value(this_month_data, 'ebf'),
                    'all': get_value(this_month_data, 'ebf_eli'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/exclusive_breastfeeding'
                }
            ],
            [
                {
                    'label': _('Children initiated appropriate Complementary Feeding'),
                    'help_text': children_initiated_appropriate_complementary_feeding_help_text(),
                    'percent': percent_diff(
                        'cf_initiation',
                        this_month_data,
                        prev_month_data,
                        'cf_initiation_eli'
                    ),
                    'color': 'green' if percent_diff(
                        'cf_initiation',
                        this_month_data,
                        prev_month_data,
                        'cf_initiation_eli'
                    ) > 0 else 'red',
                    'value': get_value(this_month_data, 'cf_initiation'),
                    'all': get_value(this_month_data, 'cf_initiation_eli'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/children_initiated'
                },
                {
                    'label': _('Institutional Deliveries'),
                    'help_text': institutional_deliveries_help_text(),
                    'percent': percent_diff(
                        'institutional_delivery',
                        deliveries_this_month,
                        deliveries_prev_month,
                        'delivered'
                    ),
                    'color': 'green' if percent_diff(
                        'institutional_delivery',
                        deliveries_this_month,
                        deliveries_prev_month,
                        'delivered'
                    ) > 0 else 'red',
                    'value': get_value(deliveries_this_month, 'institutional_delivery'),
                    'all': get_value(deliveries_this_month, 'delivered'),
                    'format': 'percent_and_div',
                    'frequency': 'month',
                    'redirect': 'maternal_and_child/institutional_deliveries'
                }
            ]
        ]
    }