-- Migration 001: Add confirmed_visits table
-- Run in Supabase SQL Editor: Dashboard > SQL Editor > New query
-- Safe to run multiple times.

create table if not exists confirmed_visits (
  id              uuid        primary key default uuid_generate_v4(),
  org_id          uuid        not null references organizations(id) on delete cascade,
  patient_id_hash text        not null,  -- SHA-256 of patient_id — no raw PHI
  confirmed_date  date        not null,
  confirmed_by    text,                  -- staff identifier (not PHI — just a label)
  created_at      timestamptz not null default now(),
  updated_at      timestamptz not null default now(),
  unique(org_id, patient_id_hash)
);

create index if not exists idx_confirmed_visits_org on confirmed_visits(org_id);
create index if not exists idx_confirmed_visits_hash on confirmed_visits(patient_id_hash);

alter table confirmed_visits enable row level security;
