create table cases ( id bigint primary key generated always as identity, case_id text unique not null, doctor_id uuid references auth.users not null, patient_name text not null, patient_age int not null, patient_gender text not null, case_summary text, status text default 'processing', created_at timestamptz default now(), updated_at timestamptz default now());-- Enable RLSalter table cases enable row level security;-- Policy: Users can only access their own casescreate policy "Users can view own cases" on cases for select using (auth.uid() = doctor_id);create policy "Users can insert own cases" on cases for insert with check (auth.uid() = doctor_id);create policy "Users can update own cases" on cases for update using (auth.uid() = doctor_id);
create table case_files ( id bigint primary key generated always as identity, file_id text unique not null, case_id text references cases(case_id) not null, file_name text not null, file_type text not null, file_size bigint not null, file_url text not null, file_category text not null, -- 'lab' or 'radiology' ai_summary jsonb, upload_date timestamptz default now());alter table case_files enable row level security;create policy "Users can view files for their cases" on case_files for select using ( exists ( select 1 from cases where cases.case_id = case_files.case_id and cases.doctor_id = auth.uid() ) );
-- Allow authenticated users to upload filescreate policy "Authenticated users can upload files" on storage.objects for insert to authenticated with check (bucket_id = 'labdocs');-- Allow users to read their own filescreate policy "Users can view their own files" on storage.objects for select to authenticated using (bucket_id = 'labdocs');
# Create a new caseawait client.create_new_case( case_id="case_123", user_id="user_uuid", patient_name="John Doe", patient_age=45, patient_gender="Male", case_summary="Initial consultation")# Get all cases for a doctorcases = await client.get_all_cases(user_id="user_uuid")# Get specific casecase = await client.get_case_by_id(case_id="case_123")# Update case statusawait client.update_case_status( case_id="case_123", status="completed")