Пример #1
0
    def testVisitBounds(self):
        # test dates around the +/- 10 day window and make sure they are/aren't counted
        out_of_bounds = ['2013-03-11', '2013-04-04']
        for oob in out_of_bounds:
            indicator = CareBiharFluff()
            dates = {
                'bp1_due': '2013-01-22', 'bp1_done': '2013-01-22', 'bp1_days_overdue': '0',
                'bp2_due': '2013-03-22', 'bp2_done': oob, 'bp2_days_overdue': '0',
                'bp3_due': '2013-06-22', 'bp3_done': '2013-06-22', 'bp3_days_overdue': '0',
            }
            case = self._load_case('test_bihar_bp.json', dates)
            indicator.calculate(case)
            bp2 = indicator.bp2
            [total] = bp2['total']
            self.assertEqual(date(2013, 3, 22), total['date'])
            self.assertEqual(1, total['value'])
            self.assertEqual(0, len(bp2['numerator']))

        in_bounds = ['2013-03-13', '2013-04-01']
        for ib in in_bounds:
            indicator = CareBiharFluff()
            dates = {
                'bp1_due': '2013-01-22', 'bp1_done': '2013-01-22', 'bp1_days_overdue': '0',
                'bp2_due': '2013-03-22', 'bp2_done': ib, 'bp2_days_overdue': '0',
                'bp3_due': '2013-06-22', 'bp3_done': '2013-06-22', 'bp3_days_overdue': '0',
            }
            case = self._load_case('test_bihar_bp.json', dates)
            indicator.calculate(case)
            bp2 = indicator.bp2
            [total] = bp2['total']
            self.assertEqual(date(2013, 3, 22), total['date'])
            self.assertEqual(1, total['value'])
            [numerator] = bp2['numerator']
            self.assertEqual(date(2013, 3, 22), numerator['date'])
            self.assertEqual(1, numerator['value'])
Пример #2
0
    def testBPNormal(self):
        # our mother has the following date properties set
        # EDD: 2013-08-19
        # 3rd Tri: 2013-05-17
        # 2nd Tri: 2013-02-13
        indicator = CareBiharFluff()

        # everything perfect
        dates = {
            'bp1_due': '2013-01-22', 'bp1_done': '2013-01-22', 'bp1_days_overdue': '0',
            'bp2_due': '2013-03-22', 'bp2_done': '2013-03-22', 'bp2_days_overdue': '0',
            'bp3_due': '2013-06-22', 'bp3_done': '2013-06-22', 'bp3_days_overdue': '0',
        }
        case = self._load_case('test_bihar_bp.json', dates)
        indicator.calculate(case)
        bp2 = indicator.bp2
        [total] = bp2['total']
        self.assertEqual(date(2013, 3, 22), total['date'])
        self.assertEqual(1, total['value'])

        [numerator] = bp2['numerator']
        self.assertEqual(date(2013, 3, 22), numerator['date'])
        self.assertEqual(1, numerator['value'])

        bp3 = indicator.bp3
        self.assertEqual(1, len(bp3['total']))
        [total] = bp3['total']
        self.assertEqual(date(2013, 6, 22), total['date'])
        self.assertEqual(1, total['value'])
        [numerator] = bp3['numerator']
        self.assertEqual(date(2013, 6, 22), numerator['date'])
        self.assertEqual(1, numerator['value'])

        self.assertIndicatorsEmpty(indicator)
Пример #3
0
    def testBPAllInThirdTri(self):
        indicator = CareBiharFluff()

        dates = {
            'bp1_due': '2013-06-21', 'bp1_done': '2013-06-21', 'bp1_days_overdue': '0',
            'bp2_due': '2013-06-22', 'bp2_done': '2013-06-22', 'bp2_days_overdue': '0',
            'bp3_due': '2013-06-23', 'bp3_done': '2013-06-23', 'bp3_days_overdue': '0',
        }
        case = self._load_case('test_bihar_bp.json', dates)
        indicator.calculate(case)
        bp3 = indicator.bp3
        self.assertEqual(3, len(bp3['total']))
        [v1, v2, v3] = bp3['total']
        self.assertEqual(date(2013, 6, 21), v1['date'])
        self.assertEqual(date(2013, 6, 22), v2['date'])
        self.assertEqual(date(2013, 6, 23), v3['date'])
        for res in bp3['total']:
            self.assertEqual(1, res['value'])

        self.assertEqual(3, len(bp3['numerator']))
        [v1, v2, v3] = bp3['numerator']
        self.assertEqual(date(2013, 6, 21), v1['date'])
        self.assertEqual(date(2013, 6, 22), v2['date'])
        self.assertEqual(date(2013, 6, 23), v3['date'])
        for res in bp3['total']:
            self.assertEqual(1, res['value'])

        self.assertIndicatorsEmpty(indicator, vals=('bp2', 'pnc', 'ebf', 'cf'))
Пример #4
0
def get_calculation(owner_ids, slug):
    from custom.bihar.models import CareBiharFluff

    r = CareBiharFluff.aggregate_results(slug, (["care-bihar", owner_id] for owner_id in owner_ids), reduce=True)
    num = r.get("numerator")
    total = r.get("total")
    r = CareBiharFluff.aggregate_results(slug, (["care-bihar", owner_id] for owner_id in owner_ids), reduce=False)
    num_cases = ", ".join(r.get("numerator", ()))
    total_cases = ", ".join(r.get("total", ()))
    return num or "", total, num_cases, total_cases
Пример #5
0
    def testBPAllInFirstTri(self):
        indicator = CareBiharFluff()

        dates = {
            'bp1_due': '2013-01-21', 'bp1_done': '2013-01-21', 'bp1_days_overdue': '0',
            'bp2_due': '2013-01-22', 'bp2_done': '2013-01-22', 'bp2_days_overdue': '0',
            'bp3_due': '2013-01-23', 'bp3_done': '2013-01-23', 'bp3_days_overdue': '0',
        }
        case = self._load_case('test_bihar_bp.json', dates)
        indicator.calculate(case)
        self.assertIndicatorsEmpty(indicator, vals=('bp2', 'bp3', 'pnc', 'ebf', 'cf'))
Пример #6
0
def get_calculation(owner_ids, slug):
    from custom.bihar.models import CareBiharFluff
    r = CareBiharFluff.aggregate_results(slug, (
        ['care-bihar', owner_id] for owner_id in owner_ids
    ), reduce=True)
    num = r.get('numerator')
    total = r.get('total')
    r = CareBiharFluff.aggregate_results(slug, (
        ['care-bihar', owner_id] for owner_id in owner_ids
    ), reduce=False)
    num_cases = ', '.join(r.get('numerator', ()))
    total_cases = ', '.join(r.get('total', ()))
    return num or '', total, num_cases, total_cases
Пример #7
0
    def testBPAllInThirdTri(self):
        indicator = CareBiharFluff()

        dates = {
            'bp1_due': '2013-06-21', 'bp1_done': '2013-06-21', 'bp1_days_overdue': '0',
            'bp2_due': '2013-06-22', 'bp2_done': '2013-06-22', 'bp2_days_overdue': '0',
            'bp3_due': '2013-06-23', 'bp3_done': '2013-06-23', 'bp3_days_overdue': '0',
        }
        case = self._load_case('test_bihar_bp.json', dates)
        indicator.calculate(case)
        bp3 = indicator.bp3
        self.assertEqual(3, len(bp3['total']))
        [v1, v2, v3] = bp3['total']
        self.assertEqual(date(2013, 6, 21), v1['date'])
        self.assertEqual(date(2013, 6, 22), v2['date'])
        self.assertEqual(date(2013, 6, 23), v3['date'])
        for res in bp3['total']:
            self.assertEqual(1, res['value'])

        self.assertEqual(3, len(bp3['numerator']))
        [v1, v2, v3] = bp3['numerator']
        self.assertEqual(date(2013, 6, 21), v1['date'])
        self.assertEqual(date(2013, 6, 22), v2['date'])
        self.assertEqual(date(2013, 6, 23), v3['date'])
        for res in bp3['total']:
            self.assertEqual(1, res['value'])

        self.assertIndicatorsEmpty(indicator, vals=('bp2', 'pnc', 'ebf', 'cf'))
Пример #8
0
    def testBPNormal(self):
        # our mother has the following date properties set
        # EDD: 2013-08-19
        # 3rd Tri: 2013-05-17
        # 2nd Tri: 2013-02-13
        indicator = CareBiharFluff()

        # everything perfect
        dates = {
            'bp1_due': '2013-01-22', 'bp1_done': '2013-01-22', 'bp1_days_overdue': '0',
            'bp2_due': '2013-03-22', 'bp2_done': '2013-03-22', 'bp2_days_overdue': '0',
            'bp3_due': '2013-06-22', 'bp3_done': '2013-06-22', 'bp3_days_overdue': '0',
        }
        case = self._load_case('test_bihar_bp.json', dates)
        indicator.calculate(case)
        bp2 = indicator.bp2
        [total] = bp2['total']
        self.assertEqual(date(2013, 3, 22), total['date'])
        self.assertEqual(1, total['value'])

        [numerator] = bp2['numerator']
        self.assertEqual(date(2013, 3, 22), numerator['date'])
        self.assertEqual(1, numerator['value'])

        bp3 = indicator.bp3
        self.assertEqual(1, len(bp3['total']))
        [total] = bp3['total']
        self.assertEqual(date(2013, 6, 22), total['date'])
        self.assertEqual(1, total['value'])
        [numerator] = bp3['numerator']
        self.assertEqual(date(2013, 6, 22), numerator['date'])
        self.assertEqual(1, numerator['value'])

        self.assertIndicatorsEmpty(indicator)
Пример #9
0
 def __init__(self, spec):
     self.slug = spec["slug"]
     self.name = spec["name"]
     display = spec["clientlistdisplay"]
     kwargs = spec.get("kwargs", {})
     self._display = display(**kwargs)
     self.fluff_calculator = CareBiharFluff.get_calculator(self.slug)
Пример #10
0
 def __init__(self, spec):
     self.slug = spec["slug"]
     self.name = spec["name"]
     display = spec["clientlistdisplay"]
     kwargs = spec.get("kwargs", {})
     self._display = display(**kwargs)
     self.fluff_calculator = CareBiharFluff.get_calculator(self.slug)
Пример #11
0
    def testBPAllInFirstTri(self):
        indicator = CareBiharFluff()

        dates = {
            'bp1_due': '2013-01-21', 'bp1_done': '2013-01-21', 'bp1_days_overdue': '0',
            'bp2_due': '2013-01-22', 'bp2_done': '2013-01-22', 'bp2_days_overdue': '0',
            'bp3_due': '2013-01-23', 'bp3_done': '2013-01-23', 'bp3_days_overdue': '0',
        }
        case = self._load_case('test_bihar_bp.json', dates)
        indicator.calculate(case)
        self.assertIndicatorsEmpty(indicator, vals=('bp2', 'bp3', 'pnc', 'ebf', 'cf'))
Пример #12
0
    def testVisitBounds(self):
        # test dates around the +/- 10 day window and make sure they are/aren't counted
        out_of_bounds = ['2013-03-11', '2013-04-04']
        for oob in out_of_bounds:
            indicator = CareBiharFluff()
            dates = {
                'bp1_due': '2013-01-22', 'bp1_done': '2013-01-22', 'bp1_days_overdue': '0',
                'bp2_due': '2013-03-22', 'bp2_done': oob, 'bp2_days_overdue': '0',
                'bp3_due': '2013-06-22', 'bp3_done': '2013-06-22', 'bp3_days_overdue': '0',
            }
            case = self._load_case('test_bihar_bp.json', dates)
            indicator.calculate(case)
            bp2 = indicator.bp2
            [total] = bp2['total']
            self.assertEqual(date(2013, 3, 22), total['date'])
            self.assertEqual(1, total['value'])
            self.assertEqual(0, len(bp2['numerator']))

        in_bounds = ['2013-03-13', '2013-04-01']
        for ib in in_bounds:
            indicator = CareBiharFluff()
            dates = {
                'bp1_due': '2013-01-22', 'bp1_done': '2013-01-22', 'bp1_days_overdue': '0',
                'bp2_due': '2013-03-22', 'bp2_done': ib, 'bp2_days_overdue': '0',
                'bp3_due': '2013-06-22', 'bp3_done': '2013-06-22', 'bp3_days_overdue': '0',
            }
            case = self._load_case('test_bihar_bp.json', dates)
            indicator.calculate(case)
            bp2 = indicator.bp2
            [total] = bp2['total']
            self.assertEqual(date(2013, 3, 22), total['date'])
            self.assertEqual(1, total['value'])
            [numerator] = bp2['numerator']
            self.assertEqual(date(2013, 3, 22), numerator['date'])
            self.assertEqual(1, numerator['value'])