def test_waiting_period(self): # When the insuree already reaches his limit of visits # Given from core import datetime insuree = create_test_insuree() child_insuree = create_test_insuree(custom_props={ "dob": datetime.datetime(2020, 1, 1), "family": insuree.family }) self.assertIsNotNone(insuree) product = create_test_product("CSECT") policy = create_test_policy(product, insuree, link=True) policy_child = create_test_policy(product, child_insuree, link=True) service = create_test_service("C") product_service = create_test_product_service( product, service, custom_props={"waiting_period_adult": 6, "waiting_period_child": 0}) pricelist_detail = add_service_to_hf_pricelist(service) # A first claim for a visit within the waiting period should be refused claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice(claim1, custom_props={"service_id": service.id}) errors = validate_claim(claim1, True) self.assertEqual(len(errors), 1, "An adult visit within the waiting period should be refused") self.assertEqual(claim1.services.first().rejection_reason, REJECTION_REASON_WAITING_PERIOD_FAIL) # a visit after the waiting period should be fine claim2 = create_test_claim({ "insuree_id": insuree.id, "date_from": datetime.datetime(2020, 2, 1), "date_to": datetime.datetime(2020, 2, 1), "date_claimed": datetime.datetime(2020, 2, 1), }) service2 = create_test_claimservice(claim2, custom_props={"service_id": service.id}) errors = validate_claim(claim2, True) self.assertEqual(len(errors), 0, "This one should be accepted as after the waiting period") # a child should not have the waiting period claim3 = create_test_claim({"insuree_id": child_insuree.id}) service3 = create_test_claimservice(claim3, custom_props={"service_id": service.id}) errors = validate_claim(claim3, True) self.assertEqual(len(errors), 0, "The child has no waiting period") # tearDown service3.delete() claim3.delete() service2.delete() claim2.delete() service1.delete() claim1.delete() policy.insuree_policies.all().delete() policy.delete() policy_child.insuree_policies.all().delete() policy_child.delete() product_service.delete() pricelist_detail.delete() service.delete() product.delete()
def create_test_policy_holder_insuree(policy_holder=None, insuree=None, contribution_plan_bundle=None, last_policy=None, custom_props={}): if not policy_holder: policy_holder = create_test_policy_holder() if not insuree: insuree = create_test_insuree() if not contribution_plan_bundle: contribution_plan_bundle = create_test_contribution_plan_bundle() if not last_policy: last_policy = create_test_policy(product=create_test_product( "TestCode", custom_props={ "insurance_period": 12, }), insuree=insuree) user = __get_or_create_simple_policy_holder_user() object_data = { 'policy_holder': policy_holder, 'insuree': insuree, 'contribution_plan_bundle': contribution_plan_bundle, 'last_policy': last_policy, 'json_ext': json.dumps("{}"), **custom_props } policy_holder_insuree = PolicyHolderInsuree(**object_data) policy_holder_insuree.save(username=user.username) return policy_holder_insuree
def test_validate_patient_category(self): # When the insuree already reaches his limit of visits # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) product = create_test_product("VISIT", custom_props={"max_no_visits": 1}) policy = create_test_policy(product, insuree, link=True) service = create_test_service("V", custom_props={"patient_category": 1}) product_service = create_test_product_service(product, service) pricelist_detail = add_service_to_hf_pricelist(service) # The insuree has a patient_category of 6, not matching the service category claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice(claim1, custom_props={"service_id": service.id}) errors = validate_claim(claim1, True) # Then claim1.refresh_from_db() self.assertEquals(len(errors), 1) self.assertEquals(errors[0]['code'], 1) # claimed rejected because all services are rejected self.assertEquals(claim1.services.first().rejection_reason, 4) # reason is wrong insuree mask # tearDown service1.delete() claim1.delete() policy.insuree_policies.first().delete() policy.delete() product_service.delete() pricelist_detail.delete() service.delete() product.delete()
def create_test_contract_details(contract=None, insuree=None, contribution_plan_bundle=None, custom_props={}): if not contract: contract = create_test_contract() if not insuree: insuree = create_test_insuree() if not contribution_plan_bundle: contribution_plan_bundle = create_test_contribution_plan_bundle() user = __get_or_create_simple_contract_user() object_data = { 'contract': contract, 'insuree': insuree, 'contribution_plan_bundle': contribution_plan_bundle, 'json_param': json.dumps("{}"), **custom_props } contract_details = ContractDetails(**object_data) contract_details.save(username=user.username) return contract_details
def test_validate_no_insuree(self): officer = create_test_officer(custom_props={"code": "TSTSIMP1"}) insuree = create_test_insuree(custom_props={"chf_id": "paysimp"}) product = create_test_product("ELI1") (policy, insuree_policy) = create_test_policy2(product, insuree, custom_props={ "value": 1000, "status": Policy.STATUS_IDLE}) service = create_test_service("A") svc_pl_detail = add_service_to_hf_pricelist(service) product_service = create_test_product_service(product, service, custom_props={"limit_no_adult": 20}) premium = create_test_premium(policy_id=policy.id, with_payer=False) payment, payment_detail = create_test_payment2( insuree_code=None, product_code=product.code, officer_code=officer.code, ) errors = validate_payment_detail(payment_detail) self.assertGreater(len(errors), 0) self.assertEqual(errors[0]["code"], PAYMENT_DETAIL_REJECTION_INSURANCE_NB) payment_detail.delete() payment.delete() premium.delete() product_service.delete() svc_pl_detail.delete() service.delete() policy.insuree_policies.all().delete() policy.delete() product.delete() insuree.delete() officer.delete()
def test_match_payment_simple(self): officer = create_test_officer(custom_props={"code": "TSTSIMP1"}) insuree = create_test_insuree(custom_props={"chf_id": "paysimp"}) product = create_test_product("ELI1") (policy, insuree_policy) = create_test_policy2(product, insuree, custom_props={ "value": 1000, "status": Policy.STATUS_IDLE}) service = create_test_service("A") svc_pl_detail = add_service_to_hf_pricelist(service) product_service = create_test_product_service(product, service, custom_props={"limit_no_adult": 20}) premium = create_test_premium(policy_id=policy.id, with_payer=False) payment, payment_detail = create_test_payment2( insuree_code=insuree.chf_id, product_code=product.code, officer_code=officer.code, ) match_payment(payment=payment, audit_user_id=-1) payment_detail.refresh_from_db() self.assertEqual(payment_detail.premium, premium) payment_detail.delete() payment.delete() premium.delete() product_service.delete() svc_pl_detail.delete() service.delete() policy.insuree_policies.all().delete() policy.delete() product.delete() insuree.delete() officer.delete()
def test_submit_claim_dedrem_limit_antenatal(self): # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) service = create_test_service("A", custom_props={}) item = create_test_item("A", custom_props={}) product = create_test_product("BCUL0001", custom_props={ "name": "Basic Cover Ultha", "lump_sum": 10_000, "max_amount_antenatal": 55, })
def test_simple_monthly_batch_run(self) -> None: insuree1 = create_test_insuree() self.assertIsNotNone(insuree1) product = create_test_product("TEST1", custom_props={ "location_id": 1, "period_rel_prices": 4 }) policy = create_test_policy(product, insuree1, link=True) service = create_test_service("V") product_service = create_test_product_service( product, service, custom_props={"price_origin": ProductService.ORIGIN_RELATIVE}) pricelist_detail = add_service_to_hf_pricelist(service) premium = create_test_premium(policy_id=policy.id, with_payer=True) create_test_rel_distr_range(product.id, RelativeDistribution.TYPE_QUARTER, RelativeDistribution.CARE_TYPE_BOTH, 10) claim1 = create_test_claim({"insuree_id": insuree1.id}) service1 = create_test_claimservice(claim1, custom_props={ "service_id": service.id, "price_origin": ProductService.ORIGIN_RELATIVE, "product": product }) errors = validate_claim(claim1, True) self.assertEquals(len(errors), 0) errors = validate_assign_prod_to_claimitems_and_services(claim1) self.assertEquals(len(errors), 0) _mark_as_processed(claim1) claim1.refresh_from_db() result = process_batch(1, location_id=1, period=6, year=2019) # tearDown premium.delete() premium.payer.delete() service1.delete() claim1.delete() policy.insuree_policies.first().delete() policy.delete() product_service.delete() pricelist_detail.delete() service.delete() for rd in product.relative_distributions.all(): rd.delete() product.delete()
def test_frequency(self): # When the insuree already reaches his limit of visits # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) product = create_test_product("CSECT") policy = create_test_policy(product, insuree, link=True) service = create_test_service("C", custom_props={ "code": "G34B", "frequency": 180 }) product_service = create_test_product_service(product, service) pricelist_detail = add_service_to_hf_pricelist(service) # A first claim for a visit should be accepted claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice( claim1, custom_props={"service_id": service.id}) errors = validate_claim(claim1, True) mark_test_claim_as_processed(claim1) self.assertEquals(len(errors), 0, "The first visit should be accepted") # a second visit should be denied claim2 = create_test_claim({"insuree_id": insuree.id}) service2 = create_test_claimservice( claim2, custom_props={"service_id": service.id}) errors = validate_claim(claim2, True) self.assertGreater( len(errors), 0, "The second service should be refused as it is withing 180 days") # Then claim1.refresh_from_db() claim2.refresh_from_db() # tearDown service2.delete() claim2.delete() service1.delete() claim1.delete() policy.insuree_policies.first().delete() policy.delete() product_service.delete() pricelist_detail.delete() service.delete() product.delete()
def test_limit_surgery(self): # When the insuree already reaches his limit of visits # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) product = create_test_product("DELIV", custom_props={"max_no_surgery": 1}) policy = create_test_policy(product, insuree, link=True) service = create_test_service("S", custom_props={"code": "SSSS"}) product_service = create_test_product_service(product, service) pricelist_detail = add_service_to_hf_pricelist(service) # A first claim for a delivery should be accepted claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice( claim1, custom_props={"service_id": service.id}) errors = validate_claim(claim1, True) mark_test_claim_as_processed(claim1) self.assertEquals(len(errors), 0, "The first surgery should be accepted") # a second delivery should be denied claim2 = create_test_claim({"insuree_id": insuree.id}) service2 = create_test_claimservice( claim2, custom_props={"service_id": service.id}) errors = validate_claim(claim2, True) self.assertGreater( len(errors), 0, "The second service should fail because there is already one surgery" ) # Then claim1.refresh_from_db() claim2.refresh_from_db() # tearDown service2.delete() claim2.delete() service1.delete() claim1.delete() policy.insuree_policies.first().delete() policy.delete() product_service.delete() pricelist_detail.delete() service.delete() product.delete()
def create_test_contract_contribution_plan_details(contribution_plan=None, policy=None, contract_details=None, contribution=None, custom_props={}): if not contribution_plan: contribution_plan = create_test_contribution_plan() if not policy: policy = create_test_policy(product=create_test_product( "TestCode", custom_props={ "insurance_period": 12, }), insuree=create_test_insuree()) if not contract_details: contract_details = create_test_contract_details() if not contribution: contribution = Premium.objects.create( **{ "policy_id": policy.id, "payer_id": None, "amount": 1000, "receipt": "Test receipt", "pay_date": "2019-01-01", "validity_from": "2019-01-01", "audit_user_id": -1, }) user = __get_or_create_simple_contract_user() object_data = { 'contribution_plan': contribution_plan, 'policy': policy, 'contract_details': contract_details, 'contribution': contribution, 'json_ext': json.dumps("{}"), **custom_props } contract_contribution_plan_details = ContractContributionPlanDetails( **object_data) contract_contribution_plan_details.save(username=user.username) return contract_contribution_plan_details
def test_validate_max_visits(self): # When the insuree already reaches his limit of visits # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) product = create_test_product("VISIT", custom_props={"max_no_visits": 1}) policy = create_test_policy(product, insuree, link=True) service = create_test_service("V") product_service = create_test_product_service(product, service) pricelist_detail = add_service_to_hf_pricelist(service) # A first claim for a visit should be accepted claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice( claim1, custom_props={"service_id": service.id}) errors = validate_claim(claim1, True) self.assertEquals(len(errors), 0, "The first visit should be accepted") # a second visit should be denied claim2 = create_test_claim({"insuree_id": insuree.id}) service2 = create_test_claimservice(claim2, "V") errors = validate_claim(claim2, True) # TODO Temporarily disabled # self.assertGreater(len(errors), 0, "The second visit should be refused") # Then claim1.refresh_from_db() claim2.refresh_from_db() # tearDown service2.delete() claim2.delete() service1.delete() claim1.delete() policy.insuree_policies.first().delete() policy.delete() product_service.delete() pricelist_detail.delete() service.delete() product.delete()
def setUpClass(cls): PolicyHolder.objects.filter(code=cls.POLICY_HOLDER['code']).delete() if not User.objects.filter(username='******').exists(): User.objects.create_superuser(username='******', password='******') cls.user = User.objects.filter(username='******').first() cls.policy_holder_service = PolicyHolderService(cls.user) cls.policy_holder_insuree_service = PolicyHolderInsureeService( cls.user) cls.policy_holder_contribution_plan_service = PolicyHolderContributionPlanService( cls.user) cls.test_policy_holder = create_test_policy_holder() cls.test_policy_holder_insuree = create_test_policy_holder_insuree() cls.test_insuree = cls.test_policy_holder_insuree.insuree cls.test_insuree_to_change = create_test_insuree() cls.test_contribution_plan_bundle = cls.test_policy_holder_insuree.contribution_plan_bundle cls.test_last_policy = cls.test_policy_holder_insuree.last_policy cls.test_contribution_plan_bundle_to_replace = create_test_contribution_plan_bundle( )
def test_validate_invalid_product_location(self): location_r1 = Location.filter_queryset().get(code="R1") location_r2 = Location.filter_queryset().get(code="R2") officer = create_test_officer(custom_props={"code": "TSTSIMP1"}) insuree = create_test_insuree(custom_props={"chf_id": "paysimp"}, family_custom_props={"location": location_r1}) # Family in R1 ! product = create_test_product("ELI1", custom_props={"location": location_r2}) # Product in R2 ! (policy, insuree_policy) = create_test_policy2( product, insuree, custom_props={"value": 1000, "status": Policy.STATUS_IDLE}) service = create_test_service("A") svc_pl_detail = add_service_to_hf_pricelist(service) product_service = create_test_product_service(product, service, custom_props={"limit_no_adult": 20}) premium = create_test_premium(policy_id=policy.id, with_payer=False) payment, payment_detail = create_test_payment2( insuree_code=insuree.chf_id, product_code=product.code, officer_code=officer.code, ) errors = validate_payment_detail(payment_detail) self.assertGreater(len(errors), 0) self.assertEqual(errors[0]["code"], PAYMENT_DETAIL_REJECTION_PRODUCT_NOT_ALLOWED) payment_detail.delete() payment.delete() premium.delete() product_service.delete() svc_pl_detail.delete() service.delete() policy.insuree_policies.all().delete() policy.delete() product.delete() insuree.delete() officer.delete()
def test_submit_claim_dedrem(self): # When the insuree already reaches his limit of visits # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) product = create_test_product("VISIT", custom_props={}) policy = create_test_policy(product, insuree, link=True) service = create_test_service("V", custom_props={}) item = create_test_item("D", custom_props={}) product_service = create_test_product_service(product, service) product_item = create_test_product_item(product, item) pricelist_detail1 = add_service_to_hf_pricelist(service) pricelist_detail2 = add_item_to_hf_pricelist(item) claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice( claim1, custom_props={"service_id": service.id}) item1 = create_test_claimitem(claim1, "D", custom_props={"item_id": item.id}) errors = validate_claim(claim1, True) errors += validate_assign_prod_to_claimitems_and_services(claim1) errors += process_dedrem(claim1, -1, True) self.assertEqual(len(errors), 0) # Then claim1.refresh_from_db() item1.refresh_from_db() service1.refresh_from_db() self.assertEqual(len(errors), 0) self.assertEqual(item1.price_adjusted, 100) self.assertEqual(item1.price_valuated, 700) self.assertEqual(item1.deductable_amount, 0) self.assertEqual(item1.exceed_ceiling_amount, 0) self.assertIsNone(item1.exceed_ceiling_amount_category) self.assertEqual(item1.remunerated_amount, 700) self.assertEqual(claim1.status, Claim.STATUS_VALUATED) self.assertEqual(claim1.audit_user_id_process, -1) self.assertIsNotNone(claim1.process_stamp) self.assertIsNotNone(claim1.date_processed) dedrem_qs = ClaimDedRem.objects.filter(claim=claim1) self.assertEqual(dedrem_qs.count(), 1) dedrem1 = dedrem_qs.first() self.assertEqual(dedrem1.policy_id, item1.policy_id) self.assertEqual(dedrem1.insuree_id, claim1.insuree_id) self.assertEqual(dedrem1.audit_user_id, -1) self.assertEqual(dedrem1.ded_g, 0) self.assertEqual(dedrem1.rem_g, 1400) self.assertEqual(dedrem1.rem_op, 1400) self.assertIsNone(dedrem1.rem_ip) self.assertEqual(dedrem1.rem_surgery, 0) self.assertEqual(dedrem1.rem_consult, 0) self.assertEqual(dedrem1.rem_hospitalization, 0) self.assertIsNotNone(claim1.validity_from) self.assertIsNone(claim1.validity_to) # tearDown dedrem_qs.delete() service1.delete() item1.delete() claim1.delete() policy.insuree_policies.first().delete() policy.delete() product_item.delete() product_service.delete() pricelist_detail1.delete() pricelist_detail2.delete() service.delete() item.delete() product.delete()
def test_review_reject_delete_dedrem(self): """ This test creates a claim, submits it so that it gets dedrem entries, then submits a review rejecting part of it, then process the claim. It should not be processed (which was ok) but the dedrem should be deleted. """ # Given insuree = create_test_insuree() self.assertIsNotNone(insuree) service = create_test_service("A", custom_props={"name": "test_review_reject_delete_dedrem"}) item = create_test_item("A", custom_props={"name": "test_review_reject_delete_dedrem"}) product = create_test_product("BCUL0001", custom_props={ "name": "Basic Cover Ultha deldedrem", "lump_sum": 10_000, }) product_service = create_test_product_service(product, service) product_item = create_test_product_item(product, item) policy = create_test_policy(product, insuree, link=True) pricelist_detail1 = add_service_to_hf_pricelist(service) pricelist_detail2 = add_item_to_hf_pricelist(item) claim1 = create_test_claim({"insuree_id": insuree.id}) service1 = create_test_claimservice( claim1, custom_props={"service_id": service.id, "qty_provided": 2}) item1 = create_test_claimitem( claim1, "A", custom_props={"item_id": item.id, "qty_provided": 3}) errors = validate_claim(claim1, True) errors += validate_assign_prod_to_claimitems_and_services(claim1) errors += process_dedrem(claim1, -1, False) self.assertEqual(len(errors), 0) # Make sure that the dedrem was generated dedrem = ClaimDedRem.objects.filter(claim=claim1).first() self.assertIsNotNone(dedrem) self.assertEquals(dedrem.rem_g, 500) # 100*2 + 100*3 # Review the claim and reject all of it # A partial rejection would still trigger the process_dedrem and be fine item1.qty_approved = 0 item1.price_approved = 0 item1.status = ClaimItem.STATUS_REJECTED item1.rejection_reason = -1 item1.audit_user_id_review = -1 item1.justification = "Review comment item" item1.save() service1.qty_approved = 0 service1.price_approved = 0 service1.status = ClaimItem.STATUS_REJECTED service1.rejection_reason = -1 service1.audit_user_id_review = -1 service1.justification = "Review comment svc" service1.save() claim1.refresh_from_db() item1.refresh_from_db() service1.refresh_from_db() set_claims_status([claim1.uuid], "review_status", Claim.REVIEW_DELIVERED) update_claims_dedrems([claim1.uuid], User.objects.first()) errors = validate_claim(claim1, True) if len(errors) == 0: errors += validate_assign_prod_to_claimitems_and_services(claim1) errors += process_dedrem(claim1, -1, False) # The claim should be globally rejected since the review rejected all items/svc claim1.refresh_from_db() item1.refresh_from_db() service1.refresh_from_db() self.assertEquals(claim1.status, Claim.STATUS_REJECTED) self.assertEquals(claim1.rejection_reason, REJECTION_REASON_INVALID_ITEM_OR_SERVICE) self.assertEquals(item1.status, ClaimDetail.STATUS_REJECTED) self.assertEquals(item1.rejection_reason, -1) self.assertEquals(service1.status, ClaimDetail.STATUS_REJECTED) self.assertEquals(service1.rejection_reason, -1) # Then dedrem should have been deleted dedrem = ClaimDedRem.objects.filter(claim=claim1).first() self.assertIsNone(dedrem) # tearDown # dedrem.delete() # already done if the test passed delete_claim_with_itemsvc_dedrem_and_history(claim1) policy.insuree_policies.first().delete() policy.delete() product_item.delete() product_service.delete() pricelist_detail1.delete() pricelist_detail2.delete() service.delete() item.delete() product.delete()