Files
agenciapsilmno/src/features/patients/composables/usePatientDetail.js
T
Leonardo 1c2a2b6e19 M2: patients — selects + repository + 8 composables refatorados
Modulo 2 da Fase 1 de padronizacao em batch unico. patientsSelects.js
nova com 11 constantes de select. patientsRepository.js estendido com
~15 funcoes novas (markIntakeConverted, list/get/update por
contexto, etc). 8 composables refatorados em paralelo (usePatients,
useDetail, Financial, Sessions, Messages, Documents, Recurrences,
SupportContacts) — zero supabase.from() em qualquer composable de
patients. _lastPatientId movido pra DENTRO das functions nos 3
composables que tinham. CadastrosRecebidosPage + MelissaCadastros
Recebidos pegam carona dos selects. Aguarda teste batch consolidado.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 04:20:08 -03:00

65 lines
1.9 KiB
JavaScript

/*
|--------------------------------------------------------------------------
| Agência PSI
|--------------------------------------------------------------------------
| Arquivo: src/features/patients/composables/usePatientDetail.js
|
| Detalhe completo de paciente — patient row + grupos + tags. Extraido do
| PatientProntuario.vue pra permitir reuso em MelissaPaciente.vue.
| Mantem a mesma logica (Promise.all em 2 etapas) — agora via repository.
|--------------------------------------------------------------------------
*/
import { ref } from 'vue';
import {
getPatientById,
getPatientRelations,
getGroupsByIds,
getTagsByIds
} from '@/features/patients/services/patientsRepository';
export function usePatientDetail() {
const patient = ref(null);
const groups = ref([]);
const tags = ref([]);
const loading = ref(false);
const loadError = ref('');
async function load(id) {
if (!id) {
patient.value = null;
groups.value = [];
tags.value = [];
return;
}
loading.value = true;
loadError.value = '';
patient.value = null;
groups.value = [];
tags.value = [];
try {
const [p, rel] = await Promise.all([getPatientById(id), getPatientRelations(id)]);
if (!p) throw new Error('Paciente não retornou dados (RLS bloqueando ou ID não existe).');
patient.value = p;
const [g, t] = await Promise.all([
getGroupsByIds(rel.groupIds || []),
getTagsByIds(rel.tagIds || [])
]);
groups.value = g;
tags.value = t;
} catch (e) {
loadError.value = e?.message || 'Falha ao buscar dados.';
} finally {
loading.value = false;
}
}
return {
patient,
groups,
tags,
loading,
loadError,
load
};
}