def __init__(self, case, report, child_index=1, **kwargs): super(Beneficiary, self).__init__(case, report, child_index=child_index, **kwargs) self.child_count = numeric_fn(0 if self.status == "pregnant" else 1) # Show only cases that require payment if self.total_cash == 0: raise InvalidRow("Case does not require payment") self.payment_last_month = numeric_fn(self.last_month_row.total_cash if self.last_month_row else 0)
def sort_and_set_serial_numbers(self, case_objects): # sets serial_number for each row as the index in cases list sorted by awc_name, name from operator import attrgetter sorted_rows = sorted(case_objects, key=attrgetter('awc_name', 'name')) for count, row in enumerate(sorted_rows, 1): row.serial_number = numeric_fn(count) return sorted_rows
def __init__(self, worker, report, case_data=None, form_data=None): self.debug = report.debug self.case_data = case_data or [] self.name = worker.get('name') self.awc_name = worker.get('awc') self.awc_code = numeric_fn(worker.get('awc_code')) self.bank_name = worker.get('bank_name') self.ifs_code = worker.get('ifs_code') self.account_number = worker.get('account_number') self.block = worker.get('block') self.owner_id = worker.get('doc_id') self.growth_monitoring_contributions = defaultdict(lambda: 0) if case_data: self.beneficiaries_registered = numeric_fn(len(case_data)) self.children_registered = numeric_fn(sum([c.raw_num_children for c in case_data if not c.is_secondary])) for opm_case in case_data: dates = opm_case.data_provider.get_dates_in_range(opm_case.owner_id, opm_case.reporting_window_start, opm_case.reporting_window_end) self.service_forms_count = 'yes' if dates else 'no' for row in self.case_data: if row.growth_calculated_aww: self.growth_monitoring_contributions[(row.case_id, row.child_index)] += 1 monitoring_count = len(self.growth_monitoring_contributions.keys()) else: self.beneficiaries_registered = None self.children_registered = None self.service_forms_count = 'no' monitoring_count = 0 self.growth_monitoring_count = numeric_fn(monitoring_count) FIXTURES = get_fixture_data() forms_cash = FIXTURES['service_form_submitted'] \ if self.service_forms_count == 'yes' else 0 self.service_forms_cash = numeric_fn(forms_cash) monitoring_cash = monitoring_count * FIXTURES['child_growth_monitored'] self.growth_monitoring_cash = numeric_fn(monitoring_cash) self.month_total = numeric_fn(forms_cash + monitoring_cash) if report.last_month_totals is not None: self.last_month_total = numeric_fn(report.last_month_totals.get( self.account_number, 0)) else: self.last_month_total = numeric_fn(0)
def __init__(self, case, report, child_index=1, **kwargs): super(ConditionsMet, self).__init__(case, report, child_index=child_index, **kwargs) self.serial_number = child_index self.payment_last_month = "Rs.%d" % (self.last_month_row.cash_amt if self.last_month_row else 0) self.cash_received_last_month = self.last_month_row.vhnd_available_display if self.last_month_row else 'no' awc_data = user_sql_data().data_by_doc_id.get(self.owner_id, None) self.awc_code = numeric_fn(awc_data[0] if awc_data else EMPTY_FIELD) self.issue = '' if self.status == 'mother': self.child_name = self.case_property(self.child_xpath("child{num}_name"), EMPTY_FIELD) self.one = self.condition_image(C_ATTENDANCE_Y, C_ATTENDANCE_N, "पोषण दिवस में उपस्थित", "पोषण दिवस में उपस्थित नही", self.child_attended_vhnd) self.two = self.condition_image(C_WEIGHT_Y, C_WEIGHT_N, "बच्चे का वज़न लिया गया", "बच्चे का वज़न लिया गया", self.child_growth_calculated) if self.child_has_diarhea and self.child_received_ors: self.three = self.img_elem % (ORSZNTREAT_Y, "दस्त होने पर ओ.आर.एस एवं जिंक लिया") elif self.child_has_diarhea and not self.child_received_ors: self.three = self.img_elem % (ORSZNTREAT_N, "दस्त होने पर ओ.आर.एस एवं जिंक नहीं लिया") elif not self.child_has_diarhea: self.three = self.img_elem % (ORSZNTREAT_Y, "बच्चे को दस्त नहीं हुआ") else: self.three = "" if self.child_condition_four is not None: self.four = self.condition_image(self.child_image_four[0], self.child_image_four[1], self.child_image_four[2], self.child_image_four[3], self.child_condition_four) else: self.four = '' self.five = self.condition_image(EXCBREASTFED_Y, EXCBREASTFED_N, "केवल माँ का दूध खिलाया गया", "केवल माँ का दूध नहीं खिलाया गया", self.child_breastfed) elif self.status == 'pregnant': self.child_name = EMPTY_FIELD self.one = self.condition_image(C_ATTENDANCE_Y, C_ATTENDANCE_N, "पोषण दिवस में उपस्थित", "पोषण दिवस में उपस्थित नही", self.preg_attended_vhnd) self.two = self.condition_image(M_WEIGHT_Y, M_WEIGHT_N, "गर्भवती का वज़न हुआ", "गर्भवती का वज़न नही हुआा", self.preg_weighed) self.three = self.condition_image(IFA_Y, IFA_N, "तीस आयरन की गोलियां लेना", "तीस आयरन की गोलियां नही लिया", self.preg_received_ifa) self.four = '' self.five = '' if self.child_age in (24, 36): if self.block == 'atri': met, pos, neg = self.weight_grade_normal, GRADE_NORMAL_Y, GRADE_NORMAL_N else: met, pos, neg = self.birth_spacing_years, SPACING_PROMPT_Y, SPACING_PROMPT_N if met: self.five = self.img_elem % (pos, "") elif met is False: self.five = self.img_elem % (neg, "") else: self.five = '' if not self.vhnd_available: self.one = self.img_elem % (VHND_NO, "पोषण दिवस का आयोजन नहीं हुआ")
def __init__(self, case, report, child_index=1, **kwargs): super(Beneficiary, self).__init__(case, report, child_index=child_index, **kwargs) # Show only cases that require payment if self.total_cash == 0: raise InvalidRow("Case does not require payment") if self.case_is_out_of_range: raise InvalidRow("Child age is greater than 36 months") self.payment_last_month = numeric_fn(self.last_month_row.total_cash if self.last_month_row else 0)
class Beneficiary(OPMCaseRow): """ Constructor object for each row in the Beneficiary Payment Report """ method_map = [ # If you need to change any of these names, keep the key intact ('name', ugettext_lazy("List of Beneficiaries"), True, None), ('husband_name', ugettext_lazy("Husband Name"), True, None), ('awc_name', ugettext_lazy("AWC Name"), True, None), ('bank_name', ugettext_lazy("Bank Name"), True, None), ('bank_branch_name', ugettext_lazy("Bank Branch Name"), True, None), ('ifs_code', ugettext_lazy("IFS Code"), True, None), ('account_number', ugettext_lazy("Bank Account Number"), True, None), ('block_name', ugettext_lazy("Block Name"), True, None), ('village', ugettext_lazy("Village Name"), True, None), ('num_children_disp', ugettext_lazy("Number of Children"), True, DTSortType.NUMERIC), ('bp1_cash', ugettext_lazy("Birth Preparedness Form 1"), True, None), ('bp2_cash', ugettext_lazy("Birth Preparedness Form 2"), True, None), ('child_cash', ugettext_lazy("Child Followup Form"), True, None), ('year_end_bonus_cash', ugettext_lazy("Bonus Payment"), True, None), ('total_cash', ugettext_lazy("Amount to be paid to beneficiary"), True, None), ('case_id', ugettext_lazy('Case ID'), True, None), ('owner_id', ugettext_lazy("Owner ID"), False, None), ('closed_date', ugettext_lazy("Closed On"), True, None), ('vhnd_available_display', ugettext_lazy('VHND organised this month'), True, None), ('payment_last_month', ugettext_lazy('Payment last month'), True, DTSortType.NUMERIC), ('issues', ugettext_lazy("Issues"), True, None), ] def __init__(self, case, report, child_index=1, **kwargs): super(Beneficiary, self).__init__(case, report, child_index=child_index, **kwargs) # Show only cases that require payment if self.total_cash == 0: raise InvalidRow("Case does not require payment") self.payment_last_month = numeric_fn( self.last_month_row.total_cash if self.last_month_row else 0)
def child_age_display(self): return numeric_fn(self.child_age) if self.child_age is not None else EMPTY_FIELD
def preg_month_display(self): return numeric_fn(self.preg_month) if self.preg_month is not None else EMPTY_FIELD
class ConditionsMet(OPMCaseRow): method_map = [ ('serial_number', ugettext_lazy("Serial number"), True, DTSortType.NUMERIC), ('name', ugettext_lazy("List of Beneficiaries"), True, None), ('awc_name', ugettext_lazy("AWC Name"), True, None), ('awc_code', ugettext_lazy("AWC Code"), True, DTSortType.NUMERIC), ('block_name', ugettext_lazy("Block Name"), True, None), ('husband_name', ugettext_lazy("Husband Name"), True, None), ('readable_status', ugettext_lazy("Current status"), True, None), ('preg_month_display', ugettext_lazy('Pregnancy Month'), True, DTSortType.NUMERIC), ('child_name', ugettext_lazy("Child Name"), True, None), ('child_age_display', ugettext_lazy("Child Age"), True, DTSortType.NUMERIC), ('window', ugettext_lazy("Window"), True, None), ('one', ugettext_lazy("Condition 1"), True, None), ('two', ugettext_lazy("Condition 2"), True, None), ('three', ugettext_lazy("Condition 3"), True, None), ('four', ugettext_lazy("Condition 4"), True, None), ('five', ugettext_lazy("Condition 5"), True, None), ('cash', ugettext_lazy("Payment amount this month (Rs.)"), True, None), ('payment_last_month', ugettext_lazy("Payment amount last month (Rs.)"), True, None), ('cash_received_last_month', ugettext_lazy("Cash received last month"), True, None), ('case_id', ugettext_lazy('Case ID'), True, None), ('closed_date', ugettext_lazy("Closed On"), True, None), ('issue', ugettext_lazy('Issues'), True, None) ] def __init__(self, case, report, child_index=1, **kwargs): super(ConditionsMet, self).__init__(case, report, child_index=child_index, **kwargs) self.serial_number = child_index self.payment_last_month = "Rs.%d" % (self.last_month_row.cash_amt if self.last_month_row else 0) self.cash_received_last_month = self.last_month_row.vhnd_available_display if self.last_month_row else 'no' awc_data = user_sql_data().data_by_doc_id.get(self.owner_id, None) self.awc_code = numeric_fn(awc_data[0] if awc_data else EMPTY_FIELD) self.issue = '' if self.status == 'mother': self.child_name = self.case_property(self.child_xpath("child{num}_name"), EMPTY_FIELD) self.one = self.condition_image(C_ATTENDANCE_Y, C_ATTENDANCE_N, "पोषण दिवस में उपस्थित", "पोषण दिवस में उपस्थित नही", self.child_attended_vhnd) self.two = self.condition_image(C_WEIGHT_Y, C_WEIGHT_N, "बच्चे का वज़न लिया गया", "बच्चे का वज़न लिया गया", self.child_growth_calculated) if self.child_has_diarhea and self.child_received_ors_in_this_window: self.three = self.img_elem % (ORSZNTREAT_Y, "दस्त होने पर ओ.आर.एस एवं जिंक लिया") elif self.child_has_diarhea and not self.child_received_ors_in_this_window: self.three = self.img_elem % (ORSZNTREAT_N, "दस्त होने पर ओ.आर.एस एवं जिंक नहीं लिया") elif not self.child_has_diarhea: self.three = self.img_elem % (ORSZNTREAT_Y, "बच्चे को दस्त नहीं हुआ") else: self.three = "" if self.child_condition_four is not None: self.four = self.condition_image(self.child_image_four[0], self.child_image_four[1], self.child_image_four[2], self.child_image_four[3], self.child_condition_four) else: self.four = '' self.five = self.condition_image(EXCBREASTFED_Y, EXCBREASTFED_N, "केवल माँ का दूध खिलाया गया", "केवल माँ का दूध नहीं खिलाया गया", self.child_breastfed) elif self.status == 'pregnant': self.child_name = EMPTY_FIELD self.one = self.condition_image(C_ATTENDANCE_Y, C_ATTENDANCE_N, "पोषण दिवस में उपस्थित", "पोषण दिवस में उपस्थित नही", self.preg_attended_vhnd) self.two = self.condition_image(M_WEIGHT_Y, M_WEIGHT_N, "गर्भवती का वज़न हुआ", "गर्भवती का वज़न नही हुआा", self.preg_weighed) self.three = self.condition_image(IFA_Y, IFA_N, "तीस आयरन की गोलियां लेना", "तीस आयरन की गोलियां नही लिया", self.preg_received_ifa) self.four = '' self.five = '' if self.child_age in (24, 36): if self.block == 'atri': met, pos, neg = self.weight_grade_normal, GRADE_NORMAL_Y, GRADE_NORMAL_N else: met, pos, neg = self.birth_spacing_years, SPACING_PROMPT_Y, SPACING_PROMPT_N if met: self.five = self.img_elem % (pos, "") elif met is False: self.five = self.img_elem % (neg, "") else: self.five = '' if not self.vhnd_available: self.one = self.img_elem % (VHND_NO, "पोषण दिवस का आयोजन नहीं हुआ")