def asha_af_report(request, domain): report = ASHAAFChecklistData( config=dict(doc_id=request.GET.get('doc_id'), date=force_to_datetime(request.GET.get('date')), domain=domain)) return HttpResponse(json.dumps(report.rows), content_type='application/json')
def rows(self): default_row_data = [ ['', _('Date when cheklist was filled')], [ 1, _('Newborn visits within first day of birth in case of home deliveries' ) ], [ 2, _('Set of home visits for newborn care as specified in the HBNC guidelines ' '(six visits in case of Institutional delivery and seven in case of a home delivery)' ) ], [3, _('Attending VHNDs/Promoting immunization')], [4, _('Supporting institutional delivery')], [ 5, _('Management of childhood illness - especially diarrhea and pneumonia' ) ], [6, _('Household visits with nutrition counseling')], [ 7, _('Fever cases seen/malaria slides made in malaria endemic area' ) ], [8, _('Acting as DOTS provider')], [9, _('Holding or attending village/VHSNC meeting')], [ 10, _('Successful referral of the IUD, female sterilization or male ' 'sterilization cases and/or providing OCPs/Condoms') ], [ '', _('Total of number of tasks on which ASHA reported being functional' ) ], [ '', _('Total number of ASHAs who are functional on at least %s of the tasks' % '60%') ], ['', _('Remark')] ] properties = [ 'completed_on', 'hv_fx_home_birth_visits', 'hv_fx_newborns_visited', 'hv_fx_vhnd', 'hv_fx_support_inst_delivery', 'hv_fx_child_illness_mgmt', 'hv_fx_nut_counseling', 'hv_fx_malaria', 'hv_fx_dots', 'hv_fx_vhsnc', 'hv_fx_fp' ] ttotal = [0] * len(default_row_data) total_of_functional = 0 for asha in self.ashas: data = ASHAAFChecklistData(config=dict( doc_id=asha['doc_id'], date=force_to_datetime(self.request.GET.get('date')), domain=self.domain, is_checklist=1)).data total = 0 denominator = 0 for idx, p in enumerate(properties): if data[p] == 1: ttotal[idx] += 1 total += 1 if p != 'completed_on' and data[p] != 88: denominator += 1 if p == 'completed_on': default_row_data[idx].append( data[p].strftime('%Y-%m-%d %H:%M')) else: default_row_data[idx].append( data[p] if data[p] != 88 else 'NA') try: percent = total * 100 / denominator except ZeroDivisionError: percent = 0 if percent >= 60: total_of_functional += 1 default_row_data[-3].append(total) default_row_data[-2].append('{0}/{1} ({2}%)'.format( total, denominator, percent)) default_row_data[-1].append('') for idx, row in enumerate(default_row_data): if idx == 0: row.append(_('Total no. of ASHAs functional on each tasks')) elif 0 < idx < 11: row.append(ttotal[idx]) elif idx == 12: row.append(total_of_functional) else: row.append('') return default_row_data