Service or Item Eligibility

This procedure was adapted from the uspServiceItemInquiry stored procedure. It is a direct translation to Python/Django with the same caveats as described below.

The request is performed for an insuree on a service or item.

The service proceeds as follows:

  1. Determine the waiting period through Policy -> Product -> ProductService/ProductItem -> WaitingPeriodAdult/Child.
    Verify the Insuree and the Service/Item requested (validity, access)

  2. Perform a query from
    ClaimService -> Claim -> Insuree <- InsureePolicy -> Policy -> Product <- ProductService -> Service

    1. the policy is Active

    2. the Claim is beyond Entered (so submitted/processed/valuated…) or unspecified

    3. the ClaimService status is Passed or unspecified (not yet verified)

      From these, take the product ID, compute the min_date as effective_date + waiting_period
      and services_left/items_left as limit_no - count of services/items in these ClaimServices/Items.
      If there is a product with a min_date before today, take that one for the limit, otherwise take any min_date
      If there is a product where services_left is null and a min_date is before today, consider that there are no services_left, otherwise, take the largest services_left in the product.

  3. This section is only for services:
    Go through the DedRem -> Claim+ClaimService -> Insuree <- InsureePolicy -> Policy -> Product
    For each Service category (Antenatal, Surgery, Delivery, Hospitalization, Consultation, Visit, Other),
    determine the max_amount_(category), max_no_(category) and the amount already claimed (Claim beyond Entered status, not rejected, with dedrem).

This computation counts the number of claims with at least one service of that category. It does not take the "amount" of the ClaimService into consideration. The Claim processing does take the amount into account. For services, it will likely be mostly a single service rendered but it could result in claims being denied the eligibility was positive.

4. The is_service_ok is then determined for surgery, consultation and delivery (only those !) as:
if min_service_date is in the future, total_(category)_left is 0, (all category) services_left is 0 or the
product_max_amount(category) is <=0 then is_service_ok is false. Otherwise, it is true.

For other service categories, it is only considering the total services_left and min_date_service.

For is_items_ok, it is false if there are no items_left or the min_date_item is in the future.

!! The above procedure only considers the first product it finds. If an insuree has several policies with different products, the result is undetermined.