from supabase import create_client, Client
def main(
patient_name: str,
date_of_birth: str,
):
SUPABASE_URL = "https://bgjcrhoasbsgbciumonc.supabase.co"
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJnamNyaG9hc2JzZ2JjaXVtb25jIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU1Mjk2MTcsImV4cCI6MjA2MTEwNTYxN30.eoQmb_y5Li5qa3cheGTAhNM6a_J5Z0B_jQ8xZ4eW4qU" # Shared in a separate email
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
# Get all the appointments
response = supabase.table("appointments").select("*").execute()
appointments = response.data
# Get all the client
response_patient = supabase.table("patients").select("*").execute()
patients = response_patient.data
patient_records = [
pat['id'] for pat in patients if pat['full_name'] == patient_name
and pat['date_of_birth'] == date_of_birth
]
if len(patient_records) == 0:
return {'appointments': []}
# Assume there is only one patient with the same name and date of birth
patient = patient_records[0]
patient_appointments = [
appointment
for appointment in appointments
if appointment['patient_id'] == patient
]
# return value is converted to JSON
return {"appointments": patient_appointments}Submitted by josep bataller i umbert854 368 days ago