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 _helper(self, person_case_id='person_case_id'): return ChildQueryHelper(self.domain, person_case_id, date(2019, 3, 1))