Пример #1
0
    def test_calculate_immunization_window(self):
        pregnancy_products = get_immunization_products(self.domain,
                                                       'pregnancy')
        child_products = get_immunization_products(self.domain, 'child')

        self.assertEqual(
            calculate_immunization_window(
                self.tasks_pregnancy, date(2017, 8, 1),
                get_map(pregnancy_products, 'code')['anc_1'],
                pregnancy_products, []),
            (date(2016, 10, 31), date(2018, 1, 28)))

        self.assertEqual(
            calculate_immunization_window(
                self.tasks_child, date(2017, 8, 1),
                get_map(child_products, 'code')['3g_dpt_3'], child_products,
                []), (None, date(2019, 8, 1)))

        self.assertEqual(
            calculate_immunization_window(
                self.tasks_child, date(2017, 8, 1),
                get_map(child_products, 'code')['3g_dpt_3'], child_products,
                [LedgerValue(entry_id=self.dpt2.get_id, balance=17390)]),
            (date(2017, 11, 7), date(2019, 8, 1)))

        self.assertEqual(
            calculate_immunization_window(
                self.tasks_child, date(2017, 8, 1),
                get_map(child_products, 'code')['3g_dpt_3'], child_products,
                [LedgerValue(entry_id=self.dpt2.get_id, balance=17501)]),
            (date(2017, 12, 29), date(2019, 8, 1)))
Пример #2
0
    def test_immunization_is_due(self, todays_date):
        pregnancy_products = get_immunization_products(self.domain,
                                                       'pregnancy')
        child_products = get_immunization_products(self.domain, 'child')

        # Immunization is due when it has a predecessor which is completed and its date range is valid
        todays_date.return_value = date(2018, 1, 1)
        self.assertTrue(
            immunization_is_due(
                self.tasks_child, date(2017, 8, 1),
                get_map(child_products, 'code')['3g_dpt_3'], child_products,
                [LedgerValue(entry_id=self.dpt2.get_id, balance=17501)]))

        # Immunization is not due when it has a predecessor and its predecessor is not completed
        todays_date.return_value = date(2018, 1, 1)
        self.assertFalse(
            immunization_is_due(self.tasks_child, date(2017, 8, 1),
                                get_map(child_products, 'code')['3g_dpt_3'],
                                child_products, []))

        # Immunization is due when it has a schedule_flag which is applied to the tasks case
        # and its date range is valid
        todays_date.return_value = date(2017, 9, 1)
        self.assertTrue(
            immunization_is_due(self.tasks_pregnancy, date(2017, 8, 1),
                                get_map(pregnancy_products, 'code')['tt_1'],
                                pregnancy_products, []))

        # Immunization is not due when it has a schedule_flag which is not applied to the tasks case
        # even though its date range is valid
        todays_date.return_value = date(2017, 9, 1)
        self.assertFalse(
            immunization_is_due(
                self.tasks_pregnancy, date(2017, 8, 1),
                get_map(pregnancy_products, 'code')['tt_booster'],
                pregnancy_products, []))

        # Immunization is not due when its date range is not valid
        todays_date.return_value = date(2020, 9, 1)
        self.assertFalse(
            immunization_is_due(self.tasks_pregnancy, date(2017, 8, 1),
                                get_map(pregnancy_products, 'code')['tt_1'],
                                pregnancy_products, []))

        # Immunization is not due when it has already been completed
        todays_date.return_value = date(2017, 9, 1)
        self.assertFalse(
            immunization_is_due(
                self.tasks_pregnancy, date(2017, 8, 1),
                get_map(pregnancy_products,
                        'code')['tt_1'], pregnancy_products,
                [LedgerValue(entry_id=self.tt1.get_id, balance=17390)]))
Пример #3
0
    given case for the later check that happens when we check if DPT3 and
    Measles vaccinations are due.

    The actual check for whether the immunizations are due happens at reminder
    runtime. The purpose of this function which is referenced in the rule
    is to just filter down that list of cases under consideration so that
    we process as few as necessary.
    """
    if case.type != 'tasks':
        raise ValueError("This rule criteria should only be applied to cases with case type 'tasks'")

    if case.get_case_property('tasks_type') != 'child':
        return False

    products = get_immunization_products(case.domain, 'child')
    product_code_to_product = get_map(products, 'code')
    dpt3_product = product_code_to_product['3g_dpt_3']
    measles_product = product_code_to_product['4g_measles']

    ledger_values = get_tasks_case_immunization_ledger_values(case)
    product_id_to_ledger_value = get_map(ledger_values, 'entry_id')

    # If either of the vaccinations have happened, do not consider the case
    if (
        dpt3_product.product_id in product_id_to_ledger_value or
        measles_product.product_id in product_id_to_ledger_value
    ):
        return False

    today = todays_date()
    anchor_date = get_immunization_anchor_date(case)
Пример #4
0
def dpt3_and_measles_are_due(recipient, case_schedule_instance):
    """
    Check if the DPT3 and Measles vaccinations are both due, and if so return the
    reminder message.
    """
    case = case_schedule_instance.case
    if case.type != 'tasks':
        raise ValueError("Expected 'tasks' case")

    if case.get_case_property('tasks_type') != 'child':
        raise ValueError("Expected 'tasks_type' of 'child'")

    products = get_immunization_products(case_schedule_instance.domain,
                                         'child')
    product_code_to_product = get_map(products, 'code')
    dpt3_product = product_code_to_product['3g_dpt_3']
    measles_product = product_code_to_product['4g_measles']

    ledger_values = get_tasks_case_immunization_ledger_values(case)
    anchor_date = get_immunization_anchor_date(case)
    if (immunization_is_due(case, anchor_date, dpt3_product, products,
                            ledger_values)
            and immunization_is_due(case, anchor_date, measles_product,
                                    products, ledger_values)):
        child_person_case = child_person_case_from_tasks_case(case)

        if person_case_is_migrated_or_opted_out(child_person_case):
            return []

        context = {