Exemplo n.º 1
0
 def _map_filter_name_to_sql_filter(self, filter_name):
     return {
         'unweighed':
         RawFilter('recorded_weight IS NULL'),
         'umeasured':
         RawFilter('recorded_height IS NULL'),
         'severely_underweight':
         RawFilter(
             "current_month_nutrition_status = 'severely_underweight'"),
         'moderately_underweight':
         RawFilter(
             "current_month_nutrition_status = 'moderately_underweight'"),
         'normal_wfa':
         RawFilter("current_month_nutrition_status = 'normal'"),
         'severely_stunted':
         RawFilter("{} = 'severe'".format(
             current_month_stunting_column(self.beta))),
         'moderately_stunted':
         RawFilter("{} = 'moderate'".format(
             current_month_stunting_column(self.beta))),
         'normal_hfa':
         RawFilter("{} = 'normal'".format(
             current_month_stunting_column(self.beta))),
         'severely_wasted':
         RawFilter("{} = 'severe'".format(
             current_month_wasting_column(self.beta))),
         'moderately_wasted':
         RawFilter("{} = 'moderate'".format(
             current_month_wasting_column(self.beta))),
         'normal_wfh':
         RawFilter("{} = 'normal'".format(
             current_month_wasting_column(self.beta))),
     }[filter_name]
Exemplo n.º 2
0
 def _map_filter_name_to_sql_filter(self, filter_name):
     return {
         'unweighed': RawFilter('recorded_weight IS NULL'),
         'umeasured': RawFilter('recorded_height IS NULL'),
         'severely_underweight': RawFilter("current_month_nutrition_status = 'severely_underweight'"),
         'moderately_underweight': RawFilter("current_month_nutrition_status = 'moderately_underweight'"),
         'normal_wfa': RawFilter("current_month_nutrition_status = 'normal'"),
         'severely_stunted': RawFilter("{} = 'severe'".format(current_month_stunting_column(self.beta))),
         'moderately_stunted': RawFilter("{} = 'moderate'".format(current_month_stunting_column(self.beta))),
         'normal_hfa': RawFilter("{} = 'normal'".format(current_month_stunting_column(self.beta))),
         'severely_wasted': RawFilter("{} = 'severe'".format(current_month_wasting_column(self.beta))),
         'moderately_wasted': RawFilter("{} = 'moderate'".format(current_month_wasting_column(self.beta))),
         'normal_wfh': RawFilter("{} = 'normal'".format(current_month_wasting_column(self.beta))),
     }[filter_name]
Exemplo n.º 3
0
 def base_data(row_data):
     return dict(
         case_id=row_data.case_id,
         person_name=row_data.person_name,
         dob=row_data.dob,
         age=calculate_date_for_age(row_data.dob,
                                    datetime(*month).date()),
         fully_immunized='Yes' if row_data.fully_immunized else 'No',
         age_in_months=row_data.age_in_months,
         current_month_nutrition_status=get_status(
             row_data.current_month_nutrition_status, 'underweight',
             'Normal weight for age'),
         recorded_weight=row_data.recorded_weight or 0,
         recorded_height=row_data.recorded_height or 0,
         current_month_stunting=get_status(
             getattr(row_data,
                     current_month_stunting_column(icds_features_flag)),
             'stunted',
             'Normal height for age',
             data_entered=True if row_data.recorded_height else False),
         current_month_wasting=get_status(
             getattr(row_data,
                     current_month_wasting_column(icds_features_flag)),
             'wasted',
             'Normal weight for height',
             data_entered=True if row_data.recorded_height
             and row_data.recorded_weight else False),
         pse_days_attended=row_data.pse_days_attended)
Exemplo n.º 4
0
    def get_columns_by_loc_level(self):
        selected_month = self.config['month']

        def test_fucntion(x):
            return "%.2f" % x if x else "Data Not Entered"

        columns = [
            DatabaseColumn('Child Name',
                           SimpleColumn('person_name'),
                           slug='person_name'),
            DatabaseColumn('Date of Birth', SimpleColumn('dob'), slug='dob'),
            DatabaseColumn('Current Age (as of {})'.format(
                selected_month.isoformat()),
                           AliasColumn('dob'),
                           format_fn=lambda x: calculate_date_for_age(
                               x, self.config['month']),
                           slug='current_age'),
            DatabaseColumn('Sex ', SimpleColumn('sex'), slug='sex'),
            ICDSDatabaseColumn('1 Year Immunizations Complete',
                               SimpleColumn('fully_immunized'),
                               format_fn=lambda x: 'Yes' if x else 'No'),
            DatabaseColumn('Month for data shown',
                           SimpleColumn('month'),
                           slug='month'),
            DatabaseColumn('Weight Recorded (in Month)',
                           SimpleColumn('recorded_weight'),
                           format_fn=test_fucntion,
                           slug='recorded_weight'),
            DatabaseColumn('Height Recorded (in Month)',
                           SimpleColumn('recorded_height'),
                           format_fn=test_fucntion,
                           slug='recorded_height'),
            DatabaseColumn(
                'Weight-for-Age Status (in Month)',
                SimpleColumn('current_month_nutrition_status'),
                format_fn=lambda x: get_status(x, 'underweight',
                                               'Normal weight for age', True),
                slug='current_month_nutrition_status'),
            DatabaseColumn('Weight-for-Height Status (in Month)',
                           SimpleColumn(current_month_wasting_column(
                               self.beta)),
                           format_fn=lambda x: get_status(
                               x, 'wasted', 'Normal weight for height', True),
                           slug="current_month_wasting"),
            DatabaseColumn('Height-for-Age status (in Month)',
                           SimpleColumn(
                               current_month_stunting_column(self.beta)),
                           format_fn=lambda x: get_status(
                               x, 'stunted', 'Normal height for age', True),
                           slug="current_month_stunting"),
            DatabaseColumn('Days attended PSE (as of {})'.format(
                selected_month.isoformat()),
                           SimpleColumn('pse_days_attended'),
                           slug="pse_days_attended"),
        ]
        return columns
 def _fetch_data(filters, order_by, case_by_grouping=False):
     query_set = ChildHealthMonthlyView.objects.filter(
         **filters).order_by(*order_by)
     data_month = query_set.values(
         'state_name', 'district_name', 'block_name', 'supervisor_name',
         'awc_name', 'awc_site_code', 'person_name', 'dob',
         'mother_name', 'mother_phone_number', 'pse_days_attended',
         'lunch_count', 'current_month_nutrition_status',
         current_month_wasting_column(self.beta),
         current_month_stunting_column(self.beta), 'case_id')
     if case_by_grouping is True:
         data_month = {item['case_id']: item for item in data_month}
     return data_month
    def get_excel_data(self, location):
        def _check_case_presence(case_id, column, data_dict):
            return data_dict[case_id][column] if case_id in data_dict.keys(
            ) else "N/A"

        def _fetch_data(filters, order_by, case_by_grouping=False):
            query_set = ChildHealthMonthlyView.objects.filter(
                **filters).order_by(*order_by)
            data_month = query_set.values(
                'state_name', 'district_name', 'block_name', 'supervisor_name',
                'awc_name', 'awc_site_code', 'person_name', 'dob',
                'mother_name', 'mother_phone_number', 'pse_days_attended',
                'lunch_count', 'current_month_nutrition_status',
                current_month_wasting_column(self.beta),
                current_month_stunting_column(self.beta), 'case_id')
            if case_by_grouping is True:
                data_month = {item['case_id']: item for item in data_month}
            return data_month

        filters = {
            "month": self.config['month'],
            "age_in_months__lte": 72,
            "valid_in_month": 1
        }
        initial_month = self.config['month']

        if self.loc_level == 5:
            filters['awc_id'] = location
            order_by = ('person_name', )
        elif self.loc_level == 4:
            filters['supervisor_id'] = location
            order_by = ('awc_name', 'person_name')
        elif self.loc_level == 3:
            filters['block_id'] = location
            order_by = ('supervisor_name', 'awc_name', 'person_name')
        elif self.loc_level == 2:
            filters['district_id'] = location
            order_by = ('block_name', 'supervisor_name', 'awc_name',
                        'person_name')

        data_month_3 = _fetch_data(filters, order_by)
        filters["month"] = initial_month - relativedelta(months=1)
        data_month_2 = _fetch_data(filters, order_by, True)
        filters["month"] = initial_month - relativedelta(months=2)
        data_month_1 = _fetch_data(filters, order_by, True)
        filters["month"] = initial_month
        month_1 = (initial_month -
                   relativedelta(months=2)).strftime('%Y-%m-%d')
        month_2 = (initial_month -
                   relativedelta(months=1)).strftime('%Y-%m-%d')
        month_3 = initial_month.strftime('%Y-%m-%d')

        headers = [
            'State', 'District', 'Block', 'Sector', 'Awc Name', 'Child', 'Age',
            'Mother Name', 'Mother Phone Number', f'PSE_{month_1}',
            f'PSE_{month_2}', f'PSE_{month_3}', f'SN_{month_1}',
            f'SN_{month_2}', f'SN_{month_3}', f'Stunting_{month_1}',
            f'Stunting_{month_2}', f'Stunting_{month_3}', f'Wasting_{month_1}',
            f'Wasting_{month_2}', f'Wasting_{month_3}',
            f'underweight_{month_1}', f'underweight_{month_2}',
            f'underweight_{month_3}'
        ]

        excel_rows = [headers]

        for row in data_month_3:
            row_data = [
                row['state_name'], row['district_name'], row['block_name'],
                row['supervisor_name'], row['awc_name'], row['person_name'],
                calculate_date_for_age(row['dob'],
                                       initial_month), row['mother_name'],
                phone_number_function(row['mother_phone_number']),
                _check_case_presence(row['case_id'], 'pse_days_attended',
                                     data_month_1),
                _check_case_presence(row['case_id'], 'pse_days_attended',
                                     data_month_2), row['pse_days_attended'],
                _check_case_presence(row['case_id'], 'lunch_count',
                                     data_month_1),
                _check_case_presence(row['case_id'], 'lunch_count',
                                     data_month_2), row['lunch_count'],
                get_status(
                    _check_case_presence(
                        row['case_id'],
                        current_month_stunting_column(self.beta),
                        data_month_1), 'stunted', 'Normal height for age',
                    True),
                get_status(
                    _check_case_presence(
                        row['case_id'],
                        current_month_stunting_column(self.beta),
                        data_month_2), 'stunted', 'Normal height for age',
                    True),
                get_status(row[current_month_stunting_column(self.beta)],
                           'stunted', 'Normal height for age', True),
                get_status(
                    _check_case_presence(
                        row['case_id'],
                        current_month_wasting_column(self.beta), data_month_1),
                    'wasted', 'Normal weight for height', True),
                get_status(
                    _check_case_presence(
                        row['case_id'],
                        current_month_wasting_column(self.beta), data_month_2),
                    'wasted', 'Normal weight for height', True),
                get_status(row[current_month_wasting_column(self.beta)],
                           'wasted', 'Normal weight for height', True),
                get_status(
                    _check_case_presence(row['case_id'],
                                         'current_month_nutrition_status',
                                         data_month_1), 'underweight',
                    'Normal weight for age', True),
                get_status(
                    _check_case_presence(row['case_id'],
                                         'current_month_nutrition_status',
                                         data_month_2), 'underweight',
                    'Normal weight for age', True),
                get_status(row['current_month_nutrition_status'],
                           'underweight', 'Normal weight for age', True)
            ]
            excel_rows.append(row_data)
        filters = [['Generated at', india_now()]]
        if location:
            locs = SQLLocation.objects.get(location_id=location).get_ancestors(
                include_self=True)
            for loc in locs:
                filters.append([loc.location_type.name.title(), loc.name])

        date = self.config['month']
        filters.append(['Month', date.strftime("%B")])
        filters.append(['Year', date.year])

        return [[self.title, excel_rows], ['Export Info', filters]]
Exemplo n.º 7
0
    def get_columns_by_loc_level(self):
        selected_month = self.config['month']

        def test_fucntion(x):
            return format_decimal(x) if x else DATA_NOT_ENTERED

        columns = [
            DatabaseColumn('AWC Name',
                           SimpleColumn('awc_name'),
                           slug='awc_name'),
            DatabaseColumn('AWC Site Code',
                           SimpleColumn('awc_site_code'),
                           slug='awc_site_code'),
            DatabaseColumn('Supervisor Name',
                           SimpleColumn('supervisor_name'),
                           slug='supervisor_name'),
            DatabaseColumn('Block Name',
                           SimpleColumn('block_name'),
                           slug='block_name'),
            DatabaseColumn('AWW Phone Number',
                           SimpleColumn('aww_phone_number'),
                           format_fn=phone_number_function,
                           slug='aww_phone_number'),
            DatabaseColumn('Mother Phone Number',
                           SimpleColumn('mother_phone_number'),
                           format_fn=phone_number_function,
                           slug='mother_phone_number'),
            DatabaseColumn('Child Name',
                           SimpleColumn('person_name'),
                           slug='person_name'),
            DatabaseColumn('Date of Birth', SimpleColumn('dob'), slug='dob'),
            DatabaseColumn('Current Age (as of {})'.format(
                selected_month.isoformat()),
                           AliasColumn('dob'),
                           format_fn=lambda x: calculate_date_for_age(
                               x, self.config['month']),
                           slug='current_age'),
            DatabaseColumn('Sex ', SimpleColumn('sex'), slug='sex'),
            ICDSDatabaseColumn('1 Year Immunizations Complete',
                               SimpleColumn('fully_immunized'),
                               format_fn=lambda x: 'Yes' if x else 'No'),
            DatabaseColumn('Month for data shown',
                           SimpleColumn('month'),
                           slug='month'),
            DatabaseColumn('Weight Recorded (in Month)',
                           SimpleColumn('recorded_weight'),
                           format_fn=test_fucntion,
                           slug='recorded_weight'),
            DatabaseColumn('Height Recorded (in Month)',
                           SimpleColumn('recorded_height'),
                           format_fn=test_fucntion,
                           slug='recorded_height'),
            DatabaseColumn(
                'Weight-for-Age Status (in Month)',
                SimpleColumn('current_month_nutrition_status'),
                format_fn=lambda x: get_status(x, 'underweight',
                                               'Normal weight for age', True),
                slug='current_month_nutrition_status'),
            DatabaseColumn('Weight-for-Height Status (in Month)',
                           SimpleColumn(current_month_wasting_column(
                               self.beta)),
                           format_fn=lambda x: get_status(
                               x, 'wasted', 'Normal weight for height', True),
                           slug="current_month_wasting_v2"),
            DatabaseColumn('Height-for-Age status (in Month)',
                           SimpleColumn(
                               current_month_stunting_column(self.beta)),
                           format_fn=lambda x: get_status(
                               x, 'stunted', 'Normal height for age', True),
                           slug="current_month_stunting_v2"),
            DatabaseColumn('Days attended PSE (as of {})'.format(
                selected_month.isoformat()),
                           SimpleColumn('pse_days_attended'),
                           slug="pse_days_attended"),
        ]
        return columns
Exemplo n.º 8
0
    def get_columns_by_loc_level(self):
        selected_month = self.config['month']

        def test_fucntion(x):
            return format_decimal(x) if x else DATA_NOT_ENTERED

        columns = [
            DatabaseColumn(
                'AWC Name',
                SimpleColumn('awc_name'),
                slug='awc_name'
            ),
            DatabaseColumn(
                'AWC Site Code',
                SimpleColumn('awc_site_code'),
                slug='awc_site_code'
            ),
            DatabaseColumn(
                'Supervisor Name',
                SimpleColumn('supervisor_name'),
                slug='supervisor_name'
            ),
            DatabaseColumn(
                'Block Name',
                SimpleColumn('block_name'),
                slug='block_name'
            ),
            DatabaseColumn(
                'AWW Phone Number',
                SimpleColumn('aww_phone_number'),
                format_fn=phone_number_function,
                slug='aww_phone_number'
            ),
            DatabaseColumn(
                'Mother Phone Number',
                SimpleColumn('mother_phone_number'),
                format_fn=phone_number_function,
                slug='mother_phone_number'
            ),
            DatabaseColumn(
                'Child Name',
                SimpleColumn('person_name'),
                slug='person_name'
            ),
            DatabaseColumn(
                'Date of Birth',
                SimpleColumn('dob'),
                slug='dob'
            ),
            DatabaseColumn(
                'Current Age (as of {})'.format(selected_month.isoformat()),
                AliasColumn('dob'),
                format_fn=lambda x: calculate_date_for_age(x, self.config['month']),
                slug='current_age'
            ),
            DatabaseColumn(
                'Sex ',
                SimpleColumn('sex'),
                slug='sex'
            ),
            ICDSDatabaseColumn(
                '1 Year Immunizations Complete',
                SimpleColumn('fully_immunized'),
                format_fn=lambda x: 'Yes' if x else 'No'
            ),
            DatabaseColumn(
                'Month for data shown',
                SimpleColumn('month'),
                slug='month'
            ),
            DatabaseColumn(
                'Weight Recorded (in Month)',
                SimpleColumn('recorded_weight'),
                format_fn=test_fucntion,
                slug='recorded_weight'
            ),
            DatabaseColumn(
                'Height Recorded (in Month)',
                SimpleColumn('recorded_height'),
                format_fn=test_fucntion,
                slug='recorded_height'
            ),
            DatabaseColumn(
                'Weight-for-Age Status (in Month)',
                SimpleColumn('current_month_nutrition_status'),
                format_fn=lambda x: get_status(
                    x,
                    'underweight',
                    'Normal weight for age',
                    True
                ),
                slug='current_month_nutrition_status'
            ),
            DatabaseColumn(
                'Weight-for-Height Status (in Month)',
                SimpleColumn(current_month_wasting_column(self.beta)),
                format_fn=lambda x: get_status(
                    x,
                    'wasted',
                    'Normal weight for height',
                    True
                ),
                slug="current_month_wasting_v2"
            ),
            DatabaseColumn(
                'Height-for-Age status (in Month)',
                SimpleColumn(current_month_stunting_column(self.beta)),
                format_fn=lambda x: get_status(
                    x,
                    'stunted',
                    'Normal height for age',
                    True
                ),
                slug="current_month_stunting_v2"
            ),
            DatabaseColumn(
                'Days attended PSE (as of {})'.format(selected_month.isoformat()),
                SimpleColumn('pse_days_attended'),
                slug="pse_days_attended"
            ),
        ]
        return columns