def async_mutate(cls, user, **data): if not user.has_perms(ClaimConfig.gql_mutation_process_claims_perms): raise PermissionDenied(_("unauthorized")) errors = [] for claim_uuid in data["uuids"]: logger.debug("ProcessClaimsMutation: processing %s", claim_uuid) c_errors = [] claim = Claim.objects \ .filter(uuid=claim_uuid) \ .prefetch_related("items") \ .prefetch_related("services") \ .first() if claim is None: errors += { 'title': claim_uuid, 'list': [{ 'message': _("claim.validation.id_does_not_exist") % { 'id': claim_uuid } }] } continue claim.save_history() logger.debug("ProcessClaimsMutation: validating claim %s", claim_uuid) c_errors += validate_claim(claim, False) logger.debug( "ProcessClaimsMutation: claim %s validated, nb of errors: %s", claim_uuid, len(c_errors)) if len(c_errors) == 0: c_errors = validate_assign_prod_to_claimitems_and_services( claim) logger.debug( "ProcessClaimsMutation: claim %s assigned, nb of errors: %s", claim_uuid, len(c_errors)) c_errors += process_dedrem(claim, user.id_for_audit, True) logger.debug( "ProcessClaimsMutation: claim %s processed for dedrem, nb of errors: %s", claim_uuid, len(errors)) c_errors += set_claim_processed_or_valuated(claim, c_errors, user) logger.debug( "ProcessClaimsMutation: claim %s set processed or valuated", claim_uuid) if c_errors: errors.append({'title': claim.code, 'list': c_errors}) if len(errors) == 1: errors = errors[0]['list'] logger.debug("ProcessClaimsMutation: claim %s done, errors: %s", claim_uuid, len(errors)) return errors
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 validate_and_process_dedrem_claim(claim, user, is_process): errors = validate_claim(claim, False) logger.debug("ProcessClaimsMutation: claim %s validated, nb of errors: %s", claim.uuid, len(errors)) if len(errors) == 0: errors = validate_assign_prod_to_claimitems_and_services(claim) logger.debug( "ProcessClaimsMutation: claim %s assigned, nb of errors: %s", claim.uuid, len(errors)) errors += process_dedrem(claim, user.id_for_audit, is_process) logger.debug( "ProcessClaimsMutation: claim %s processed for dedrem, nb of errors: %s", claim.uuid, len(errors)) else: # OMT-208 the claim is invalid. If there is a dedrem, we need to clear it (caused by a review) deleted_dedrems = ClaimDedRem.objects.filter(claim=claim).delete() if deleted_dedrems: logger.debug( f"Claim {claim.uuid} is invalid, we deleted its dedrem ({deleted_dedrems})" ) if is_process: errors += set_claim_processed_or_valuated(claim, errors, user) return errors
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()
}) 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) # 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}) 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, 55) 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, 55) self.assertEqual(claim1.status, Claim.STATUS_VALUATED)
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()