示例#1
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')
示例#2
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,
            })
示例#3
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'
    )
示例#4
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,
        })
示例#5
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth', 0))
        selected_year = int(self.request.POST.get('selectedYear', 0))
        month_end = date(selected_year, selected_month,
                         1) + relativedelta(months=1) - relativedelta(days=1)
        section = self.request.POST.get('section', '')
        sub_section = self.request.POST.get('subsection', '')
        beneficiary_id = self.request.POST.get('beneficiaryId', '')
        data = {}

        if sub_section == 'person_details':
            person_model = Woman if section != 'child' else Child

            values = [
                'dob', 'name', 'sex', 'has_aadhar_number', 'hh_address',
                'contact_phone_number', 'hh_religion', 'hh_caste',
                'hh_bpl_apl', 'sc_id', 'village_id', 'awc_id'
            ]

            if section != 'child':
                values.extend([
                    'migration_status', 'age_marriage', 'husband_name',
                    'marital_status'
                ])
            else:
                values.append('mother_case_id')

            person = person_model.objects.values(*values).get(
                domain=request.domain, person_case_id=beneficiary_id)

            location_details = SQLLocation.objects.filter(
                domain=request.domain,
                location_id__in=[
                    person['sc_id'], person['village_id'], person['awc_id']
                ])

            for location in location_details:
                person[location.location_type.code] = location.name

            data = dict(person=person, )

            if section == 'child':
                mother = Woman.objects.extra(select={
                    'id': 'person_case_id'
                }).values('id',
                          'name').get(person_case_id=person['mother_case_id'])
                data.update(dict(mother=mother))
            else:
                # TODO update when the model will be created
                husband = dict(name=person['husband_name'],
                               sex='N/A',
                               dob='N/A',
                               age_marriage='N/A',
                               has_aadhar_number='N/A')
                data.update(dict(husband=husband))
        elif sub_section == 'child_details':
            data = dict(children=list(
                Child.objects.filter(domain=request.domain,
                                     mother_case_id=beneficiary_id).extra(
                                         select={
                                             'id': 'person_case_id'
                                         }).values('id', 'name', 'dob')))

        if section == 'child':
            helper = ChildQueryHelper(request.domain, beneficiary_id,
                                      month_end)
            if sub_section == 'infant_details':
                data = helper.infant_details()
            elif sub_section == 'child_postnatal_care_details':
                data = {'visits': helper.postnatal_care_details()}
            elif sub_section == 'vaccination_details':
                period = self.request.POST.get('period', 'atBirth')
                data = {'vitamins': helper.vaccination_details(period)}
            elif sub_section == 'growth_monitoring':
                data = helper.growth_monitoring()
            elif sub_section == 'weight_for_age_chart':
                data = {'points': helper.weight_for_age_chart()}
            elif sub_section == 'height_for_age_chart':
                data = {'points': helper.height_for_age_chart()}
            elif sub_section == 'weight_for_height_chart':
                data = {'points': helper.weight_for_height_chart()}
        elif section == 'pregnant_women':
            helper = PregnantWomanQueryHelper(request.domain, beneficiary_id,
                                              month_end)
            if sub_section == 'pregnancy_details':
                data = helper.pregnancy_details()
            elif sub_section == 'pregnancy_risk':
                data = helper.pregnancy_risk()
            elif sub_section == 'consumables_disbursed':
                data = helper.consumables_disbursed()
            elif sub_section == 'immunization_counseling_details':
                data = helper.immunization_counseling_details()
            elif sub_section == 'abortion_details':
                data = helper.abortion_details()
            elif sub_section == 'maternal_death_details':
                data = helper.maternal_death_details()
            elif sub_section == 'delivery_details':
                data = helper.delivery_details()
            elif sub_section == 'postnatal_care_details':
                data = {'visits': helper.postnatal_care_details()}
            elif sub_section == 'antenatal_care_details':
                data = {'visits': helper.antenatal_care_details()}
        elif section == 'eligible_couple':
            helper = EligibleCoupleQueryHelper(request.domain, beneficiary_id,
                                               month_end)
            if sub_section == 'eligible_couple_details':
                data = helper.eligible_couple_details()

        if not data:
            raise Http404()
        return JsonResponse(data=data)
 def test_newborn(self):
     self._create_child(date(2019, 2, 28))
     self.assertEqual(
         ChildQueryHelper.list(self.domain, date(2019, 3, 1), {},
                               'id').count(), 1)
 def test_future_child(self):
     self._create_child('2019-12-01')
     self.assertEqual(
         ChildQueryHelper.list(self.domain, date(2019, 3, 1), {},
                               'id').count(), 0)
 def test_six_year_old(self):
     self._create_child('2013-01-01')
     self.assertEqual(
         ChildQueryHelper.list(self.domain, date(2019, 3, 1), {},
                               'id').count(), 0)
 def _helper(self, person_case_id='person_case_id'):
     return ChildQueryHelper(self.domain, person_case_id, date(2019, 3, 1))
示例#10
0
 def test_newborn(self):
     self._create_child(date(2019, 2, 28))
     self.assertEqual(ChildQueryHelper.list(self.domain, date(2019, 3, 1), {}, 'id').count(), 1)
示例#11
0
 def test_future_child(self):
     self._create_child('2019-12-01')
     self.assertEqual(ChildQueryHelper.list(self.domain, date(2019, 3, 1), {}, 'id').count(), 0)
示例#12
0
 def test_six_year_old(self):
     self._create_child('2013-01-01')
     self.assertEqual(ChildQueryHelper.list(self.domain, date(2019, 3, 1), {}, 'id').count(), 0)
示例#13
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth', 0))
        selected_year = int(self.request.POST.get('selectedYear', 0))
        month_end = date(selected_year, selected_month, 1) + relativedelta(months=1) - relativedelta(days=1)
        section = self.request.POST.get('section', '')
        sub_section = self.request.POST.get('subsection', '')
        beneficiary_id = self.request.POST.get('beneficiaryId', '')
        data = {}

        if sub_section == 'person_details':
            person_model = Woman if section != 'child' else Child

            values = [
                'dob', 'name', 'sex', 'has_aadhar_number', 'hh_address', 'contact_phone_number',
                'hh_religion', 'hh_caste', 'hh_bpl_apl', 'sc_id', 'village_id', 'awc_id'
            ]

            if section != 'child':
                values.extend([
                    'migration_status',
                    'age_marriage',
                    'husband_name'
                ])
            else:
                values.append('mother_case_id')

            person = person_model.objects.values(*values).get(
                domain=request.domain,
                person_case_id=beneficiary_id
            )

            location_details = SQLLocation.objects.filter(
                domain=request.domain,
                location_id__in=[person['sc_id'], person['village_id'], person['awc_id']]
            )

            for location in location_details:
                person[location.location_type.code] = location.name

            data = dict(
                person=person,
            )

            if section == 'child':
                mother = Woman.objects.extra(
                    select={
                        'id': 'person_case_id'
                    }
                ).values('id', 'name').get(person_case_id=person['mother_case_id'])
                data.update(dict(mother=mother))
            else:
                # TODO update when the model will be created
                husband = dict(
                    name=person['husband_name'],
                    sex='N/A',
                    dob='N/A',
                    age_marriage='N/A',
                    has_aadhar_number='N/A'
                )
                data.update(dict(husband=husband))
        elif sub_section == 'child_details':
            data = dict(
                children=list(Child.objects.filter(
                    domain=request.domain,
                    mother_case_id=beneficiary_id
                ).extra(
                    select={
                        'id': 'person_case_id'
                    }
                ).values('id', 'name', 'dob'))
            )

        if section == 'child':
            helper = ChildQueryHelper(request.domain, beneficiary_id, month_end)
            if sub_section == 'infant_details':
                data = helper.infant_details()
            elif sub_section == 'child_postnatal_care_details':
                data = {'visits': helper.postnatal_care_details()}
            elif sub_section == 'vaccination_details':
                period = self.request.POST.get('period', 'atBirth')
                data = {'vitamins': helper.vaccination_details(period)}
            elif sub_section == 'growth_monitoring':
                data = helper.growth_monitoring()
            elif sub_section == 'weight_for_age_chart':
                data = {'points': helper.weight_for_age_chart()}
            elif sub_section == 'height_for_age_chart':
                data = {'points': helper.height_for_age_chart()}
            elif sub_section == 'weight_for_height_chart':
                data = {'points': helper.weight_for_height_chart()}
        elif section == 'pregnant_women':
            helper = PregnantWomanQueryHelper(request.domain, beneficiary_id, month_end)
            if sub_section == 'pregnancy_details':
                data = helper.pregnancy_details()
            elif sub_section == 'pregnancy_risk':
                data = helper.pregnancy_risk()
            elif sub_section == 'consumables_disbursed':
                data = helper.consumables_disbursed()
            elif sub_section == 'immunization_counseling_details':
                data = helper.immunization_counseling_details()
            elif sub_section == 'abortion_details':
                data = helper.abortion_details()
            elif sub_section == 'maternal_death_details':
                data = helper.maternal_death_details()
            elif sub_section == 'delivery_details':
                data = helper.delivery_details()
            elif sub_section == 'postnatal_care_details':
                data = {'visits': helper.postnatal_care_details()}
            elif sub_section == 'antenatal_care_details':
                data = {'visits': helper.antenatal_care_details()}
        elif section == 'eligible_couple':
            helper = EligibleCoupleQueryHelper(request.domain, beneficiary_id, month_end)
            if sub_section == 'eligible_couple_details':
                data = helper.eligible_couple_details()

        if not data:
            raise Http404()
        return JsonResponse(data=data)