Documentos Pacientes, Template Documentos Pacientes Saas, Documentos prontuários, Documentos Externos, Visualização Externa, Permissão de Visualização, Render Otimização
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
-- ==========================================================================
|
||||
-- Agência PSI — Migração: tabela `patient_support_contacts`
|
||||
-- ==========================================================================
|
||||
-- Arquivo: supabase/migrations/20260328000004_create_patient_support_contacts.sql
|
||||
-- Criado por: Leonardo Nohama · 2026 · São Carlos/SP
|
||||
--
|
||||
-- Contatos da rede de suporte do paciente.
|
||||
-- Alimenta o card "Contatos & rede de suporte" na tela de detalhe.
|
||||
-- is_primario = true → badge vermelho "emergência" no perfil.
|
||||
-- ==========================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.patient_support_contacts (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
|
||||
patient_id uuid NOT NULL REFERENCES public.patients(id) ON DELETE CASCADE,
|
||||
owner_id uuid NOT NULL,
|
||||
tenant_id uuid NOT NULL,
|
||||
|
||||
nome text,
|
||||
relacao text, -- Ex: mãe, psiquiatra, cônjuge
|
||||
tipo text, -- emergencia | familiar | profissional_saude | amigo | outro
|
||||
telefone text,
|
||||
email text,
|
||||
is_primario boolean DEFAULT false NOT NULL,
|
||||
|
||||
created_at timestamptz DEFAULT now(),
|
||||
updated_at timestamptz DEFAULT now(),
|
||||
|
||||
CONSTRAINT patient_support_contacts_pkey PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
-- Índices
|
||||
CREATE INDEX IF NOT EXISTS psc_patient_idx ON public.patient_support_contacts USING btree (patient_id);
|
||||
CREATE INDEX IF NOT EXISTS psc_owner_idx ON public.patient_support_contacts USING btree (owner_id);
|
||||
|
||||
-- Trigger updated_at
|
||||
CREATE TRIGGER trg_psc_updated_at
|
||||
BEFORE UPDATE ON public.patient_support_contacts
|
||||
FOR EACH ROW EXECUTE FUNCTION public.set_updated_at();
|
||||
|
||||
-- RLS
|
||||
ALTER TABLE public.patient_support_contacts ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
CREATE POLICY "psc: owner full access"
|
||||
ON public.patient_support_contacts
|
||||
USING (owner_id = auth.uid())
|
||||
WITH CHECK (owner_id = auth.uid());
|
||||
|
||||
-- Comentários
|
||||
COMMENT ON TABLE public.patient_support_contacts IS 'Rede de suporte do paciente. Exibida no card "Contatos & rede de suporte" do perfil.';
|
||||
COMMENT ON COLUMN public.patient_support_contacts.is_primario IS 'true = badge vermelho "emergência" no perfil do paciente.';
|
||||
COMMENT ON COLUMN public.patient_support_contacts.tipo IS 'emergencia | familiar | profissional_saude | amigo | outro';
|
||||
|
||||
-- ==========================================================================
|
||||
-- FIM DA MIGRAÇÃO
|
||||
-- ==========================================================================
|
||||
Reference in New Issue
Block a user