def infer_drug_days_supply(
        days_supply=None,
        refills=None,
        quantity=None,
        default_rx_days=30,
):
    """
    Return the number of days this medication is "active".

    The number of days this medication is active is determined by the
    value of `days_supply` if it exists, and otherwise by a combination
    of the other fields so as to estimate the number of days in the
    prescription.  When the number of days is missing, the quantity is
    assumed to be 1 / day.  When the quantity is missing, each refill is
    assumed to "contain" `default_rx_days`.
    """
    # The total number of fills is `refills + 1`
    if isinstance(refills, int):
        refills += 1
    # Ignore `None` for all fields
    if days_supply is not None:
        if refills:
            return days_supply * refills
        else:
            return days_supply
    elif quantity is not None:
        if refills:
            return quantity * refills
        else:
            return quantity
    elif refills:
        return default_rx_days * refills
    else:
        return default_rx_days