def rows(self):
        def percent(v1, v2):
            try:
                return float(v1) * 100.0 / float(v2)
            except ZeroDivisionError:
                return 0

        def get_grade(v):
            return 'D' if v < 25 else 'C' if v < 50 else 'B' if v < 75 else 'A'

        rows = [[column.header] for column in self.model.columns[2:]]

        for block in self.get_blocks_for_district():
            self.request_params['hierarchy_block'] = block
            q = self.request.GET.copy()
            q['hierarchy_block'] = block
            self.request.GET = q
            rs, block_total = BlockLevelAFReport(self.request,
                                                 domain=self.domain).rows
            for index, row in enumerate(rs[0:-2]):
                value = percent(row[-1]['sort_key'], block_total)
                grade = get_grade(value)
                if index < 10:
                    rows[index].append(
                        format_datatables_data('%.1f%%' % value,
                                               '%.1f%%' % value))
                    rows[index].append(format_datatables_data(grade, grade))
                else:
                    rows[index].append(row[-1])
                    val = row[-1]['sort_key']
                    grade = get_grade(val)
                    rows[index].append(format_datatables_data(grade, grade))

        return rows, 0
Esempio n. 2
0
 def report(self):
     config = self.report_config
     if config.get('sf') == 'sf5':
         return DistrictFunctionalityReport(self.request, domain=self.domain)
     elif config.get('sf') == 'sf4':
         return BlockLevelAFReport(self.request, domain=self.domain)
     elif config.get('sf') == 'sf3':
         return BlockLevelMonthReport(self.request, domain=self.domain)
     elif config.get('sf') == 'sf2':
         return ASHAFacilitatorsReport(self.request, domain=self.domain)
     else:
         return ASHAFunctionalityChecklistReport(self.request, domain=self.domain)
Esempio n. 3
0
    def test_block_level_af_report(self, mock_run_query):
        mock = MagicMock()
        mock.couch_user = self.user
        mock.GET = {
            'lang': '',
            'sf': 'sf4',
            'startdate': '2018-01-01',
            'enddate': '2018-01-31',
            'hierarchy_af': '646eb23165f2f3ee9966b0512efc9494',
            'month': '01',
            'year': '2018',
            'hierarchy_district': 'kaushambi',
            'hierarchy_block': 'Chail',
        }
        block_level_af_report = BlockLevelAFReport(request=mock, domain=DOMAIN)
        rows = block_level_af_report.rows
        expected = (
            [
                [
                    'Newborn visits within first day of birth in case of home deliveries',
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '2', 'html': '2'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '1', 'html': '1'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '1', 'html': '1'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': 4.0, 'html': 4.0}
                ],
                [
                    'Set of home visits for newborn care as specified in the HBNC guidelines<br/>'
                    '(six visits in case of Institutional delivery and seven in case of a home delivery)',
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': '2', 'html': '2'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': 32.0, 'html': 32.0}
                ],
                [
                    'Attending VHNDs/Promoting immunization',
                    {'sort_key': '6', 'html': '6'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '5', 'html': '5'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': 43.0, 'html': 43.0}
                ],
                [
                    'Supporting institutional delivery',
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '1', 'html': '1'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': 32.0, 'html': 32.0}
                ],
                [
                    'Management of childhood illness - especially diarrhea and pneumonia',
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': 34.0, 'html': 34.0}
                ],
                [
                    'Household visits with nutrition counseling',
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': '3', 'html': '3'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': 30.0, 'html': 30.0}
                ],
                [
                    'Fever cases seen/malaria slides made in malaria endemic area',
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': 0.0, 'html': 0.0}],
                [
                    'Acting as DOTS provider',
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': 0.0, 'html': 0.0}
                ],
                [
                    'Holding or attending village/VHSNC meeting',
                    {'sort_key': '1', 'html': '1'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '0', 'html': '0'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '0', 'html': '0'},
                    {'sort_key': '3', 'html': '3'}, {'sort_key': 12.0, 'html': 12.0}
                ],
                [
                    'Successful referral of the IUD, female sterilization or male '
                    'sterilization cases and/or providing OCPs/Condoms',
                    {'sort_key': '6', 'html': '6'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '5', 'html': '5'},
                    {'sort_key': '5', 'html': '5'}, {'sort_key': '4', 'html': '4'},
                    {'sort_key': '4', 'html': '4'}, {'sort_key': 41.0, 'html': 41.0}
                ],
                [
                    '<b>Total number of ASHAs who are functional on at least 60% of the tasks</b>',
                    {'sort_key': 29.629629629629626, 'html': '5/18 (29%)'},
                    {'sort_key': 30.76923076923077, 'html': '4/13 (30%)'},
                    {'sort_key': 28.88888888888889, 'html': '4/15 (28%)'},
                    {'sort_key': 33.33333333333333, 'html': '4/13 (33%)'},
                    {'sort_key': 33.333333333333336, 'html': '4/14 (33%)'},
                    {'sort_key': 27.083333333333332, 'html': '4/16 (27%)'},
                    {'sort_key': 27.083333333333332, 'html': '4/16 (27%)'},
                    {'sort_key': 30.555555555555554, 'html': '3/12 (30%)'},
                    {'sort_key': 30.952380952380953, 'html': '4/14 (30%)'},
                    {'sort_key': 27, 'html': '36/131 (27%)'}
                ],
                [
                    '<b>Total number of ASHAs who did not report/not known</b>',
                    {'sort_key': '12', 'html': '12'}, {'sort_key': '11', 'html': '11'},
                    {'sort_key': '11', 'html': '11'}, {'sort_key': '11', 'html': '11'},
                    {'sort_key': '10', 'html': '10'}, {'sort_key': '12', 'html': '12'},
                    {'sort_key': '12', 'html': '12'}, {'sort_key': '10', 'html': '10'},
                    {'sort_key': '10', 'html': '10'}, {'sort_key': 99.0, 'html': 99.0}
                ],
                [
                    '<b>Total Number of ASHAs under each Facilitator</b>',
                    {'sort_key': 18, 'html': 18}, {'sort_key': 15, 'html': 15},
                    {'sort_key': 16, 'html': 16}, {'sort_key': 15, 'html': 15},
                    {'sort_key': 15, 'html': 15}, {'sort_key': 17, 'html': 17},
                    {'sort_key': 17, 'html': 17}, {'sort_key': 14, 'html': 14},
                    {'sort_key': 15, 'html': 15}, {'sort_key': 142, 'html': 142}
                ]
            ], 142
        )

        self.assertEqual(len(rows), len(expected))
        self.assertEqual(len(rows[0]), len(expected[0]))
        for i in range(len(rows[0])):
            self.assertEqual(len(rows[0][i]), len(expected[0][i]))
            for record in expected[0][i]:
                self.assertIn(record, rows[0][i])