def get_infants_weight_scale_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter(**config).values(*group_by).annotate( in_month=Sum('infra_infant_weighing_scale'), all=Sum('num_awc_infra_last_update'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'in_month': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['all'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'in_month': in_month or 0, 'all': valid or 0} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": awcs_reported_weighing_scale_infants_help_text(), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_adolescent_girls_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter(**config).values(*group_by).annotate( valid=Sum('cases_person_adolescent_girls_11_14') + Sum('cases_person_adolescent_girls_15_18'), all=Sum('cases_person_adolescent_girls_11_14_all') + Sum('cases_person_adolescent_girls_15_18_all'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = {'blue': []} tooltips_data = defaultdict(lambda: {'valid': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['valid'] or 0 all_adolescent = row['all'] or 0 name = row['%s_name' % loc_level] result_set.add(name) row_values = {'valid': valid, 'all': all_adolescent} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value chart_data['blue'].append([name, valid]) 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']) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": _(("Total number of adolescent girls who are enrolled for ICDS services" )), "chart_data": [{ "values": chart_data['blue'], "key": "Number Of Girls", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_enrolled_children_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate(valid=Sum('valid_in_month'), all=Sum('valid_all_registered_in_month')).order_by( '%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = {'blue': []} tooltips_data = defaultdict(lambda: {'valid': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['valid'] or 0 all_children = row['all'] or 0 name = row['%s_name' % loc_level] result_set.add(name) row_values = {'valid': valid, 'all': all_children} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value chart_data['blue'].append([name, valid]) 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']) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": _(("Total number of children between the age of 0 - 6 years who are enrolled for Anganwadi Services" )), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_lactating_enrolled_women_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggCcsRecordMonthly.objects.filter(**config).values( *group_by).annotate(valid=Sum('lactating'), all=Sum('lactating_all')).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = {'blue': []} tooltips_data = defaultdict(lambda: {'valid': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['valid'] or 0 all_lactating = row['all'] or 0 name = row['%s_name' % loc_level] result_set.add(name) row_values = {'valid': valid, 'all': all_lactating} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value chart_data['blue'].append([name, valid]) 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']) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": percent_lactating_women_enrolled_help_text(), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_registered_household_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter(**config).values(*group_by).annotate( household=Sum('cases_household'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = {'blue': []} tooltips_data = defaultdict(lambda: {'household': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: name = row['%s_name' % loc_level] household = row['household'] result_set.add(name) row_values = {'household': household} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value for name, value_dict in six.iteritems(tooltips_data): chart_data['blue'].append([name, value_dict['household'] or 0]) 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']) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": _("Total number of households registered"), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_registered_household_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter( **config ).values( *group_by ).annotate( household=Sum('cases_household'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [] } tooltips_data = defaultdict(lambda: { 'household': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: name = row['%s_name' % loc_level] household = row['household'] result_set.add(name) row_values = { 'household': household } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value for name, value_dict in six.iteritems(tooltips_data): chart_data['blue'].append([name, value_dict['household'] or 0]) 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']) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": _("Total number of households registered"), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
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_awcs_covered_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) level = config['aggregation_level'] data = AggAwcMonthly.objects.filter( **config ).values( *group_by ).annotate( states=Sum('num_launched_states') if level <= 1 else Max('num_launched_states'), districts=Sum('num_launched_districts') if level <= 2 else Max('num_launched_districts'), blocks=Sum('num_launched_blocks') if level <= 3 else Max('num_launched_blocks'), supervisors=Sum('num_launched_supervisors') if level <= 4 else Max('num_launched_supervisors'), awcs=Sum('num_launched_awcs') if level <= 5 else Max('num_launched_awcs'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'districts': 0, 'blocks': 0, 'states': 0, 'supervisors': 0, 'awcs': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: name = row['%s_name' % loc_level] awcs = row['awcs'] or 0 supervisors = row['supervisors'] or 0 blocks = row['blocks'] or 0 districts = row['districts'] or 0 states = row['states'] or 0 result_set.add(name) row_values = { 'awcs': awcs, 'supervisors': supervisors, 'blocks': blocks, 'districts': districts, 'states': states, } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += (value or 0) for name, value_dict in six.iteritems(tooltips_data): chart_data['blue'].append([name, value_dict['awcs']]) 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']) if level == 1: prop = 'states' elif level == 2: prop = 'districts' elif level == 3: prop = 'blocks' elif level == 4: prop = 'supervisors' else: prop = 'awcs' total_awcs = sum([(x['awcs'] or 0) for x in six.itervalues(tooltips_data)]) total = sum([(x[prop] or 0) for x in six.itervalues(tooltips_data)]) info = _( "{:s}<br /><br />" "Number of AWCs launched: {:d}".format(awcs_launched_help_text(), total_awcs) ) if level != 5: info = _( "{:s}<br /><br />" "Number of AWCs launched: {:d} <br />" "Number of {:s} launched: {:d}".format(awcs_launched_help_text(), total_awcs, prop.title(), total) ) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": info, "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_newborn_with_low_birth_weight_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate(low_birth=Sum('low_birth_weight_in_month'), in_month=Sum('weighed_and_born_in_month'), all=Sum('born_in_month')).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'low_birth': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] or 0 name = row['%s_name' % loc_level] result_set.add(name) all_records = row['all'] or 0 low_birth = row['low_birth'] or 0 value = low_birth / float(in_month or 1) tooltips_data[name]['low_birth'] += low_birth tooltips_data[name]['in_month'] += in_month tooltips_data[name]['all'] += all_records 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']) return { "tooltips_data": dict(tooltips_data), "info": _((new_born_with_low_weight_help_text(html=True))), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_immunization_coverage_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( in_month=Sum('fully_immunized_on_time') + Sum('fully_immunized_late'), eligible=Sum('fully_immunized_eligible'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'children': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = { 'children': in_month or 0, 'all': valid or 0 } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(( "Of the total number of children enrolled for Anganwadi Services who are over a year old, the " "percentage of children who have received the complete immunization as per the National Immunization " "Schedule of India that is required by age 1." "<br/><br/>" "This includes the following immunizations:<br/>" "If Pentavalent path: Penta1/2/3, OPV1/2/3, BCG, Measles, VitA1<br/>" "If DPT/HepB path: DPT1/2/3, HepB1/2/3, OPV1/2/3, BCG, Measles, VitA1" )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_prevalence_of_severe_sector_data(domain, config, loc_level, location_id, show_test=False, icds_feature_flag=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( moderate=Sum(wasting_moderate_column(icds_feature_flag)), severe=Sum(wasting_severe_column(icds_feature_flag)), normal=Sum(wasting_normal_column(icds_feature_flag)), total_height_eligible=Sum('height_eligible'), total_weighed=Sum('nutrition_status_weighed'), total_measured=Sum(wfh_recorded_in_month_column(icds_feature_flag)), weighed_and_height_measured=Sum('weighed_and_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: data = data.exclude(age_tranche=72) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'severe': 0, 'moderate': 0, 'total_height_eligible': 0, 'weighed_and_height_measured': 0, 'normal': 0, 'total_weighed': 0, 'total_measured': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: total_weighed = row['total_weighed'] or 0 name = row['%s_name' % loc_level] result_set.add(name) severe = row['severe'] or 0 moderate = row['moderate'] or 0 normal = row['normal'] or 0 total_measured = row['total_measured'] or 0 total_height_eligible = row['total_height_eligible'] or 0 weighed_and_height_measured = row['weighed_and_height_measured'] or 0 tooltips_data[name]['severe'] += severe tooltips_data[name]['moderate'] += moderate tooltips_data[name]['total_weighed'] += total_weighed tooltips_data[name]['normal'] += normal tooltips_data[name]['total_measured'] += total_measured tooltips_data[name]['total_height_eligible'] += total_height_eligible tooltips_data[name]['weighed_and_height_measured'] += weighed_and_height_measured value = (moderate + severe) / float(total_weighed or 1) chart_data['blue'].append([ name, value ]) for sql_location in loc_children: if sql_location.name not in result_set: chart_data['blue'].append([sql_location.name, 0]) chart_data['blue'] = sorted(chart_data['blue']) gender_label, age_label, chosen_filters = chosen_filters_to_labels( config, default_interval=default_age_interval(icds_feature_flag) ) return { "tooltips_data": dict(tooltips_data), "info": _(wasting_help_text(age_label)), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_awcs_covered_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) level = config['aggregation_level'] data = AggAwcMonthly.objects.filter( **config ).values( *group_by ).annotate( states=Sum('num_launched_states') if level <= 1 else Max('num_launched_states'), districts=Sum('num_launched_districts') if level <= 2 else Max('num_launched_districts'), blocks=Sum('num_launched_blocks') if level <= 3 else Max('num_launched_blocks'), supervisors=Sum('num_launched_supervisors') if level <= 4 else Max('num_launched_supervisors'), awcs=Sum('num_launched_awcs') if level <= 5 else Max('num_launched_awcs'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'districts': 0, 'blocks': 0, 'states': 0, 'supervisors': 0, 'awcs': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: name = row['%s_name' % loc_level] awcs = row['awcs'] or 0 supervisors = row['supervisors'] or 0 blocks = row['blocks'] or 0 districts = row['districts'] or 0 states = row['states'] or 0 result_set.add(name) row_values = { 'awcs': awcs, 'supervisors': supervisors, 'blocks': blocks, 'districts': districts, 'states': states, } for prop, value in row_values.items(): tooltips_data[name][prop] += (value or 0) for name, value_dict in tooltips_data.items(): chart_data['blue'].append([name, value_dict['awcs']]) 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']) if level == 1: prop = 'states' elif level == 2: prop = 'districts' elif level == 3: prop = 'blocks' elif level == 4: prop = 'supervisors' else: prop = 'awcs' total_awcs = sum([(x['awcs'] or 0) for x in tooltips_data.values()]) total = sum([(x[prop] or 0) for x in tooltips_data.values()]) info = _( "{:s}<br /><br />" "Number of AWCs launched: {:d}".format(awcs_launched_help_text(), total_awcs) ) if level != 5: info = _( "{:s}<br /><br />" "Number of AWCs launched: {:d} <br />" "Number of {:s} launched: {:d}".format(awcs_launched_help_text(), total_awcs, prop.title(), total) ) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": info, "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_institutional_deliveries_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggCcsRecordMonthly.objects.filter(**config).values( *group_by).annotate( in_month=Sum('institutional_delivery_in_month'), eligible=Sum('delivered_in_month'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'children': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'children': in_month or 0, 'all': valid or 0} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Of the total number of women enrolled for Anganwadi services who gave birth in the last month, " "the percentage who delivered in a public or private medical facility. " "<br/><br/>" "Delivery in medical instituitions is associated with a decrease in maternal mortality rate" )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_adhaar_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter(**config).values(*group_by).annotate( in_month=Sum('cases_person_has_aadhaar'), all=Sum('cases_person_beneficiary'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'in_month': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['all'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'in_month': in_month or 0, 'all': valid or 0} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Percentage of individuals registered using CAS whose Aadhaar identification has been captured" )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_newborn_with_low_birth_weight_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( low_birth=Sum('low_birth_weight_in_month'), in_month=Sum('weighed_and_born_in_month'), all=Sum('born_in_month') ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'low_birth': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] or 0 name = row['%s_name' % loc_level] result_set.add(name) all_records = row['all'] or 0 low_birth = row['low_birth'] or 0 value = low_birth / float(in_month or 1) tooltips_data[name]['low_birth'] += low_birth tooltips_data[name]['in_month'] += in_month tooltips_data[name]['all'] += all_records 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']) return { "tooltips_data": dict(tooltips_data), "info": _(( new_born_with_low_weight_help_text(html=True) )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_exclusive_breastfeeding_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( in_month=Sum('ebf_in_month'), eligible=Sum('ebf_eligible'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'children': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'children': in_month or 0, 'all': valid or 0} for prop, value in row_values.items(): tooltips_data[name][prop] += value in_month = row['in_month'] value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": exclusive_breastfeeding_help_text(html=True), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_prevalence_of_undernutrition_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( moderately_underweight=Sum( 'nutrition_status_moderately_underweight'), severely_underweight=Sum('nutrition_status_severely_underweight'), weighed=Sum('nutrition_status_weighed'), normal=Sum('nutrition_status_normal'), total=Sum('wer_eligible'), ).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: { 'severely_underweight': 0, 'moderately_underweight': 0, 'weighed': 0, 'normal': 0, 'total': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: weighed = row['weighed'] total = row['total'] name = row['%s_name' % loc_level] result_set.add(name) severely_underweight = row['severely_underweight'] moderately_underweight = row['moderately_underweight'] normal = row['normal'] tooltips_data[name]['severely_underweight'] += severely_underweight tooltips_data[name]['moderately_underweight'] += moderately_underweight tooltips_data[name]['weighed'] += (weighed or 0) tooltips_data[name]['normal'] += normal tooltips_data[name]['total'] += (total or 0) chart_data['blue'].append([ name, ((moderately_underweight or 0) + (severely_underweight or 0)) / float(weighed or 1) ]) 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']) return { "tooltips_data": dict(tooltips_data), "info": underweight_children_help_text(age_label="0-5 years", html=True), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_prevalence_of_severe_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( moderate=Sum('wasting_moderate'), severe=Sum('wasting_severe'), valid=Sum('height_eligible'), normal=Sum('wasting_normal'), 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: 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: valid = row['valid'] name = row['%s_name' % loc_level] result_set.add(name) severe = row['severe'] moderate = row['moderate'] normal = row['normal'] total_measured = row['total_measured'] tooltips_data[name]['severe'] += (severe or 0) tooltips_data[name]['moderate'] += (moderate or 0) tooltips_data[name]['total'] += (valid or 0) tooltips_data[name]['normal'] += normal tooltips_data[name]['total_measured'] += total_measured value = ((moderate or 0) + (severe or 0)) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(( "Percentage of children between 6 - 60 months enrolled for ICDS services with " "weight-for-height below -3 standard deviations of the WHO Child Growth Standards median." "<br/><br/>" "Severe Acute Malnutrition (SAM) or wasting in children is a symptom of acute " "undernutrition usually as a consequence of insufficient food intake or a high " "incidence of infectious diseases." )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_adult_weight_scale_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter( **config ).values( *group_by ).annotate( in_month=Sum('infra_adult_weighing_scale'), all=Sum('num_awc_infra_last_update'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['all'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = { 'in_month': in_month or 0, 'all': valid or 0 } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": awcs_reported_weighing_scale_mother_and_child_help_text(), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_clean_water_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggAwcMonthly.objects.filter( **config ).values( *group_by ).annotate( in_month=Sum('infra_clean_water'), all=Sum('num_awc_infra_last_update') ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['all'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = { 'in_month': in_month or 0, 'all': valid or 0 } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(( "Of the AWCs that have submitted an Infrastructure Details form, the percentage of AWCs that " "reported having a source of clean drinking water. " )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_exclusive_breastfeeding_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( in_month=Sum('ebf_in_month'), eligible=Sum('ebf_eligible'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'children': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'children': in_month or 0, 'all': valid or 0} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value in_month = row['in_month'] value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Percentage of infants 0-6 months of age who are fed exclusively with breast milk. " "<br/><br/>" "An infant is exclusively breastfed if they recieve only breastmilk with no additional food, " "liquids (even water) ensuring optimal nutrition and growth between 0 - 6 months" )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_awc_daily_status_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] date = datetime(*config['month']) del config['month'] def get_data_for(filters): queryset = AggAwcDailyView.objects.filter( **filters ).values( *group_by ).annotate( in_day=Sum('daily_attendance_open'), all=Sum('num_launched_awcs'), ).order_by('%s_name' % loc_level) if not show_test: queryset = apply_exclude(domain, queryset) return queryset chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_day': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() config['date'] = date.date() sector_data = None while sector_data is None or (not sector_data and config['date'].day != 1): sector_data = get_data_for(config) config['date'] -= relativedelta(days=1) for row in sector_data: valid = row['all'] name = row['%s_name' % loc_level] result_set.add(name) in_day = row['in_day'] row_values = { 'in_day': in_day or 0, 'all': valid or 0 } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_day or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(( "Of the total number of AWCs, the percentage of AWCs that were open yesterday." )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_newborn_with_low_birth_weight_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( low_birth=Sum('low_birth_weight_in_month'), in_month=Sum('weighed_and_born_in_month'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'low_birth': 0, }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] name = row['%s_name' % loc_level] result_set.add(name) low_birth = row['low_birth'] or 0 value = low_birth / float(in_month or 1) tooltips_data[name]['low_birth'] += low_birth tooltips_data[name]['in_month'] += (in_month or 0) 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Percentage of newborns with born with birth weight less than 2500 grams." "<br/><br/>" "Newborns with Low Birth Weight are closely associated with foetal and neonatal " "mortality and morbidity, inhibited growth and cognitive development, and chronic " "diseases later in life")), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
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_immunization_coverage_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( in_month=Sum('fully_immunized_on_time') + Sum('fully_immunized_late'), eligible=Sum('fully_immunized_eligible'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'children': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'children': in_month or 0, 'all': valid or 0} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Of the total number of children enrolled for Anganwadi Services who are over a year old, the " "percentage of children who have received the complete immunization as per the National Immunization " "Schedule of India that is required by age 1." "<br/><br/>" "This includes the following immunizations:<br/>" "If Pentavalent path: Penta1/2/3, OPV1/2/3, BCG, Measles, VitA1<br/>" "If DPT/HepB path: DPT1/2/3, HepB1/2/3, OPV1/2/3, BCG, Measles, VitA1" )), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_early_initiation_breastfeeding_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( birth=Sum('bf_at_birth'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'birth': 0, }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] name = row['%s_name' % loc_level] result_set.add(name) birth = row['birth'] value = (birth or 0) / float(in_month or 1) tooltips_data[name]['birth'] += birth tooltips_data[name]['in_month'] += (in_month or 0) 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']) return { "tooltips_data": dict(tooltips_data), "info": early_initiation_breastfeeding_help_text(html=True), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_lactating_enrolled_women_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggCcsRecordMonthly.objects.filter( **config ).values( *group_by ).annotate( valid=Sum('lactating'), all=Sum('lactating_all') ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [] } tooltips_data = defaultdict(lambda: { 'valid': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['valid'] or 0 all_lactating = row['all'] or 0 name = row['%s_name' % loc_level] result_set.add(name) row_values = { 'valid': valid, 'all': all_lactating } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value chart_data['blue'].append([ name, valid ]) 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']) return { "tooltips_data": dict(tooltips_data), "format": "number", "info": percent_lactating_women_enrolled_help_text(), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_early_initiation_breastfeeding_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( birth=Sum('bf_at_birth'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'birth': 0, }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] name = row['%s_name' % loc_level] result_set.add(name) birth = row['birth'] value = (birth or 0) / float(in_month or 1) tooltips_data[name]['birth'] += birth tooltips_data[name]['in_month'] += (in_month or 0) 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']) return { "tooltips_data": dict(tooltips_data), "info": early_initiation_breastfeeding_help_text(html=True), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_children_initiated_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( in_month=Sum('cf_initiation_in_month'), eligible=Sum('cf_initiation_eligible'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: {'children': 0, 'all': 0}) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = {'children': in_month or 0, 'all': valid or 0} for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Percentage of children between 6 - 8 months given timely introduction to solid, " "semi-solid or soft food.")), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_prevalence_of_undernutrition_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter(**config).values( *group_by).annotate( moderately_underweight=Sum( 'nutrition_status_moderately_underweight'), severely_underweight=Sum('nutrition_status_severely_underweight'), weighed=Sum('nutrition_status_weighed'), normal=Sum('nutrition_status_normal'), total=Sum('wer_eligible'), ).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: { 'severely_underweight': 0, 'moderately_underweight': 0, 'weighed': 0, 'normal': 0, 'total': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: weighed = row['weighed'] total = row['total'] name = row['%s_name' % loc_level] result_set.add(name) severely_underweight = row['severely_underweight'] moderately_underweight = row['moderately_underweight'] normal = row['normal'] tooltips_data[name]['severely_underweight'] += severely_underweight tooltips_data[name]['moderately_underweight'] += moderately_underweight tooltips_data[name]['weighed'] += (weighed or 0) tooltips_data[name]['normal'] += normal tooltips_data[name]['total'] += (total or 0) chart_data['blue'].append([ name, ((moderately_underweight or 0) + (severely_underweight or 0)) / float(weighed or 1) ]) 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']) return { "tooltips_data": dict(tooltips_data), "info": _(("Of the total children enrolled for Anganwadi services and weighed, the percentage of children " "between 0-5 years who were moderately/severely underweight in the current month. " "<br/><br/>" "Children who are moderately or severely underweight have a higher risk of mortality. " )), "chart_data": [{ "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }] }
def get_early_initiation_breastfeeding_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( birth=Sum('bf_at_birth'), in_month=Sum('born_in_month'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'in_month': 0, 'birth': 0, }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: in_month = row['in_month'] name = row['%s_name' % loc_level] result_set.add(name) birth = row['birth'] value = (birth or 0) / float(in_month or 1) tooltips_data[name]['birth'] += birth tooltips_data[name]['in_month'] += (in_month or 0) 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']) return { "tooltips_data": dict(tooltips_data), "info": _(( "Percentage of children who were put to the breast within one hour of birth." "<br/><br/>" "Early initiation of breastfeeding ensure the newborn recieves the 'first milk' rich in " "nutrients and encourages exclusive breastfeeding practice" )), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }
def get_prevalence_of_severe_sector_data(domain, config, loc_level, location_id, show_test=False, icds_feature_flag=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( moderate=Sum(wasting_moderate_column(icds_feature_flag)), severe=Sum(wasting_severe_column(icds_feature_flag)), normal=Sum(wasting_normal_column(icds_feature_flag)), total_height_eligible=Sum('height_eligible'), total_weighed=Sum('nutrition_status_weighed'), total_measured=Sum(wfh_recorded_in_month_column(icds_feature_flag)), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) if 'age_tranche' not in config: data = data.exclude(age_tranche=72) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'severe': 0, 'moderate': 0, 'total_height_eligible': 0, 'normal': 0, 'total_weighed': 0, 'total_measured': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: total_weighed = row['total_weighed'] or 0 name = row['%s_name' % loc_level] result_set.add(name) severe = row['severe'] or 0 moderate = row['moderate'] or 0 normal = row['normal'] or 0 total_measured = row['total_measured'] or 0 total_height_eligible = row['total_height_eligible'] or 0 tooltips_data[name]['severe'] += severe tooltips_data[name]['moderate'] += moderate tooltips_data[name]['total_weighed'] += total_weighed tooltips_data[name]['normal'] += normal tooltips_data[name]['total_measured'] += total_measured tooltips_data[name]['total_height_eligible'] += total_height_eligible value = (moderate + severe) / float(total_weighed or 1) chart_data['blue'].append([ name, value ]) for sql_location in loc_children: if sql_location.name not in result_set: chart_data['blue'].append([sql_location.name, 0]) chart_data['blue'] = sorted(chart_data['blue']) gender_label, age_label, chosen_filters = chosen_filters_to_labels( config, default_interval=default_age_interval(icds_feature_flag) ) return { "tooltips_data": dict(tooltips_data), "info": _(wasting_help_text(age_label)), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_children_initiated_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( in_month=Sum('cf_initiation_in_month'), eligible=Sum('cf_initiation_eligible'), ).order_by('%s_name' % loc_level) if not show_test: data = apply_exclude(domain, data) chart_data = { 'blue': [], } tooltips_data = defaultdict(lambda: { 'children': 0, 'all': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: valid = row['eligible'] name = row['%s_name' % loc_level] result_set.add(name) in_month = row['in_month'] row_values = { 'children': in_month or 0, 'all': valid or 0 } for prop, value in six.iteritems(row_values): tooltips_data[name][prop] += value value = (in_month or 0) / float(valid 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']) return { "tooltips_data": dict(tooltips_data), "info": children_initiated_appropriate_complementary_feeding_help_text(html=True), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE }, ] }
def get_prevalence_of_undernutrition_sector_data(domain, config, loc_level, location_id, show_test=False): group_by = ['%s_name' % loc_level] config['month'] = datetime(*config['month']) data = AggChildHealthMonthly.objects.filter( **config ).values( *group_by ).annotate( moderately_underweight=Sum('nutrition_status_moderately_underweight'), severely_underweight=Sum('nutrition_status_severely_underweight'), weighed=Sum('nutrition_status_weighed'), normal=Sum('nutrition_status_normal'), total=Sum('wer_eligible'), ).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: { 'severely_underweight': 0, 'moderately_underweight': 0, 'weighed': 0, 'normal': 0, 'total': 0 }) loc_children = get_child_locations(domain, location_id, show_test) result_set = set() for row in data: weighed = row['weighed'] total = row['total'] name = row['%s_name' % loc_level] result_set.add(name) severely_underweight = row['severely_underweight'] moderately_underweight = row['moderately_underweight'] normal = row['normal'] tooltips_data[name]['severely_underweight'] += severely_underweight tooltips_data[name]['moderately_underweight'] += moderately_underweight tooltips_data[name]['weighed'] += (weighed or 0) tooltips_data[name]['normal'] += normal tooltips_data[name]['total'] += (total or 0) chart_data['blue'].append([ name, ((moderately_underweight or 0) + (severely_underweight or 0)) / float(weighed or 1) ]) 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']) return { "tooltips_data": dict(tooltips_data), "info": underweight_children_help_text(age_label="0-5 years", html=True), "chart_data": [ { "values": chart_data['blue'], "key": "", "strokeWidth": 2, "classed": "dashed", "color": MapColors.BLUE } ] }