Instruction file imported from yangsi7/ecg-lab-playground (
.cursor/rules/rpc-functions.mdc). Copyright stays with the author.
description: When dealing with supabase rpc functions globs: *.ts
Your rule content
-
SUPABASE, RPC AND EDGEFUNCTION KNOWLEDGE BASE
Available Database RPC Functions and Edge Functions for the Monitoring & Diagnostic Portal
This document merges the previously outlined RPC (Remote Procedure Call) functions with additional functions discovered in your database schema. We also add a new Edge Function example based on the style shown before.
1. Database RPC Functions
RPC Calls (from the code references) get_study_details_with_earliest_latest
Usage: In StudyContext, HolterDetail, etc. to fetch basic study + earliest/latest times. Input: { p_study_id: string } Output: Array with a single object containing study_id, pod_id, earliest_time, latest_time, etc. get_pod_days
Usage: Retrieve an array of distinct days for a given pod. Input: { p_pod_id: string } Output: [ { day_value: string }, ... ] get_clinic_overview
Usage: Summaries for a single clinic (active, total studies, etc.). Input: { _clinic_id: string } Output: [{ active_studies, total_studies, average_quality_hours, recent_alerts }] get_clinic_status_breakdown, get_clinic_quality_breakdown, get_clinic_weekly_quality, get_clinic_monthly_quality, get_clinic_weekly_studies, get_clinic_monthly_studies
Used in ClinicLab, returning different sets of aggregated stats for clinic(s). Inputs: _clinic_id optional or required Outputs: Arrays of objects with relevant summary fields. downsample_ecg
Usage: Returns every nth sample for an ECG for a time range. Called either from an Edge Function or directly. Inputs: { p_pod_id, p_time_start, p_time_end, p_factor } Outputs: Array of data points with sample_time, downsampled_channel_1, etc. aggregate_leads
Usage: Summarizes lead-on and quality across a time bucket. Inputs: { p_pod_id, p_time_start, p_time_end, p_bucket_seconds } Output: [ { time_bucket, lead_on_p_1, ..., quality_1_percent, ...} ] And several other functions, but above are the big ones used in the code.
Edge Functions (in ./supabase/functions) downsample-ecg/index.ts Usage: Receives POST requests with JSON: { pod_id, time_start, time_end, factor }. Internally calls downsample_ecg DB function. Returns: JSON with the downsampled data and metadata about sampling frequency.