def is_inpatient(med):
    """Return true if the medication record belong to a valid inpatient order."""
    return med.ordering_mode_name == 'Inpatient' and \
        (med.order_status_name != 'Discontinued' and med.order_status_name != 'Canceled')