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
Exemple #2
0
 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
 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
 def agg_child_health_monthly(self):
     data = AggChildHealthMonthly.objects.filter(
         awc_id__in=self.config['awc_id'],
         aggregation_level=AWC_LOCATION_LEVEL,
         month=self.config['month']
     ).values('awc_id').annotate(
         boys_normal_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, 'nutrition_status_normal')),
         girls_normal_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, 'nutrition_status_normal')),
         boys_normal_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, 'nutrition_status_normal')),
         girls_normal_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, 'nutrition_status_normal')),
         boys_moderately_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, 'nutrition_status_moderately_underweight')),
         girls_moderately_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, 'nutrition_status_moderately_underweight')),
         boys_moderately_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, 'nutrition_status_moderately_underweight')),
         girls_moderately_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, 'nutrition_status_moderately_underweight')),
         boys_severely_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, 'nutrition_status_severely_underweight')),
         girls_severely_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, 'nutrition_status_severely_underweight')),
         boys_severely_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, 'nutrition_status_severely_underweight')),
         girls_severely_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, 'nutrition_status_severely_underweight')),
         boys_stunted_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, stunting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, stunting_severe_column(self.icds_feature_flag))),
         girls_stunted_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, stunting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, stunting_severe_column(self.icds_feature_flag))),
         boys_stunted_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, stunting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, stunting_severe_column(self.icds_feature_flag))),
         girls_stunted_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, stunting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, stunting_severe_column(self.icds_feature_flag))),
         boys_wasted_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, wasting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'M'
         }, wasting_severe_column(self.icds_feature_flag))),
         girls_wasted_0_3=Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, wasting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['0', '6', '12', '24', '36'],
             'gender': 'F'
         }, wasting_severe_column(self.icds_feature_flag))),
         boys_wasted_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, wasting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'M'
         }, wasting_severe_column(self.icds_feature_flag))),
         girls_wasted_3_5=Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, wasting_moderate_column(self.icds_feature_flag))) + Sum(self.filter_by({
             'age_tranche__in': ['48', '60'],
             'gender': 'F'
         }, wasting_severe_column(self.icds_feature_flag))),
         sc_boys_6_36=Sum(self.filter_by({
             'caste': 'sc',
             'gender': 'M',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         sc_girls_6_36=Sum(self.filter_by({
             'caste': 'sc',
             'gender': 'F',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         st_boys_6_36=Sum(self.filter_by({
             'caste': 'st',
             'gender': 'M',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         st_girls_6_36=Sum(self.filter_by({
             'caste': 'st',
             'gender': 'F',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         obc_boys_6_36=Sum(self.filter_by({
             'caste': 'obc',
             'gender': 'M',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         obc_girls_6_36=Sum(self.filter_by({
             'caste': 'obc',
             'gender': 'F',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         general_boys_6_36=Sum(self.filter_by({
             'caste': 'other',
             'gender': 'M',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         general_girls_6_36=Sum(self.filter_by({
             'caste': 'other',
             'gender': 'F',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         total_boys_6_36=Sum(self.filter_by({
             'gender': 'M',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         total_girls_6_36=Sum(self.filter_by({
             'gender': 'F',
             'age_tranche__in': ['6', '12', '24', '36']
         }, 'rations_21_plus_distributed')),
         minority_boys_6_36_num=Sum(self.filter_by({
             'gender': 'M',
             'age_tranche__in': ['6', '12', '24', '36'],
             'minority': 'yes'
         }, 'rations_21_plus_distributed')),
         minority_girls_6_36_num=Sum(self.filter_by({
             'gender': 'F',
             'age_tranche__in': ['6', '12', '24', '36'],
             'minority': 'yes'
         }, 'rations_21_plus_distributed')),
     )
     return {row['awc_id']: row for row in data}
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
            },
        ]
    }
def get_prevalence_of_stunting_data_chart(domain,
                                          config,
                                          loc_level,
                                          show_test=False,
                                          icds_feature_flag=False):
    month = datetime(*config['month'])
    three_before = datetime(*config['month']) - relativedelta(months=3)

    config['month__range'] = (three_before, month)
    del config['month']

    chart_data = AggChildHealthMonthly.objects.filter(**config).values(
        'month', '%s_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'),
            measured=Sum('height_measured_in_month'),
        ).order_by('month')

    if not show_test:
        chart_data = apply_exclude(domain, chart_data)

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

    data = {
        'red': OrderedDict(),
        'orange': OrderedDict(),
        'peach': OrderedDict()
    }

    dates = [dt for dt in rrule(MONTHLY, dtstart=three_before, until=month)]

    for date in dates:
        miliseconds = int(date.strftime("%s")) * 1000
        data['red'][miliseconds] = {'y': 0, 'all': 0, 'measured': 0}
        data['orange'][miliseconds] = {'y': 0, 'all': 0, 'measured': 0}
        data['peach'][miliseconds] = {'y': 0, 'all': 0, 'measured': 0}

    best_worst = {}
    for row in chart_data:
        date = row['month']
        total = row['total'] or 0
        measured = row['measured'] or 0
        location = row['%s_name' % loc_level]
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0

        underweight = moderate + severe

        best_worst[location] = underweight * 100 / float(measured or 1)

        date_in_miliseconds = int(date.strftime("%s")) * 1000

        data['peach'][date_in_miliseconds]['y'] += normal
        data['peach'][date_in_miliseconds]['measured'] += measured
        data['peach'][date_in_miliseconds]['all'] += total
        data['orange'][date_in_miliseconds]['y'] += moderate
        data['orange'][date_in_miliseconds]['measured'] += measured
        data['orange'][date_in_miliseconds]['all'] += total
        data['red'][date_in_miliseconds]['y'] += severe
        data['red'][date_in_miliseconds]['measured'] += measured
        data['red'][date_in_miliseconds]['all'] += total

    top_locations = sorted([
        dict(loc_name=key, percent=value)
        for key, value in six.iteritems(best_worst)
    ],
                           key=lambda x: (x['percent'], x['loc_name']))

    return {
        "chart_data": [{
            "values": [{
                'x': key,
                'y': value['y'] / float(value['measured'] or 1),
                'all': value['all'],
                'measured': value['measured']
            } for key, value in six.iteritems(data['peach'])],
            "key":
            "% normal",
            "strokeWidth":
            2,
            "classed":
            "dashed",
            "color":
            ChartColors.PINK
        }, {
            "values": [{
                'x': key,
                'y': value['y'] / float(value['measured'] or 1),
                'all': value['all'],
                'measured': value['measured']
            } for key, value in six.iteritems(data['orange'])],
            "key":
            "% moderately stunted",
            "strokeWidth":
            2,
            "classed":
            "dashed",
            "color":
            ChartColors.ORANGE
        }, {
            "values": [{
                'x': key,
                'y': value['y'] / float(value['measured'] or 1),
                'all': value['all'],
                'measured': value['measured']
            } for key, value in six.iteritems(data['red'])],
            "key":
            "% severely stunted",
            "strokeWidth":
            2,
            "classed":
            "dashed",
            "color":
            ChartColors.RED
        }],
        "all_locations":
        top_locations,
        "top_five":
        top_locations[:5],
        "bottom_five":
        top_locations[-5:],
        "location_type":
        loc_level.title()
        if loc_level != LocationTypes.SUPERVISOR else 'Sector'
    }
 def get_columns(self, filters):
     return [
         DatabaseColumn('month', SimpleColumn('month')),
         AggregateColumn(
             '% Weighing efficiency (Children <5 weighed)',
             percent_num, [
                 SumColumn(
                     'nutrition_status_weighed',
                     filters=filters + [NOT(EQ('age_tranche', 'age_72'))]),
                 SumColumn(
                     'wer_eligible',
                     alias='wer_eligible',
                     filters=filters + [NOT(EQ('age_tranche', 'age_72'))])
             ],
             slug='status_weighed'),
         AggregateColumn(
             '% Height measurement efficiency (Children <5 measured)',
             percent_num, [
                 SumColumn(
                     'height_measured_in_month',
                     alias='height_measured_in_month_less_5',
                     filters=filters + [NOT(EQ('age_tranche', 'age_72'))]),
                 SumColumn(
                     'height_eligible',
                     alias='height_eligible',
                     filters=filters + [NOT(EQ('age_tranche', 'age_72'))])
             ],
             slug='status_height_efficiency'),
         DatabaseColumn(
             'Total number Unweighed',
             SumColumn('nutrition_status_unweighed',
                       filters=filters +
                       [NOT(EQ('age_tranche', 'age_72'))])),
         AggregateColumn(
             'Percent Children severely underweight (weight for age)',
             percent_num, [
                 SumColumn(
                     'nutrition_status_severely_underweight',
                     filters=filters + [NOT(EQ('age_tranche', 'age_72'))]),
                 AliasColumn('nutrition_status_weighed')
             ],
             slug='severely_underweight'),
         AggregateColumn(
             'Percent Children moderately underweight (weight for age)',
             percent_num, [
                 SumColumn(
                     'nutrition_status_moderately_underweight',
                     filters=filters + [NOT(EQ('age_tranche', 'age_72'))]),
                 AliasColumn('nutrition_status_weighed')
             ],
             slug='moderately_underweight'),
         AggregateColumn('Percent Children normal (weight for age)',
                         percent_num, [
                             SumColumn('nutrition_status_normal',
                                       filters=filters +
                                       [NOT(EQ('age_tranche', 'age_72'))]),
                             AliasColumn('nutrition_status_weighed')
                         ],
                         slug='status_normal'),
         AggregateColumn(
             'Percent children with severe acute malnutrition (weight-for-height)',
             percent_num, [
                 SumColumn(wasting_severe_column(self.beta),
                           filters=filters + get_age_filters(self.beta)),
                 SumColumn(wfh_recorded_in_month_column(self.beta),
                           alias='weighed_and_height_measured_in_month',
                           filters=filters + get_age_filters(self.beta))
             ],
             slug='wasting_severe'),
         AggregateColumn(
             'Percent children with moderate acute malnutrition (weight-for-height)',
             percent_num, [
                 SumColumn(wasting_moderate_column(self.beta),
                           filters=filters + get_age_filters(self.beta)),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='wasting_moderate'),
         AggregateColumn(
             'Percent children normal (weight-for-height)',
             percent_num, [
                 SumColumn(wasting_normal_column(self.beta),
                           filters=filters + get_age_filters(self.beta)),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='wasting_normal'),
         AggregateColumn(
             'Percent children with severe stunting (height for age)',
             percent_num, [
                 SumColumn(stunting_severe_column(self.beta),
                           filters=filters + get_age_filters(self.beta)),
                 SumColumn(hfa_recorded_in_month_column(self.beta),
                           alias='height_measured_in_month',
                           filters=filters + get_age_filters(self.beta))
             ],
             slug='stunting_severe'),
         AggregateColumn(
             'Percent children with moderate stunting (height for age)',
             percent_num, [
                 SumColumn(stunting_moderate_column(self.beta),
                           filters=filters + get_age_filters(self.beta)),
                 AliasColumn('height_measured_in_month')
             ],
             slug='stunting_moderate'),
         AggregateColumn(
             'Percent children with normal (height for age)',
             percent_num, [
                 SumColumn(stunting_normal_column(self.beta),
                           filters=filters + get_age_filters(self.beta)),
                 AliasColumn('height_measured_in_month')
             ],
             slug='stunting_normal'),
         AggregateColumn(
             'Percent children immunized with 1st year immunizations',
             lambda x, y, z: ((x or 0) + (y or 0)) * 100 / float(z or 1), [
                 SumColumn('fully_immunized_on_time'),
                 SumColumn('fully_immunized_late'),
                 SumColumn('fully_immunized_eligible')
             ],
             slug='fully_immunized'),
         AggregateColumn(
             'Percent Children breastfed at birth',
             percent_num,
             [SumColumn('bf_at_birth'),
              SumColumn('born_in_month')],
             slug='breastfed_at_birth'),
         AggregateColumn(
             'Percent Children exclusively breastfed',
             percent_num,
             [SumColumn('ebf_in_month'),
              SumColumn('ebf_eligible')],
             slug='exclusively_breastfed'),
         AggregateColumn(
             'Percent Children initiated appropriate complementary feeding',
             percent_num, [
                 SumColumn('cf_initiation_in_month'),
                 SumColumn('cf_initiation_eligible')
             ],
             slug='cf_initiation'),
         AggregateColumn(
             'Perecent children complementary feeding',
             percent_num,
             [SumColumn('cf_in_month'),
              SumColumn('cf_eligible')],
             slug='complementary_feeding'),
         AggregateColumn(
             'Percentage of children consuming atleast 4 food groups',
             percent_num,
             [SumColumn('cf_diet_diversity'),
              AliasColumn('cf_eligible')],
             slug='diet_diversity'),
         AggregateColumn(
             'Percentage of children consuming adequate food',
             percent_num,
             [SumColumn('cf_diet_quantity'),
              AliasColumn('cf_eligible')],
             slug='diet_quantity'),
         AggregateColumn(
             'Percentage of children whose mothers handwash before feeding',
             percent_num,
             [SumColumn('cf_handwashing'),
              AliasColumn('cf_eligible')],
             slug='handwashing'),
         DatabaseColumn('Children (0 - 28 Days) Seeking Services',
                        SumColumn('valid_in_month',
                                  filters=filters +
                                  [EQ('age_tranche', 'age_0')],
                                  alias='zero'),
                        slug='zero'),
         DatabaseColumn('Children (28 Days - 6 mo) Seeking Services',
                        SumColumn('valid_in_month',
                                  filters=filters +
                                  [EQ('age_tranche', 'age_6')],
                                  alias='one'),
                        slug='one'),
         DatabaseColumn('Children (6 mo - 1 year) Seeking Services',
                        SumColumn('valid_in_month',
                                  filters=filters +
                                  [EQ('age_tranche', 'age_12')],
                                  alias='two'),
                        slug='two'),
         DatabaseColumn('Children (1 year - 3 years) Seeking Services',
                        SumColumn('valid_in_month',
                                  filters=filters + [
                                      OR([
                                          EQ('age_tranche', 'age_24'),
                                          EQ('age_tranche', 'age_36')
                                      ])
                                  ],
                                  alias='three'),
                        slug='three'),
         DatabaseColumn('Children (3 years - 6 years) Seeking Services',
                        SumColumn('valid_in_month',
                                  filters=filters + [
                                      OR([
                                          EQ('age_tranche', 'age_48'),
                                          EQ('age_tranche', 'age_60'),
                                          EQ('age_tranche', 'age_72')
                                      ])
                                  ],
                                  alias='four'),
                        slug='four'),
         AggregateColumn(
             'Percent of children born in month with low birth weight',
             percent_num, [
                 SumColumn('low_birth_weight_in_month'),
                 SumColumn('weighed_and_born_in_month')
             ],
             slug='low_birth_weight')
     ]
Exemple #8
0
 def columns(self):
     columns = self.get_columns_by_loc_level
     agg_columns = [
         AggregateColumn(
             'Weighing efficiency (in month)',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_weighed'}, else_=0,
                     alias='nutrition_status_weighed'
                 ),
                 SumWhen(
                     whens={"age_tranche != :age_72": 'wer_eligible'}, else_=0,
                     alias='wer_eligible'
                 )
             ],
             slug='percent_weight_efficiency'
         ),
         AggregateColumn(
             'Height measurement efficiency (in month)',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'height_measured_in_month'}, else_=0,
                     alias='height_measured_in_month_efficiency'
                 ),
                 SumWhen(
                     whens={"age_tranche != :age_72": 'height_eligible'}, else_=0,
                     alias='height_eligible',
                 )
             ],
             slug='height_measurement'
         ),
         DatabaseColumn(
             'Total number of unweighed children (0-5 Years)',
             SumWhen(
                 whens={"age_tranche != :age_72": 'nutrition_status_unweighed'}, else_=0,
                 alias='nutrition_status_unweighed'
             ),
             slug='total_number_unweighed'
         ),
         AggregateColumn(
             'Percentage of severely underweight children',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_severely_underweight'}, else_=0,
                     alias='nutrition_status_severely_underweight'
                 ),
                 AliasColumn('nutrition_status_weighed'),
             ],
             slug='percent_severe_underweight'
         ),
         AggregateColumn(
             'Percentage of moderately underweight children',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_moderately_underweight'}, else_=0,
                     alias='nutrition_status_moderately_underweight'
                 ),
                 AliasColumn('nutrition_status_weighed'),
             ],
             slug='percent_moderate_underweight'
         ),
         AggregateColumn(
             'Percentage of normal weight-for-age children',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_normal'}, else_=0,
                     alias='nutrition_status_normal'
                 ),
                 AliasColumn('nutrition_status_weighed'),
             ],
             slug='percent_normal_weight'
         ),
         AggregateColumn(
             'Percentage of children with severe wasting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_severe_column(self.beta)},
                     alias='wasting_severe'
                 ),
                 SumWhen(
                     whens={get_age_condition(self.beta): wfh_recorded_in_month_column(self.beta)},
                     alias='weighed_and_height_measured_in_month'
                 ),
             ],
             slug='percent_severe_wasting'
         ),
         AggregateColumn(
             'Percentage of children with moderate wasting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_moderate_column(self.beta)},
                     alias='wasting_moderate'
                 ),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='percent_moderate_wasting'
         ),
         AggregateColumn(
             'Percentage of children with normal weight-for-height',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_normal_column(self.beta)},
                     alias='wasting_normal'
                 ),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='percent_normal_wasting'
         ),
         AggregateColumn(
             'Percentage of children with severe stunting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_severe_column(self.beta)},
                     alias='stunting_severe'
                 ),
                 SumWhen(
                     whens={get_age_condition(self.beta): hfa_recorded_in_month_column(self.beta)},
                     alias='height_measured_in_month'
                 ),
             ],
             slug='percent_severe_stunting'
         ),
         AggregateColumn(
             'Percentage of children with moderate stunting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_moderate_column(self.beta)},
                     alias='stunting_moderate'
                 ),
                 AliasColumn('height_measured_in_month')
             ],
             slug='percent_moderate_stunting'
         ),
         AggregateColumn(
             'Percentage of children with normal height-for-age',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_normal_column(self.beta)},
                     alias='stunting_normal'
                 ),
                 AliasColumn('height_measured_in_month')
             ],
             slug='percent_normal_stunting'
         ),
         AggregateColumn(
             'Percent of newborns with low birth weight',
             percent,
             [
                 SumColumn('low_birth_weight_in_month'),
                 SumColumn('weighed_and_born_in_month')
             ],
             slug='newborn_low_birth_weight'
         ),
         AggregateColumn(
             'Percentage of children with completed 1 year immunizations',
             lambda x, y, z: '%.2f%%' % (((x or 0) + (y or 0)) * 100 / float(z or 1)),
             [
                 SumColumn('fully_immunized_on_time'),
                 SumColumn('fully_immunized_late'),
                 SumColumn('fully_immunized_eligible')
             ],
             slug='percent_completed_1year_immunizations'
         ),
         AggregateColumn(
             'Percentage of children breastfed at birth',
             percent,
             [
                 SumColumn('bf_at_birth'),
                 SumColumn('born_in_month')
             ],
             slug='percent_breastfed_at_birth'
         ),
         AggregateColumn(
             'Percentage of children exclusively breastfeeding',
             percent,
             [
                 SumColumn('ebf_in_month'),
                 SumColumn('ebf_eligible')
             ],
             slug='percent_ebf'
         ),
         AggregateColumn(
             'Percentage of children initiated complementary feeding (in the past 30 days)',
             percent,
             [
                 SumColumn('cf_initiation_in_month'),
                 SumColumn('cf_initiation_eligible')
             ],
             slug='percent_initiated_on_cf'
         ),
         AggregateColumn(
             'Percentage of children initiated appropriate complementary feeding',
             percent,
             [
                 SumColumn('cf_in_month'),
                 SumColumn('cf_eligible')
             ],
             slug='percent_appropriate_cf'
         ),
         AggregateColumn(
             'Percentage of children receiving complementary feeding with adequate diet diversity',
             percent,
             [
                 SumColumn('cf_diet_diversity'),
                 AliasColumn('cf_eligible')
             ],
             slug='percent_cf_diet_diversity'
         ),
         AggregateColumn(
             'Percentage of children receiving complementary feeding with adequate diet quanity',
             percent,
             [
                 SumColumn('cf_diet_quantity'),
                 AliasColumn('cf_eligible')
             ],
             slug='percent_cf_diet_quanity'
         ),
         AggregateColumn(
             "Percentage of children receiving complementary feeding "
             "with appropriate handwashing before feeding",
             percent,
             [
                 SumColumn('cf_handwashing'),
                 AliasColumn('cf_eligible')
             ],
             slug='percent_cf_handwashing_before_feeding'
         ),
     ]
     return columns + agg_columns
Exemple #9
0
 def get_columns(self, filters):
     return [
         DatabaseColumn('month', SimpleColumn('month')),
         AggregateColumn(
             '% Weighing efficiency (Children <5 weighed)',
             percent_num,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_weighed'},
                     alias='nutrition_status_weighed'
                 ),
                 SumWhen(
                     whens={"age_tranche != :age_72": 'wer_eligible'},
                     alias='wer_eligible'
                 )
             ],
             slug='status_weighed'
         ),
         AggregateColumn(
             '% Height measurement efficiency (Children <5 measured)',
             percent_num,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'height_measured_in_month'},
                     alias='height_measured_in_month_less_5'
                 ),
                 SumWhen(
                     whens={"age_tranche != :age_72": 'height_eligible'},
                     alias='height_eligible'
                 )
             ],
             slug='status_height_efficiency'
         ),
         DatabaseColumn(
             'Total number Unweighed',
             SumWhen(
                 whens={"age_tranche != :age_72": 'nutrition_status_unweighed'},
                 alias='nutrition_status_unweighed'
             )
         ),
         AggregateColumn(
             'Percent Children severely underweight (weight for age)',
             percent_num,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_severely_underweight'},
                     alias='nutrition_status_severely_underweight'
                 ),
                 AliasColumn('nutrition_status_weighed')
             ],
             slug='severely_underweight'
         ),
         AggregateColumn(
             'Percent Children moderately underweight (weight for age)',
             percent_num,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_moderately_underweight'},
                     alias='nutrition_status_moderately_underweight'
                 ),
                 AliasColumn('nutrition_status_weighed')
             ],
             slug='moderately_underweight'
         ),
         AggregateColumn(
             'Percent Children normal (weight for age)',
             percent_num,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_normal'},
                     alias='nutrition_status_normal'
                 ),
                 AliasColumn('nutrition_status_weighed')
             ],
             slug='status_normal'
         ),
         AggregateColumn(
             'Percent children with severe acute malnutrition (weight-for-height)',
             percent_num,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_severe_column(self.beta)},
                     alias='wasting_severe'
                 ),
                 SumWhen(
                     whens={get_age_condition(self.beta): wfh_recorded_in_month_column(self.beta)},
                     alias='weighed_and_height_measured_in_month'
                 )
             ],
             slug='wasting_severe'
         ),
         AggregateColumn(
             'Percent children with moderate acute malnutrition (weight-for-height)',
             percent_num,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_moderate_column(self.beta)},
                     alias='wasting_moderate'
                 ),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='wasting_moderate'
         ),
         AggregateColumn(
             'Percent children normal (weight-for-height)',
             percent_num,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_normal_column(self.beta)},
                     alias='wasting_normal'
                 ),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='wasting_normal'
         ),
         AggregateColumn(
             'Percent children with severe stunting (height for age)',
             percent_num,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_severe_column(self.beta)},
                     alias='zscore_grading_hfa_severe'
                 ),
                 SumWhen(
                     whens={get_age_condition(self.beta): hfa_recorded_in_month_column(self.beta)},
                     alias='height_measured_in_month'
                 )
             ],
             slug='stunting_severe'
         ),
         AggregateColumn(
             'Percent children with moderate stunting (height for age)',
             percent_num,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_moderate_column(self.beta)},
                     alias='zscore_grading_hfa_moderate'
                 ),
                 AliasColumn('height_measured_in_month')
             ],
             slug='stunting_moderate'
         ),
         AggregateColumn(
             'Percent children with normal (height for age)',
             percent_num,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_normal_column(self.beta)},
                     alias='zscore_grading_hfa_normal'
                 ),
                 AliasColumn('height_measured_in_month')
             ],
             slug='stunting_normal'
         ),
         AggregateColumn(
             'Percent children immunized with 1st year immunizations',
             lambda x, y, z: ((x or 0) + (y or 0)) * 100 / float(z or 1),
             [
                 SumColumn('fully_immunized_on_time'),
                 SumColumn('fully_immunized_late'),
                 SumColumn('fully_immunized_eligible')
             ],
             slug='fully_immunized'
         ),
         AggregateColumn(
             'Percent Children breastfed at birth',
             percent_num,
             [
                 SumColumn('bf_at_birth'),
                 SumColumn('born_in_month')
             ],
             slug='breastfed_at_birth'
         ),
         AggregateColumn(
             'Percent Children exclusively breastfed',
             percent_num,
             [
                 SumColumn('ebf_in_month'),
                 SumColumn('ebf_eligible')
             ],
             slug='exclusively_breastfed'
         ),
         AggregateColumn(
             'Percent Children initiated appropriate complementary feeding',
             percent_num,
             [
                 SumColumn('cf_initiation_in_month'),
                 SumColumn('cf_initiation_eligible')
             ],
             slug='cf_initiation'
         ),
         AggregateColumn(
             'Perecent children complementary feeding',
             percent_num,
             [
                 SumColumn('cf_in_month'),
                 SumColumn('cf_eligible')
             ],
             slug='complementary_feeding'
         ),
         AggregateColumn(
             'Percentage of children consuming atleast 4 food groups',
             percent_num,
             [
                 SumColumn('cf_diet_diversity'),
                 AliasColumn('cf_eligible')
             ],
             slug='diet_diversity'
         ),
         AggregateColumn(
             'Percentage of children consuming adequate food',
             percent_num,
             [
                 SumColumn('cf_diet_quantity'),
                 AliasColumn('cf_eligible')
             ],
             slug='diet_quantity'
         ),
         AggregateColumn(
             'Percentage of children whose mothers handwash before feeding',
             percent_num,
             [
                 SumColumn('cf_handwashing'),
                 AliasColumn('cf_eligible')
             ],
             slug='handwashing'
         ),
         DatabaseColumn(
             'Children (0 - 28 Days) Seeking Services',
             SumWhen(
                 whens={'age_tranche = :age_0': 'valid_in_month'},
                 alias='zero'
             ),
             slug='zero'
         ),
         DatabaseColumn(
             'Children (28 Days - 6 mo) Seeking Services',
             SumWhen(
                 whens={'age_tranche = :age_6': 'valid_in_month'},
                 alias='one'
             ),
             slug='one'
         ),
         DatabaseColumn(
             'Children (6 mo - 1 year) Seeking Services',
             SumWhen(
                 whens={'age_tranche = :age_12': 'valid_in_month'},
                 alias='two'
             ),
             slug='two'
         ),
         DatabaseColumn(
             'Children (1 year - 3 years) Seeking Services',
             SumWhen(
                 whens={'age_tranche = :age_24 OR age_tranche = :age_36': 'valid_in_month'},
                 alias='three'
             ),
             slug='three'
         ),
         DatabaseColumn(
             'Children (3 years - 6 years) Seeking Services',
             SumWhen(
                 whens={
                     'age_tranche = :age_48 OR age_tranche = :age_60 OR age_tranche = :age_72':
                         'valid_in_month'
                 },
                 alias='four'
             ),
             slug='four'
         ),
         AggregateColumn(
             'Percent of children born in month with low birth weight',
             percent_num,
             [
                 SumColumn('low_birth_weight_in_month'),
                 SumColumn('weighed_and_born_in_month')
             ],
             slug='low_birth_weight'
         )
     ]
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
            },
        ]
    }
def get_prevalence_of_stunting_data_chart(domain, config, loc_level, show_test=False, icds_feature_flag=False):
    month = datetime(*config['month'])
    three_before = datetime(*config['month']) - relativedelta(months=3)

    config['month__range'] = (three_before, month)
    del config['month']

    chart_data = AggChildHealthMonthly.objects.filter(
        **config
    ).values(
        'month', '%s_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'),
        measured=Sum(hfa_recorded_in_month_column(icds_feature_flag)),
    ).order_by('month')

    if not show_test:
        chart_data = apply_exclude(domain, chart_data)

    if 'age_tranche' not in config:
        chart_data = chart_data.exclude(age_tranche=72)

    data = {
        'red': OrderedDict(),
        'orange': OrderedDict(),
        'peach': OrderedDict()
    }

    dates = [dt for dt in rrule(MONTHLY, dtstart=three_before, until=month)]

    for date in dates:
        miliseconds = int(date.strftime("%s")) * 1000
        data['red'][miliseconds] = {'y': 0, 'all': 0, 'measured': 0}
        data['orange'][miliseconds] = {'y': 0, 'all': 0, 'measured': 0}
        data['peach'][miliseconds] = {'y': 0, 'all': 0, 'measured': 0}

    best_worst = {}
    for row in chart_data:
        date = row['month']
        total = row['total'] or 0
        measured = row['measured'] or 0
        location = row['%s_name' % loc_level]
        severe = row['severe'] or 0
        moderate = row['moderate'] or 0
        normal = row['normal'] or 0

        underweight = moderate + severe

        best_worst[location] = underweight * 100 / float(measured or 1)

        date_in_miliseconds = int(date.strftime("%s")) * 1000

        data['peach'][date_in_miliseconds]['y'] += normal
        data['peach'][date_in_miliseconds]['measured'] += measured
        data['peach'][date_in_miliseconds]['all'] += total
        data['orange'][date_in_miliseconds]['y'] += moderate
        data['orange'][date_in_miliseconds]['measured'] += measured
        data['orange'][date_in_miliseconds]['all'] += total
        data['red'][date_in_miliseconds]['y'] += severe
        data['red'][date_in_miliseconds]['measured'] += measured
        data['red'][date_in_miliseconds]['all'] += total

    top_locations = sorted(
        [dict(loc_name=key, percent=value) for key, value in six.iteritems(best_worst)],
        key=lambda x: (x['percent'], x['loc_name'])
    )

    return {
        "chart_data": [
            {
                "values": [
                    {
                        'x': key,
                        'y': value['y'] / float(value['measured'] or 1),
                        'all': value['all'],
                        'measured': value['measured']
                    } for key, value in six.iteritems(data['peach'])
                ],
                "key": "% normal",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": ChartColors.PINK
            },
            {
                "values": [
                    {
                        'x': key,
                        'y': value['y'] / float(value['measured'] or 1),
                        'all': value['all'],
                        'measured': value['measured']
                    } for key, value in six.iteritems(data['orange'])
                ],
                "key": "% moderately stunted",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": ChartColors.ORANGE
            },
            {
                "values": [
                    {
                        'x': key,
                        'y': value['y'] / float(value['measured'] or 1),
                        'all': value['all'],
                        'measured': value['measured']
                    } for key, value in six.iteritems(data['red'])
                ],
                "key": "% severely stunted",
                "strokeWidth": 2,
                "classed": "dashed",
                "color": ChartColors.RED
            }
        ],
        "all_locations": top_locations,
        "top_five": top_locations[:5],
        "bottom_five": top_locations[-5:],
        "location_type": loc_level.title() if loc_level != LocationTypes.SUPERVISOR else 'Sector'
    }
Exemple #12
0
 def columns(self):
     columns = self.get_columns_by_loc_level
     agg_columns = [
         AggregateColumn(
             'Weighing efficiency (in month)',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_weighed'}, else_=0,
                     alias='nutrition_status_weighed'
                 ),
                 SumWhen(
                     whens={"age_tranche != :age_72": 'wer_eligible'}, else_=0,
                     alias='wer_eligible'
                 )
             ],
             slug='percent_weight_efficiency'
         ),
         AggregateColumn(
             'Height measurement efficiency (in month)',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'height_measured_in_month'}, else_=0,
                     alias='height_measured_in_month_efficiency'
                 ),
                 SumWhen(
                     whens={"age_tranche != :age_72": 'height_eligible'}, else_=0,
                     alias='height_eligible',
                 )
             ],
             slug='height_measurement'
         ),
         DatabaseColumn(
             'Total number of unweighed children (0-5 Years)',
             SumWhen(
                 whens={"age_tranche != :age_72": 'nutrition_status_unweighed'}, else_=0,
                 alias='nutrition_status_unweighed'
             ),
             slug='total_number_unweighed'
         ),
         AggregateColumn(
             'Percentage of severely underweight children',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_severely_underweight'}, else_=0,
                     alias='nutrition_status_severely_underweight'
                 ),
                 AliasColumn('nutrition_status_weighed'),
             ],
             slug='percent_severe_underweight'
         ),
         AggregateColumn(
             'Percentage of moderately underweight children',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_moderately_underweight'}, else_=0,
                     alias='nutrition_status_moderately_underweight'
                 ),
                 AliasColumn('nutrition_status_weighed'),
             ],
             slug='percent_moderate_underweight'
         ),
         AggregateColumn(
             'Percentage of normal weight-for-age children',
             percent,
             [
                 SumWhen(
                     whens={"age_tranche != :age_72": 'nutrition_status_normal'}, else_=0,
                     alias='nutrition_status_normal'
                 ),
                 AliasColumn('nutrition_status_weighed'),
             ],
             slug='percent_normal_weight'
         ),
         AggregateColumn(
             'Percentage of children with severe wasting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_severe_column(self.beta)},
                     alias='wasting_severe'
                 ),
                 SumWhen(
                     whens={get_age_condition(self.beta): wfh_recorded_in_month_column(self.beta)},
                     alias='weighed_and_height_measured_in_month'
                 ),
             ],
             slug='percent_severe_wasting'
         ),
         AggregateColumn(
             'Percentage of children with moderate wasting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_moderate_column(self.beta)},
                     alias='wasting_moderate'
                 ),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='percent_moderate_wasting'
         ),
         AggregateColumn(
             'Percentage of children with normal weight-for-height',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): wasting_normal_column(self.beta)},
                     alias='wasting_normal'
                 ),
                 AliasColumn('weighed_and_height_measured_in_month')
             ],
             slug='percent_normal_wasting'
         ),
         AggregateColumn(
             'Percentage of children with severe stunting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_severe_column(self.beta)},
                     alias='stunting_severe'
                 ),
                 SumWhen(
                     whens={get_age_condition(self.beta): hfa_recorded_in_month_column(self.beta)},
                     alias='height_measured_in_month'
                 ),
             ],
             slug='percent_severe_stunting'
         ),
         AggregateColumn(
             'Percentage of children with moderate stunting',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_moderate_column(self.beta)},
                     alias='stunting_moderate'
                 ),
                 AliasColumn('height_measured_in_month')
             ],
             slug='percent_moderate_stunting'
         ),
         AggregateColumn(
             'Percentage of children with normal height-for-age',
             percent,
             [
                 SumWhen(
                     whens={get_age_condition(self.beta): stunting_normal_column(self.beta)},
                     alias='stunting_normal'
                 ),
                 AliasColumn('height_measured_in_month')
             ],
             slug='percent_normal_stunting'
         ),
         AggregateColumn(
             'Percent of newborns with low birth weight',
             percent,
             [
                 SumColumn('low_birth_weight_in_month'),
                 SumColumn('weighed_and_born_in_month')
             ],
             slug='newborn_low_birth_weight'
         ),
         AggregateColumn(
             'Percentage of children with completed 1 year immunizations',
             lambda x, y, z: '%.2f%%' % (((x or 0) + (y or 0)) * 100 / float(z or 1)),
             [
                 SumColumn('fully_immunized_on_time'),
                 SumColumn('fully_immunized_late'),
                 SumColumn('fully_immunized_eligible')
             ],
             slug='percent_completed_1year_immunizations'
         ),
         AggregateColumn(
             'Percentage of children breastfed at birth',
             percent,
             [
                 SumColumn('bf_at_birth'),
                 SumColumn('born_in_month')
             ],
             slug='percent_breastfed_at_birth'
         ),
         AggregateColumn(
             'Percentage of children exclusively breastfeeding',
             percent,
             [
                 SumColumn('ebf_in_month'),
                 SumColumn('ebf_eligible')
             ],
             slug='percent_ebf'
         ),
         AggregateColumn(
             'Percentage of children initiated complementary feeding (in the past 30 days)',
             percent,
             [
                 SumColumn('cf_initiation_in_month'),
                 SumColumn('cf_initiation_eligible')
             ],
             slug='percent_initiated_on_cf'
         ),
         AggregateColumn(
             'Percentage of children initiated appropriate complementary feeding',
             percent,
             [
                 SumColumn('cf_in_month'),
                 SumColumn('cf_eligible')
             ],
             slug='percent_appropriate_cf'
         ),
         AggregateColumn(
             'Percentage of children receiving complementary feeding with adequate diet diversity',
             percent,
             [
                 SumColumn('cf_diet_diversity'),
                 AliasColumn('cf_eligible')
             ],
             slug='percent_cf_diet_diversity'
         ),
         AggregateColumn(
             'Percentage of children receiving complementary feeding with adequate diet quanity',
             percent,
             [
                 SumColumn('cf_diet_quantity'),
                 AliasColumn('cf_eligible')
             ],
             slug='percent_cf_diet_quanity'
         ),
         AggregateColumn(
             "Percentage of children receiving complementary feeding "
             "with appropriate handwashing before feeding",
             percent,
             [
                 SumColumn('cf_handwashing'),
                 AliasColumn('cf_eligible')
             ],
             slug='percent_cf_handwashing_before_feeding'
         ),
     ]
     return columns + agg_columns
Exemple #13
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
            },
        ]
    }
Exemple #14
0
    def columns(self):
        columns = self.get_columns_by_loc_level
        agg_columns = [
            AggregateColumn(
                'Weighing efficiency (in month)',
                percent, [
                    SumWhen(whens={
                        "age_tranche != :age_72":
                        'nutrition_status_weighed'
                    },
                            else_=0,
                            alias='nutrition_status_weighed'),
                    SumWhen(whens={"age_tranche != :age_72": 'wer_eligible'},
                            else_=0,
                            alias='wer_eligible')
                ],
                slug='percent_weight_efficiency'),
            AggregateColumn(
                'Height measurement efficiency (in month)',
                percent, [
                    SumWhen(whens={
                        "age_tranche != :age_72":
                        'height_measured_in_month'
                    },
                            else_=0,
                            alias='height_measured_in_month_efficiency'),
                    SumWhen(
                        whens={"age_tranche != :age_72": 'height_eligible'},
                        else_=0,
                        alias='height_eligible',
                    )
                ],
                slug='height_measurement'),
            DatabaseColumn('Total number of unweighed children (0-5 Years)',
                           SumWhen(whens={
                               "age_tranche != :age_72":
                               'nutrition_status_unweighed'
                           },
                                   else_=0,
                                   alias='nutrition_status_unweighed'),
                           slug='total_number_unweighed'),
            AggregateColumn(
                'Percentage of severely underweight children',
                percent, [
                    SumWhen(whens={
                        "age_tranche != :age_72":
                        'nutrition_status_severely_underweight'
                    },
                            else_=0,
                            alias='nutrition_status_severely_underweight'),
                    AliasColumn('nutrition_status_weighed'),
                ],
                slug='percent_severe_underweight'),
            AggregateColumn(
                'Percentage of moderately underweight children',
                percent, [
                    SumWhen(whens={
                        "age_tranche != :age_72":
                        'nutrition_status_moderately_underweight'
                    },
                            else_=0,
                            alias='nutrition_status_moderately_underweight'),
                    AliasColumn('nutrition_status_weighed'),
                ],
                slug='percent_moderate_underweight'),
            AggregateColumn(
                'Percentage of normal weight-for-age children',
                percent, [
                    SumWhen(whens={
                        "age_tranche != :age_72": 'nutrition_status_normal'
                    },
                            else_=0,
                            alias='nutrition_status_normal'),
                    AliasColumn('nutrition_status_weighed'),
                ],
                slug='percent_normal_weight'),
            AggregateColumn(
                'Percentage of children with severe wasting',
                percent, [
                    SumWhen(whens={
                        get_age_condition(self.beta):
                        wasting_severe_column(self.beta)
                    },
                            alias='wasting_severe'),
                    SumWhen(whens={
                        get_age_condition(self.beta):
                        wfh_recorded_in_month_column(self.beta)
                    },
                            alias='weighed_and_height_measured_in_month'),
                ],
                slug='percent_severe_wasting'),
            AggregateColumn(
                'Percentage of children with moderate wasting',
                percent, [
                    SumWhen(whens={
                        get_age_condition(self.beta):
                        wasting_moderate_column(self.beta)
                    },
                            alias='wasting_moderate'),
                    AliasColumn('weighed_and_height_measured_in_month')
                ],
                slug='percent_moderate_wasting'),
            AggregateColumn(
                'Percentage of children with normal weight-for-height',
                percent, [
                    SumWhen(whens={
                        get_age_condition(self.beta):
                        wasting_normal_column(self.beta)
                    },
                            alias='wasting_normal'),
                    AliasColumn('weighed_and_height_measured_in_month')
                ],
                slug='percent_normal_wasting'),
            AggregateColumn('Percentage of children with severe stunting',
                            percent, [
                                SumWhen(whens={
                                    get_age_condition(self.beta):
                                    stunting_severe_column(self.beta)
                                },
                                        alias='stunting_severe'),
                                SumWhen(whens={
                                    get_age_condition(self.beta):
                                    hfa_recorded_in_month_column(self.beta)
                                },
                                        alias='height_measured_in_month'),
                            ],
                            slug='percent_severe_stunting'),
            AggregateColumn('Percentage of children with moderate stunting',
                            percent, [
                                SumWhen(whens={
                                    get_age_condition(self.beta):
                                    stunting_moderate_column(self.beta)
                                },
                                        alias='stunting_moderate'),
                                AliasColumn('height_measured_in_month')
                            ],
                            slug='percent_moderate_stunting'),
            AggregateColumn(
                'Percentage of children with normal height-for-age',
                percent, [
                    SumWhen(whens={
                        get_age_condition(self.beta):
                        stunting_normal_column(self.beta)
                    },
                            alias='stunting_normal'),
                    AliasColumn('height_measured_in_month')
                ],
                slug='percent_normal_stunting'),
            AggregateColumn('Percent of newborns with low birth weight',
                            percent, [
                                SumColumn('low_birth_weight_in_month',
                                          alias='low_birth_weight_in_month'),
                                SumColumn('weighed_and_born_in_month',
                                          alias='weighed_and_born_in_month')
                            ],
                            slug='newborn_low_birth_weight'),
            AggregateColumn(
                'Percentage of children with completed 1 year immunizations',
                lambda x, y, z: '%.2f%%' % ((
                    (x or 0) + (y or 0)) * 100 / float(z or 1)), [
                        SumColumn('fully_immunized_on_time',
                                  alias='fully_immunized_on_time'),
                        SumColumn('fully_immunized_late',
                                  alias='fully_immunized_late'),
                        SumColumn('fully_immunized_eligible',
                                  alias='fully_immunized_eligible')
                    ],
                slug='percent_completed_1year_immunizations'),
            AggregateColumn(
                'Percentage of children breastfed at birth',
                percent, [
                    SumColumn('bf_at_birth', alias='bf_at_birth'),
                    SumColumn('born_in_month', alias='born_in_month')
                ],
                slug='percent_breastfed_at_birth'),
            AggregateColumn(
                'Percentage of children exclusively breastfeeding',
                percent, [
                    SumColumn('ebf_in_month', alias='ebf_in_month'),
                    SumColumn('ebf_eligible', alias='ebf_eligible')
                ],
                slug='percent_ebf'),
            AggregateColumn(
                'Percentage of children initiated complementary feeding (in the past 30 days)',
                percent, [
                    SumColumn('cf_initiation_in_month',
                              alias='cf_initiation_in_month'),
                    SumColumn('cf_initiation_eligible',
                              alias='cf_initiation_eligible')
                ],
                slug='percent_initiated_on_cf'),
            AggregateColumn(
                'Percentage of children initiated appropriate complementary feeding',
                percent, [
                    SumColumn('cf_in_month', alias='cf_in_month'),
                    SumColumn('cf_eligible', alias='cf_eligible')
                ],
                slug='percent_appropriate_cf'),
            AggregateColumn(
                'Percentage of children receiving complementary feeding with adequate diet diversity',
                percent, [
                    SumColumn('cf_diet_diversity', alias='cf_diet_diversity'),
                    AliasColumn('cf_eligible')
                ],
                slug='percent_cf_diet_diversity'),
            AggregateColumn(
                'Percentage of children receiving complementary feeding with adequate diet quantity',
                percent, [
                    SumColumn('cf_diet_quantity', alias='cf_diet_quantity'),
                    AliasColumn('cf_eligible')
                ],
                slug='percent_cf_diet_quanity'),
            AggregateColumn(
                "Percentage of children receiving complementary feeding "
                "with appropriate handwashing before feeding",
                percent, [
                    SumColumn('cf_handwashing', alias='cf_handwashing'),
                    AliasColumn('cf_eligible')
                ],
                slug='percent_cf_handwashing_before_feeding'),
        ]
        agg_columns.insert(
            0,
            DatabaseColumn('Total no. of children weighed',
                           AliasColumn('nutrition_status_weighed'),
                           slug='nutrition_status_weighed'))
        agg_columns.insert(
            1,
            DatabaseColumn('Total no. of children eligible to be weighed',
                           AliasColumn('wer_eligible'),
                           slug='wer_eligible'))

        agg_columns.insert(
            3,
            DatabaseColumn('Total no. of children whose height was measured',
                           AliasColumn('height_measured_in_month_efficiency'),
                           slug='height_measured_in_month_efficiency'))
        agg_columns.insert(
            4,
            DatabaseColumn(
                'Total no. of children  eligible for measuring height',
                AliasColumn('height_eligible'),
                slug='height_eligible'))

        agg_columns.insert(
            7,
            DatabaseColumn(
                'No. of severely underweight children',
                AliasColumn('nutrition_status_severely_underweight'),
                slug='nutrition_status_severely_underweight'))
        agg_columns.insert(
            8,
            DatabaseColumn('Total No. of children weighed',
                           AliasColumn('nutrition_status_weighed'),
                           slug='nutrition_status_weighed'))

        agg_columns.insert(
            10,
            DatabaseColumn(
                'No. of moderately underweight children ',
                AliasColumn('nutrition_status_moderately_underweight'),
                slug='nutrition_status_moderately_underweight'))
        agg_columns.insert(
            11,
            DatabaseColumn('Total No. of children weighed',
                           AliasColumn('nutrition_status_weighed'),
                           slug='nutrition_status_weighed'))

        agg_columns.insert(
            13,
            DatabaseColumn('No. of  children with normal weight for age',
                           AliasColumn('nutrition_status_normal'),
                           slug='nutrition_status_normal'))
        agg_columns.insert(
            14,
            DatabaseColumn('Total No. of children weighed',
                           AliasColumn('nutrition_status_weighed'),
                           slug='nutrition_status_weighed'))

        agg_columns.insert(
            16,
            DatabaseColumn('No. of Children with severe wasting',
                           AliasColumn('wasting_severe'),
                           slug='wasting_severe'))
        agg_columns.insert(
            17,
            DatabaseColumn(
                'Total number of children whose height and weight is measured',
                AliasColumn('weighed_and_height_measured_in_month'),
                slug='weighed_and_height_measured_in_month'))

        agg_columns.insert(
            19,
            DatabaseColumn('No. of moderately wasted children',
                           AliasColumn('wasting_moderate'),
                           slug='wasting_moderate'))
        agg_columns.insert(
            20,
            DatabaseColumn(
                'Total number of children whose height and weight is measured',
                AliasColumn('weighed_and_height_measured_in_month'),
                slug='weighed_and_height_measured_in_month'))

        agg_columns.insert(
            22,
            DatabaseColumn('No. of children with normal weight-for-height',
                           AliasColumn('wasting_normal'),
                           slug='wasting_normal'))
        agg_columns.insert(
            23,
            DatabaseColumn(
                'Total no. of children  whose height and weight is measured',
                AliasColumn('weighed_and_height_measured_in_month'),
                slug='weighed_and_height_measured_in_month'))

        agg_columns.insert(
            25,
            DatabaseColumn('No. of severely stunted children',
                           AliasColumn('stunting_severe'),
                           slug='stunting_severe'))
        agg_columns.insert(
            26,
            DatabaseColumn(
                'Total no. of children whose height has been measured',
                AliasColumn('height_measured_in_month'),
                slug='height_measured_in_month'))

        agg_columns.insert(
            28,
            DatabaseColumn('No. of moderately stunted children',
                           AliasColumn('stunting_moderate'),
                           slug='stunting_moderate'))
        agg_columns.insert(
            29,
            DatabaseColumn(
                'Total no. of children whose height has been measured',
                AliasColumn('height_measured_in_month'),
                slug='height_measured_in_month'))

        agg_columns.insert(
            31,
            DatabaseColumn('No. of children with normal height for age',
                           AliasColumn('stunting_normal'),
                           slug='stunting_normal'))
        agg_columns.insert(
            32,
            DatabaseColumn(
                'Total no. of children whose height has been measured',
                AliasColumn('height_measured_in_month'),
                slug='height_measured_in_month'))

        agg_columns.insert(
            34,
            DatabaseColumn('No. of newborns with low birth weight',
                           AliasColumn('low_birth_weight_in_month'),
                           slug='low_birth_weight_in_month'))
        agg_columns.insert(
            35,
            DatabaseColumn(
                'Total no. of children born and weighed in the current month',
                AliasColumn('weighed_and_born_in_month'),
                slug='weighed_and_born_in_month'))

        agg_columns.insert(
            37,
            AggregateColumn('No. of children completed 1 year immunization',
                            lambda x, y: ((x or 0) + (y or 0)), [
                                AliasColumn('fully_immunized_on_time'),
                                AliasColumn('fully_immunized_late')
                            ],
                            slug='num_immun_children'))
        agg_columns.insert(
            38,
            DatabaseColumn('Total no. of children from age >12 months',
                           AliasColumn('fully_immunized_eligible'),
                           slug='fully_immunized_eligible'))

        agg_columns.insert(
            40,
            DatabaseColumn('No. of children breastfed at birth',
                           AliasColumn('bf_at_birth'),
                           slug='bf_at_birth'))
        agg_columns.insert(
            41,
            DatabaseColumn(
                'Total no. of children enrolled in ICDS-CAS system and born in last month',
                AliasColumn('born_in_month'),
                slug='born_in_month'))

        agg_columns.insert(
            43,
            DatabaseColumn('No. of children exclusively breastfed',
                           AliasColumn('ebf_in_month'),
                           slug='ebf_in_month'))
        agg_columns.insert(
            44,
            DatabaseColumn(
                'Total number of children (0-6 months) of age enrolled in ICDS-CAS system',
                AliasColumn('ebf_eligible'),
                slug='ebf_eligible'))

        agg_columns.insert(
            46,
            DatabaseColumn(
                'No. of children initiated complementary feeding (in the past 30 days)',
                AliasColumn('cf_initiation_in_month'),
                slug='cf_initiation_in_month'))
        agg_columns.insert(
            47,
            DatabaseColumn(
                'Total no. of children (6-8 ) months of age enrolled with ICDS-CAS',
                AliasColumn('cf_initiation_eligible'),
                slug='cf_initiation_eligible'))

        agg_columns.insert(
            49,
            DatabaseColumn(
                'No. of children initiated appropriate complementary feeding',
                AliasColumn('cf_in_month'),
                slug='cf_in_month'))
        agg_columns.insert(
            50,
            DatabaseColumn(
                'No.of children (6-24) months of age enrolled with ICDS-CAS',
                AliasColumn('cf_eligible'),
                slug='cf_eligible'))

        agg_columns.insert(
            52,
            DatabaseColumn(
                'No.of children receiving complementary feeding with adequate diet diversity',
                AliasColumn('cf_diet_diversity'),
                slug='cf_diet_diversity'))
        agg_columns.insert(
            53,
            DatabaseColumn(
                'Total number of children (6 months - 2 yrs) of age enrolled with ICDS-CAS',
                AliasColumn('cf_eligible'),
                slug='cf_eligible'))

        agg_columns.insert(
            55,
            DatabaseColumn(
                'No. of children initiated complementary feeding with adequate diet quantity',
                AliasColumn('cf_diet_quantity'),
                slug='cf_diet_quantity'))
        agg_columns.insert(
            56,
            DatabaseColumn(
                'No.of children (6-24) months of age enrolled with ICDS-CAS',
                AliasColumn('cf_eligible'),
                slug='cf_eligible'))

        agg_columns.insert(
            58,
            DatabaseColumn(
                'Total Number of children receiving complementary feeding '
                'with appropriate handwashing before feeding',
                AliasColumn('cf_handwashing'),
                slug='cf_handwashing'))
        agg_columns.insert(
            59,
            DatabaseColumn(
                'No.of children (6-24) months of age enrolled with ICDS-CAS',
                AliasColumn('cf_eligible'),
                slug='cf_eligible'))
        return columns + agg_columns
Exemple #15
0
    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_child_health_monthly(date, filters):

        age_filters = {'age_tranche': 72}

        moderately_underweight = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            'nutrition_status_moderately_underweight'
        )
        severely_underweight = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            'nutrition_status_severely_underweight'
        )
        wasting_moderate = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            wasting_moderate_column(icds_feature_flag)
        )
        wasting_severe = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            wasting_severe_column(icds_feature_flag)
        )
        stunting_moderate = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            stunting_moderate_column(icds_feature_flag)
        )
        stunting_severe = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            stunting_severe_column(icds_feature_flag)
        )
        nutrition_status_weighed = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            'nutrition_status_weighed'
        )
        height_measured_in_month = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            hfa_recorded_in_month_column(icds_feature_flag)
        )
        weighed_and_height_measured_in_month = include_records_by_age_for_column(
            {'age_tranche__lt': 72},
            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