patient cadastro: fix nav pra view individual + rename pra singular
Bug: no melissa, salvar paciente -> "Salvar e ver pacientes" caia em /pages/access. Causa: patientsListRoute() so tinha branches /therapist e /admin, jogava na rota errada que o guard rejeita no contexto melissa. Fix: 1. PatientCadastroDialog + ComponentCadastroRapido — funcao renomeada pra patientViewRoute(patientId). Branch /melissa redireciona pra /melissa/paciente?id=<id> (prontuario individual) quando ha id, ou /melissa/pacientes (lista) sem id. 2. Botao "Salvar e ver pacientes" -> "Salvar e ver paciente" (singular). Reflete a navegacao real: vai pro proprio paciente que acabou de salvar, nao pra lista. 3. onCreated pega data?.id || props.patientId pra montar a rota. Comportamento melissa: salvar paciente -> abre /melissa/paciente ?id=<id> (prontuario). Therapist/admin segue indo pra lista (comportamento pre-existente). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -197,8 +197,17 @@ function generateUser() {
|
||||
});
|
||||
}
|
||||
|
||||
function patientsListRoute() {
|
||||
// Rota de destino do "Salvar e ver paciente". Em melissa, prefere a
|
||||
// view individual do paciente recém-criado (id vem de data.id no
|
||||
// emit('created')); fallback pra lista.
|
||||
function patientViewRoute(patientId) {
|
||||
const p = String(route.path || '');
|
||||
if (p.startsWith('/melissa') && patientId) {
|
||||
return { path: '/melissa/paciente', query: { id: String(patientId) } };
|
||||
}
|
||||
if (p.startsWith('/melissa')) {
|
||||
return '/melissa/pacientes';
|
||||
}
|
||||
return p.startsWith('/therapist') ? '/therapist/patients' : '/admin/pacientes';
|
||||
}
|
||||
|
||||
@@ -252,7 +261,10 @@ async function submit(mode = 'only') {
|
||||
|
||||
emit('created', data);
|
||||
if (props.closeOnCreated) close();
|
||||
if (mode === 'view') await router.push(patientsListRoute());
|
||||
if (mode === 'view') {
|
||||
const pid = data?.id || null;
|
||||
await router.push(patientViewRoute(pid));
|
||||
}
|
||||
} catch (err) {
|
||||
const msg = err?.message || err?.details || 'Não foi possível criar o paciente.';
|
||||
errorMsg.value = msg;
|
||||
@@ -334,10 +346,10 @@ async function submit(mode = 'only') {
|
||||
<!-- Na rota de pacientes OU em fluxo (hideViewListButton): só "Salvar" / "Salvar e fechar" -->
|
||||
<Button v-if="isOnPatientsPage" label="Salvar" :loading="saving" :disabled="saving" @click="submit('only')" />
|
||||
<Button v-else-if="hideViewListButton" label="Salvar e fechar" :loading="saving" :disabled="saving" @click="submit('only')" />
|
||||
<!-- Standalone fora da lista: "Salvar e fechar" + "Salvar e ver pacientes" -->
|
||||
<!-- Standalone fora da lista: "Salvar e fechar" + "Salvar e ver paciente" -->
|
||||
<template v-else>
|
||||
<Button label="Salvar e fechar" severity="secondary" outlined :loading="saving" :disabled="saving" @click="submit('only')" />
|
||||
<Button label="Salvar e ver pacientes" :loading="saving" :disabled="saving" @click="submit('view')" />
|
||||
<Button label="Salvar e ver paciente" :loading="saving" :disabled="saving" @click="submit('view')" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -65,11 +65,22 @@ const router = useRouter();
|
||||
|
||||
const isOnPatientsPage = computed(() => {
|
||||
const p = String(route.path || '');
|
||||
return p.includes('/patients') || p.includes('/pacientes');
|
||||
// /melissa/paciente (singular — prontuário) é página de paciente.
|
||||
// /melissa/pacientes (plural — lista) também.
|
||||
return p.includes('/patients') || p.includes('/pacientes') || p.startsWith('/melissa/paciente');
|
||||
});
|
||||
|
||||
function patientsListRoute() {
|
||||
// Rota de destino quando o usuário pede "Salvar e ver paciente":
|
||||
// — no Melissa, abre o prontuário do paciente (singular, via query id)
|
||||
// — no Therapist/Admin, volta pra lista (não há rota dedicada de view).
|
||||
function patientViewRoute(patientId) {
|
||||
const p = String(route.path || '');
|
||||
if (p.startsWith('/melissa') && patientId) {
|
||||
return { path: '/melissa/paciente', query: { id: String(patientId) } };
|
||||
}
|
||||
if (p.startsWith('/melissa')) {
|
||||
return '/melissa/pacientes';
|
||||
}
|
||||
return p.startsWith('/therapist') ? '/therapist/patients' : '/admin/pacientes';
|
||||
}
|
||||
|
||||
@@ -82,7 +93,9 @@ async function onCreated(data) {
|
||||
isOpen.value = false;
|
||||
emit('created', data);
|
||||
if (pendingMode.value === 'view') {
|
||||
await router.push(patientsListRoute());
|
||||
// data.id vem do PatientsCadastroPage (criação ou edição)
|
||||
const pid = data?.id || props.patientId || null;
|
||||
await router.push(patientViewRoute(pid));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -197,10 +210,10 @@ async function onCreated(data) {
|
||||
<!-- Na rota de pacientes OU em fluxo (hideViewListButton): só um botao -->
|
||||
<Button v-if="isOnPatientsPage" label="Salvar" :loading="!!pageRef?.saving?.value" :disabled="!!pageRef?.saving?.value || !!pageRef?.deleting?.value" @click="submitWith('only')" />
|
||||
<Button v-else-if="hideViewListButton" label="Salvar e fechar" :loading="!!pageRef?.saving?.value" :disabled="!!pageRef?.saving?.value || !!pageRef?.deleting?.value" @click="submitWith('only')" />
|
||||
<!-- Standalone fora da lista: "Salvar e fechar" + "Salvar e ver pacientes" -->
|
||||
<!-- Standalone fora da lista: "Salvar e fechar" + "Salvar e ver paciente" -->
|
||||
<template v-else>
|
||||
<Button label="Salvar e fechar" severity="secondary" outlined :loading="pendingMode === 'only' && !!pageRef?.saving?.value" :disabled="!!pageRef?.saving?.value || !!pageRef?.deleting?.value" @click="submitWith('only')" />
|
||||
<Button label="Salvar e ver pacientes" :loading="pendingMode === 'view' && !!pageRef?.saving?.value" :disabled="!!pageRef?.saving?.value || !!pageRef?.deleting?.value" @click="submitWith('view')" />
|
||||
<Button label="Salvar e ver paciente" :loading="pendingMode === 'view' && !!pageRef?.saving?.value" :disabled="!!pageRef?.saving?.value || !!pageRef?.deleting?.value" @click="submitWith('view')" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user