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)))
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)]))
def test_get_immunization_products(self): self.assertItemsEqual([ p.product_id for p in get_immunization_products(self.domain, 'child') ], [self.dpt2.get_id, self.dpt3.get_id]) self.assertItemsEqual([ p.product_id for p in get_immunization_products(self.domain, 'pregnancy') ], [ self.tt1.get_id, self.ttbooster.get_id, self.anc1.get_id, self.anc2.get_id ])
] 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 []