The Kaiser Permanente mobile app receives appointment objects containing scheduling and clinician details. Implement a function that filters appointments to those that are scheduled, meet a minimum number of days before the visit, and belong to an allowed specialty, then maps each match to the smaller object needed by an appointment card.
Return matching objects in their original input order. Do not modify the input list or its objects.
Implement filter_appointments(appointments, allowed_specialties, min_days).
appointments is a list of dictionaries. Every dictionary contains string keys appointment_id, clinician, specialty, and status, plus an integer days_until.allowed_specialties is a list of specialty strings.min_days is an integer. An appointment qualifies when status is exactly "scheduled", specialty is allowed, and days_until >= min_days.appointment_id, clinician, specialty, and days_until.Use a set for efficient specialty membership checks.
def filter_appointments(appointments, allowed_specialties, min_days):