Esempio n. 1
0
 def test_build_location_filters_for_state_MWCD(self):
     expected_output = {
         'district_id': ALL,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.state.location_id, MINISTRY_MWCD)
     self.assertDictEqual(result, expected_output)
Esempio n. 2
0
 def test_build_location_filters_for_district_without_child_MWCD(self):
     expected_output = {
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.district.location_id, MINISTRY_MWCD, with_child=False)
     self.assertDictEqual(result, expected_output)
Esempio n. 3
0
 def test_build_location_filters_for_district_MOHFW(self):
     expected_output = {
         'taluka_id': ALL,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.district.location_id, MINISTRY_MOHFW)
     self.assertDictEqual(result, expected_output)
Esempio n. 4
0
 def test_build_location_filters_for_phc_without_child_MOHFW(self):
     expected_output = {
         'phc_id': self.phc.location_id,
         'taluka_id': self.taluka.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.phc.location_id, MINISTRY_MOHFW, with_child=False)
     self.assertDictEqual(result, expected_output)
Esempio n. 5
0
 def test_build_location_filters_for_block_MWCD(self):
     expected_output = {
         'supervisor_id': ALL,
         'block_id': self.block.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.block.location_id, MINISTRY_MWCD)
     self.assertDictEqual(result, expected_output)
Esempio n. 6
0
 def test_build_location_filters_for_district_without_child_MWCD(self):
     expected_output = {
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.district.location_id,
                                     MINISTRY_MWCD,
                                     with_child=False)
     self.assertDictEqual(result, expected_output)
Esempio n. 7
0
 def test_build_location_filters_for_district_MOHFW(self):
     expected_output = {
         'taluka_id': ALL,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.district.location_id,
                                     MINISTRY_MOHFW)
     self.assertDictEqual(result, expected_output)
Esempio n. 8
0
def prepare_export_reports(domain, selected_date, next_month_start,
                           selected_location, selected_ministry,
                           beneficiary_type):
    location_filters = build_location_filters(selected_location,
                                              selected_ministry,
                                              with_child=False)
    sort_column = 'name'

    selected_date = force_to_date(selected_date)
    next_month_start = force_to_date(next_month_start)

    columns = []
    data = []

    if beneficiary_type == 'child':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('gender', 'Gender'),
            ('lastImmunizationType', 'Last Immunization Type'),
            ('lastImmunizationDate', 'Last Immunization Date'),
        )
        data = ChildQueryHelper.list(domain, next_month_start,
                                     location_filters, sort_column)
    elif beneficiary_type == 'eligible_couple':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('currentFamilyPlanningMethod', 'Current Family Planing Method'),
            ('adoptionDateOfFamilyPlaning',
             'Adoption Date Of Family Planning'),
        )
        data = EligibleCoupleQueryHelper.list(domain, selected_date,
                                              location_filters, sort_column)
        month_end = selected_date + relativedelta(months=1) - relativedelta(
            days=1)
        data = EligibleCoupleQueryHelper.update_list(data, month_end)
    elif beneficiary_type == 'pregnant_women':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('pregMonth', 'Preg. Month'),
            ('highRiskPregnancy', 'High Risk Pregnancy'),
            ('noOfAncCheckUps', 'No. Of ANC Check-Ups'),
        )
        data = PregnantWomanQueryHelper.list(domain, selected_date,
                                             location_filters, sort_column)

    export_columns = [col[1] for col in columns]

    export_data = [export_columns]
    for row in data:
        row_data = [row[col[0]] or 'N/A' for col in columns]
        export_data.append(row_data)
    return create_excel_file(domain, [[beneficiary_type, export_data]],
                             beneficiary_type, 'xlsx')
Esempio n. 9
0
 def test_build_location_filters_for_supervisor_MWCD(self):
     expected_output = {
         'awc_id': ALL,
         'supervisor_id': self.supervisor.location_id,
         'block_id': self.block.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.supervisor.location_id, MINISTRY_MWCD)
     self.assertDictEqual(result, expected_output)
Esempio n. 10
0
 def test_build_location_filters_for_phc_without_child_MOHFW(self):
     expected_output = {
         'phc_id': self.phc.location_id,
         'taluka_id': self.taluka.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.phc.location_id,
                                     MINISTRY_MOHFW,
                                     with_child=False)
     self.assertDictEqual(result, expected_output)
Esempio n. 11
0
 def test_build_location_filters_for_village_MOHFW(self):
     expected_output = {
         'village_id': self.village.location_id,
         'sc_id': self.sc.location_id,
         'phc_id': self.phc.location_id,
         'taluka_id': self.taluka.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.village.location_id, MINISTRY_MOHFW)
     self.assertDictEqual(result, expected_output)
Esempio n. 12
0
 def test_build_location_filters_for_village_MOHFW(self):
     expected_output = {
         'village_id': self.village.location_id,
         'sc_id': self.sc.location_id,
         'phc_id': self.phc.location_id,
         'taluka_id': self.taluka.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.village.location_id,
                                     MINISTRY_MOHFW)
     self.assertDictEqual(result, expected_output)
Esempio n. 13
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth'))
        selected_year = int(self.request.POST.get('selectedYear'))
        selected_date = date(selected_year, selected_month, 1)
        next_month_start = selected_date + relativedelta(months=1)
        selected_location = self.request.POST.get('selectedLocation')
        selected_ministry = self.request.POST.get('selectedMinistry')
        beneficiary_type = self.request.POST.get('selectedBeneficiaryType')
        draw = self.request.POST.get('draw', 0)
        length = int(self.request.POST.get('length', 0))
        start = int(self.request.POST.get('start', 0))
        sort_column = self.request.POST.get('sortColumn', 'name')
        sort_column_dir = self.request.POST.get('sortColumnDir', 'asc')

        location_filters = build_location_filters(selected_location,
                                                  selected_ministry,
                                                  with_child=False)
        sort_column_with_dir = sort_column
        if sort_column_dir == 'desc':
            sort_column_with_dir = '-' + sort_column
        data = []
        if beneficiary_type == 'child':
            data = ChildQueryHelper.list(request.domain, next_month_start,
                                         location_filters,
                                         sort_column_with_dir)
        elif beneficiary_type == 'eligible_couple':
            data = EligibleCoupleQueryHelper.list(request.domain,
                                                  selected_date,
                                                  location_filters,
                                                  sort_column_with_dir)
        elif beneficiary_type == 'pregnant_women':
            sort_column_with_dir = '"%s" %s' % (sort_column, sort_column_dir)
            data = PregnantWomanQueryHelper.list(request.domain, selected_date,
                                                 location_filters,
                                                 sort_column_with_dir)
        if data:
            number_of_data = len(data)
            data = data[start:start + length]
        else:
            number_of_data = 0
        if beneficiary_type == 'eligible_couple':
            month_end = date(selected_year, selected_month, 1) + relativedelta(
                months=1) - relativedelta(days=1)
            data = EligibleCoupleQueryHelper.update_list(data, month_end)
        data = list(data)
        return JsonResponse(
            data={
                'rows': data,
                'draw': draw,
                'recordsTotal': number_of_data,
                'recordsFiltered': number_of_data,
            })
Esempio n. 14
0
def prepare_export_reports(domain, selected_date, next_month_start, selected_location,
                           selected_ministry, beneficiary_type):
    location_filters = build_location_filters(selected_location, selected_ministry, with_child=False)
    sort_column = 'name'

    selected_date = force_to_date(selected_date)
    next_month_start = force_to_date(next_month_start)

    columns = []
    data = []

    if beneficiary_type == 'child':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('gender', 'Gender'),
            ('lastImmunizationType', 'Last Immunization Type'),
            ('lastImmunizationDate', 'Last Immunization Date'),
        )
        data = ChildQueryHelper.list(domain, next_month_start, location_filters, sort_column)
    elif beneficiary_type == 'eligible_couple':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('currentFamilyPlanningMethod', 'Current Family Planing Method'),
            ('adoptionDateOfFamilyPlaning', 'Adoption Date Of Family Planning'),
        )
        data = EligibleCoupleQueryHelper.list(domain, selected_date, location_filters, sort_column)
    elif beneficiary_type == 'pregnant_women':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('pregMonth', 'Preg. Month'),
            ('highRiskPregnancy', 'High Risk Pregnancy'),
            ('noOfAncCheckUps', 'No. Of ANC Check-Ups'),
        )
        data = PregnantWomanQueryHelper.list(domain, selected_date, location_filters, sort_column)

    export_columns = [col[1] for col in columns]

    export_data = [export_columns]
    for row in data:
        row_data = [row[col[0]] or 'N/A' for col in columns]
        export_data.append(row_data)
    return create_excel_file(
        domain,
        [[beneficiary_type, export_data]],
        beneficiary_type,
        'xlsx'
    )
Esempio n. 15
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth'))
        selected_year = int(self.request.POST.get('selectedYear'))
        selected_date = date(selected_year, selected_month, 1)
        next_month_start = selected_date + relativedelta(months=1)
        selected_location = self.request.POST.get('selectedLocation')
        selected_ministry = self.request.POST.get('selectedMinistry')
        beneficiary_type = self.request.POST.get('selectedBeneficiaryType')
        draw = self.request.POST.get('draw', 0)
        length = int(self.request.POST.get('length', 0))
        start = int(self.request.POST.get('start', 0))
        sort_column = self.request.POST.get('sortColumn', 'name')
        sort_column_dir = self.request.POST.get('sortColumnDir', 'asc')

        location_filters = build_location_filters(selected_location, selected_ministry, with_child=False)
        sort_column_with_dir = sort_column
        if sort_column_dir == 'desc':
            sort_column_with_dir = '-' + sort_column
        data = []
        if beneficiary_type == 'child':
            data = ChildQueryHelper.list(request.domain, next_month_start, location_filters, sort_column_with_dir)
        elif beneficiary_type == 'eligible_couple':
            sort_column_with_dir = '"%s" %s' % (sort_column, sort_column_dir)
            data = EligibleCoupleQueryHelper.list(
                request.domain,
                selected_date,
                location_filters,
                sort_column_with_dir
            )
        elif beneficiary_type == 'pregnant_women':
            sort_column_with_dir = '"%s" %s' % (sort_column, sort_column_dir)
            data = PregnantWomanQueryHelper.list(
                request.domain,
                selected_date,
                location_filters,
                sort_column_with_dir
            )
        if data:
            number_of_data = len(data)
            data = data[start:start + length]
        else:
            number_of_data = 0
        data = list(data)
        return JsonResponse(data={
            'rows': data,
            'draw': draw,
            'recordsTotal': number_of_data,
            'recordsFiltered': number_of_data,
        })
Esempio n. 16
0
 def test_build_location_filters_for_national_without_child_MWCD(self):
     expected_output = {}
     result = build_location_filters('', MINISTRY_MWCD, with_child=False)
     self.assertDictEqual(result, expected_output)
Esempio n. 17
0
 def test_build_location_filters_for_national_MWCD(self):
     expected_output = {
         'state_id': ALL,
     }
     result = build_location_filters('', MINISTRY_MWCD)
     self.assertDictEqual(result, expected_output)
Esempio n. 18
0
 def test_build_location_filters_for_national_without_child_MWCD(self):
     expected_output = {}
     result = build_location_filters('', MINISTRY_MWCD, with_child=False)
     self.assertDictEqual(result, expected_output)
Esempio n. 19
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth'))
        selected_year = int(self.request.POST.get('selectedYear'))
        selected_location = self.request.POST.get('selectedLocation')
        selected_date = date(selected_year, selected_month, 1)
        selected_ministry = self.request.POST.get('selectedMinistry')
        prev_month = date(selected_year, selected_month, 1) - relativedelta(months=1)

        location_filters = build_location_filters(selected_location, selected_ministry)
        data = get_location_model_for_ministry(selected_ministry).objects.filter(
            (Q(month=selected_date) | Q(month=prev_month)),
            domain=self.request.domain,
            **location_filters
        ).order_by('month').values()

        vals = {
            val['month']: val
            for val in data
        }
        data = vals.get(selected_date, {})
        prev_month_data = vals.get(prev_month, {})

        return JsonResponse(data={'data': [
            [
                {
                    'indicator': INDICATOR_LIST['registered_eligible_couples'],
                    'format': NUMERIC,
                    'color': COLORS['violet'],
                    'value': data.get('registered_eligible_couples', 0),
                    'past_month_value': prev_month_data.get('registered_eligible_couples', 0)
                },
                {
                    'indicator': INDICATOR_LIST['registered_pregnancies'],
                    'format': NUMERIC,
                    'color': COLORS['blue'],
                    'value': data.get('registered_pregnancies', 0),
                    'past_month_value': prev_month_data.get('registered_pregnancies', 0)
                },
                {
                    'indicator': INDICATOR_LIST['registered_children'],
                    'format': NUMERIC,
                    'color': COLORS['orange'],
                    'value': data.get('registered_children', 0),
                    'past_month_value': prev_month_data.get('registered_children', 0)
                }
            ],
            [
                {
                    'indicator': INDICATOR_LIST['couples_family_planning'],
                    'format': PERCENT,
                    'color': COLORS['aqua'],
                    'value': data.get('eligible_couples_using_fp_method', 0),
                    'total': data.get('registered_eligible_couples', 0),
                    'past_month_value': prev_month_data.get('eligible_couples_using_fp_method', 0),
                },
                {
                    'indicator': INDICATOR_LIST['high_risk_pregnancies'],
                    'format': PERCENT,
                    'color': COLORS['darkorange'],
                    'value': data.get('high_risk_pregnancies', 0),
                    'total': data.get('registered_pregnancies', 0),
                    'past_month_value': prev_month_data.get('high_risk_pregnancies', 0),
                },
                {
                    'indicator': INDICATOR_LIST['institutional_deliveries'],
                    'format': PERCENT,
                    'color': COLORS['mediumblue'],
                    'value': data.get('institutional_deliveries', 0),
                    'total': data.get('total_deliveries', 0),
                    'past_month_value': prev_month_data.get('institutional_deliveries', 0),
                }
            ]
        ]})
Esempio n. 20
0
 def test_build_location_filters_for_national_MWCD(self):
     expected_output = {
         'state_id': ALL,
     }
     result = build_location_filters('', MINISTRY_MWCD)
     self.assertDictEqual(result, expected_output)
Esempio n. 21
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth'))
        selected_year = int(self.request.POST.get('selectedYear'))
        selected_location = self.request.POST.get('selectedLocation')
        selected_date = date(selected_year, selected_month, 1)
        selected_ministry = self.request.POST.get('selectedMinistry')
        prev_month = date(selected_year, selected_month,
                          1) - relativedelta(months=1)

        location_filters = build_location_filters(selected_location,
                                                  selected_ministry)
        data = get_location_model_for_ministry(
            selected_ministry).objects.filter(
                (Q(month=selected_date) | Q(month=prev_month)),
                domain=self.request.domain,
                **location_filters).order_by('month').values()

        vals = {val['month']: val for val in data}
        data = vals.get(selected_date, {})
        prev_month_data = vals.get(prev_month, {})

        return JsonResponse(
            data={
                'data': [[{
                    'indicator':
                    INDICATOR_LIST['registered_eligible_couples'],
                    'format':
                    NUMERIC,
                    'color':
                    COLORS['violet'],
                    'value':
                    data.get('registered_eligible_couples', 0),
                    'past_month_value':
                    prev_month_data.get('registered_eligible_couples', 0)
                }, {
                    'indicator':
                    INDICATOR_LIST['registered_pregnancies'],
                    'format':
                    NUMERIC,
                    'color':
                    COLORS['blue'],
                    'value':
                    data.get('registered_pregnancies', 0),
                    'past_month_value':
                    prev_month_data.get('registered_pregnancies', 0)
                }, {
                    'indicator':
                    INDICATOR_LIST['registered_children'],
                    'format':
                    NUMERIC,
                    'color':
                    COLORS['orange'],
                    'value':
                    data.get('registered_children', 0),
                    'past_month_value':
                    prev_month_data.get('registered_children', 0)
                }],
                         [{
                             'indicator':
                             INDICATOR_LIST['couples_family_planning'],
                             'format':
                             PERCENT,
                             'color':
                             COLORS['aqua'],
                             'value':
                             data.get('eligible_couples_using_fp_method', 0),
                             'total':
                             data.get('registered_eligible_couples', 0),
                             'past_month_value':
                             prev_month_data.get(
                                 'eligible_couples_using_fp_method', 0),
                         }, {
                             'indicator':
                             INDICATOR_LIST['high_risk_pregnancies'],
                             'format':
                             PERCENT,
                             'color':
                             COLORS['darkorange'],
                             'value':
                             data.get('high_risk_pregnancies', 0),
                             'total':
                             data.get('registered_pregnancies', 0),
                             'past_month_value':
                             prev_month_data.get('high_risk_pregnancies', 0),
                         }, {
                             'indicator':
                             INDICATOR_LIST['institutional_deliveries'],
                             'format':
                             PERCENT,
                             'color':
                             COLORS['mediumblue'],
                             'value':
                             data.get('institutional_deliveries', 0),
                             'total':
                             data.get('total_deliveries', 0),
                             'past_month_value':
                             prev_month_data.get('institutional_deliveries',
                                                 0),
                         }]]
            })
Esempio n. 22
0
 def test_build_location_filters_for_state_without_child_MOHFW(self):
     expected_output = {
         'state_id': self.state.location_id,
     }
     result = build_location_filters(self.state.location_id, MINISTRY_MOHFW, with_child=False)
     self.assertDictEqual(result, expected_output)