Scheduling agent

This script looks for schedules of a client in a database in suapbase, given the patient full name and their dat of birth

Script github

by josep bataller i umbert854 ยท 5/5/2025

  • Submitted by josep bataller i umbert854 Python3
    Created 368 days ago
    1
    from supabase import create_client, Client
    2
    
    
    3
    def main(
    4
        patient_name: str,
    5
        date_of_birth: str,
    6
    ):
    7
        SUPABASE_URL = "https://bgjcrhoasbsgbciumonc.supabase.co"
    8
        SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJnamNyaG9hc2JzZ2JjaXVtb25jIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU1Mjk2MTcsImV4cCI6MjA2MTEwNTYxN30.eoQmb_y5Li5qa3cheGTAhNM6a_J5Z0B_jQ8xZ4eW4qU"  # Shared in a separate email
    9
    
    
    10
        supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
    11
    
    
    12
        # Get all the appointments
    13
        response = supabase.table("appointments").select("*").execute()
    14
        appointments = response.data
    15
    
    
    16
        # Get all the client
    17
        response_patient = supabase.table("patients").select("*").execute()
    18
        patients = response_patient.data
    19
    
    
    20
        patient_records = [
    21
            pat['id'] for pat in patients if pat['full_name'] == patient_name
    22
            and pat['date_of_birth'] == date_of_birth
    23
        ]
    24
        if len(patient_records) == 0:
    25
            return {'appointments': []}
    26
    
    
    27
        # Assume there is only one patient with the same name and date of birth
    28
        patient = patient_records[0]
    29
    
    
    30
        patient_appointments = [
    31
            appointment
    32
            for appointment in appointments
    33
            if appointment['patient_id'] == patient
    34
        ]
    35
    
    
    36
        # return value is converted to JSON
    37
        return {"appointments": patient_appointments}