forked from RiseUP/riseup-squad21
função editar incompleta
This commit is contained in:
parent
cb598058d6
commit
9ed0952d32
@ -14,56 +14,13 @@ import { ArrowLeft, Save, Trash2, Paperclip, Upload } from "lucide-react";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import SecretaryLayout from "@/components/secretary-layout";
|
import SecretaryLayout from "@/components/secretary-layout";
|
||||||
|
import { patientsService } from "@/services/patientsApi.mjs";
|
||||||
// Mock data - in a real app, this would come from an API
|
import { json } from "stream/consumers";
|
||||||
const mockPatients = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
nome: "Aaron Avalos Perez",
|
|
||||||
cpf: "123.456.789-00",
|
|
||||||
rg: "12.345.678-9",
|
|
||||||
sexo: "masculino",
|
|
||||||
dataNascimento: "1990-01-15",
|
|
||||||
etnia: "branca",
|
|
||||||
raca: "caucasiana",
|
|
||||||
naturalidade: "Aracaju",
|
|
||||||
nacionalidade: "brasileira",
|
|
||||||
profissao: "Engenheiro",
|
|
||||||
estadoCivil: "solteiro",
|
|
||||||
nomeMae: "Maria Perez",
|
|
||||||
profissaoMae: "Professora",
|
|
||||||
nomePai: "João Perez",
|
|
||||||
profissaoPai: "Médico",
|
|
||||||
nomeResponsavel: "",
|
|
||||||
cpfResponsavel: "",
|
|
||||||
nomeEsposo: "",
|
|
||||||
email: "aaron@email.com",
|
|
||||||
celular: "(79) 99943-2499",
|
|
||||||
telefone1: "(79) 3214-5678",
|
|
||||||
telefone2: "",
|
|
||||||
cep: "49000-000",
|
|
||||||
endereco: "Rua das Flores, 123",
|
|
||||||
numero: "123",
|
|
||||||
complemento: "Apt 101",
|
|
||||||
bairro: "Centro",
|
|
||||||
cidade: "Aracaju",
|
|
||||||
estado: "SE",
|
|
||||||
tipoSanguineo: "O+",
|
|
||||||
peso: "75",
|
|
||||||
altura: "1.75",
|
|
||||||
alergias: "Nenhuma alergia conhecida",
|
|
||||||
convenio: "Particular",
|
|
||||||
plano: "Premium",
|
|
||||||
numeroMatricula: "123456789",
|
|
||||||
validadeCarteira: "2025-12-31",
|
|
||||||
observacoes: "Paciente colaborativo",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function EditarPacientePage() {
|
export default function EditarPacientePage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const patientId = Number.parseInt(params.id as string);
|
const patientId = params.id;
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
// Photo upload state
|
// Photo upload state
|
||||||
@ -75,45 +32,107 @@ export default function EditarPacientePage() {
|
|||||||
const [isUploadingAnexo, setIsUploadingAnexo] = useState(false);
|
const [isUploadingAnexo, setIsUploadingAnexo] = useState(false);
|
||||||
const anexoInputRef = useRef<HTMLInputElement | null>(null);
|
const anexoInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
const [formData, setFormData] = useState({
|
type FormData = {
|
||||||
|
nome: string; // full_name
|
||||||
|
cpf: string;
|
||||||
|
dataNascimento: string; // birth_date
|
||||||
|
sexo: string; // sex
|
||||||
|
id?: string;
|
||||||
|
nomeSocial?: string; // social_name
|
||||||
|
rg?: string;
|
||||||
|
documentType?: string; // document_type
|
||||||
|
documentNumber?: string; // document_number
|
||||||
|
ethnicity?: string;
|
||||||
|
race?: string;
|
||||||
|
naturality?: string;
|
||||||
|
nationality?: string;
|
||||||
|
profession?: string;
|
||||||
|
maritalStatus?: string; // marital_status
|
||||||
|
motherName?: string; // mother_name
|
||||||
|
motherProfession?: string; // mother_profession
|
||||||
|
fatherName?: string; // father_name
|
||||||
|
fatherProfession?: string; // father_profession
|
||||||
|
guardianName?: string; // guardian_name
|
||||||
|
guardianCpf?: string; // guardian_cpf
|
||||||
|
spouseName?: string; // spouse_name
|
||||||
|
rnInInsurance?: boolean; // rn_in_insurance
|
||||||
|
legacyCode?: string; // legacy_code
|
||||||
|
notes?: string;
|
||||||
|
email?: string;
|
||||||
|
phoneMobile?: string; // phone_mobile
|
||||||
|
phone1?: string;
|
||||||
|
phone2?: string;
|
||||||
|
cep?: string;
|
||||||
|
street?: string;
|
||||||
|
number?: string;
|
||||||
|
complement?: string;
|
||||||
|
neighborhood?: string;
|
||||||
|
city?: string;
|
||||||
|
state?: string;
|
||||||
|
reference?: string;
|
||||||
|
vip?: boolean;
|
||||||
|
lastVisitAt?: string;
|
||||||
|
nextAppointmentAt?: string;
|
||||||
|
createdAt?: string;
|
||||||
|
updatedAt?: string;
|
||||||
|
createdBy?: string;
|
||||||
|
updatedBy?: string;
|
||||||
|
weightKg?: string;
|
||||||
|
heightM?: string;
|
||||||
|
bmi?: string;
|
||||||
|
bloodType?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const [formData, setFormData] = useState<FormData>({
|
||||||
nome: "",
|
nome: "",
|
||||||
cpf: "",
|
cpf: "",
|
||||||
rg: "",
|
|
||||||
sexo: "",
|
|
||||||
dataNascimento: "",
|
dataNascimento: "",
|
||||||
etnia: "",
|
sexo: "",
|
||||||
raca: "",
|
id: "",
|
||||||
naturalidade: "",
|
nomeSocial: "",
|
||||||
nacionalidade: "",
|
rg: "",
|
||||||
profissao: "",
|
documentType: "",
|
||||||
estadoCivil: "",
|
documentNumber: "",
|
||||||
nomeMae: "",
|
ethnicity: "",
|
||||||
profissaoMae: "",
|
race: "",
|
||||||
nomePai: "",
|
naturality: "",
|
||||||
profissaoPai: "",
|
nationality: "",
|
||||||
nomeResponsavel: "",
|
profession: "",
|
||||||
cpfResponsavel: "",
|
maritalStatus: "",
|
||||||
nomeEsposo: "",
|
motherName: "",
|
||||||
|
motherProfession: "",
|
||||||
|
fatherName: "",
|
||||||
|
fatherProfession: "",
|
||||||
|
guardianName: "",
|
||||||
|
guardianCpf: "",
|
||||||
|
spouseName: "",
|
||||||
|
rnInInsurance: false,
|
||||||
|
legacyCode: "",
|
||||||
|
notes: "",
|
||||||
email: "",
|
email: "",
|
||||||
celular: "",
|
phoneMobile: "",
|
||||||
telefone1: "",
|
phone1: "",
|
||||||
telefone2: "",
|
phone2: "",
|
||||||
cep: "",
|
cep: "",
|
||||||
endereco: "",
|
street: "",
|
||||||
numero: "",
|
number: "",
|
||||||
complemento: "",
|
complement: "",
|
||||||
bairro: "",
|
neighborhood: "",
|
||||||
cidade: "",
|
city: "",
|
||||||
estado: "",
|
state: "",
|
||||||
tipoSanguineo: "",
|
reference: "",
|
||||||
peso: "",
|
vip: false,
|
||||||
altura: "",
|
lastVisitAt: "",
|
||||||
alergias: "",
|
nextAppointmentAt: "",
|
||||||
convenio: "",
|
createdAt: "",
|
||||||
plano: "",
|
updatedAt: "",
|
||||||
numeroMatricula: "",
|
createdBy: "",
|
||||||
validadeCarteira: "",
|
updatedBy: "",
|
||||||
observacoes: "",
|
weightKg: "",
|
||||||
|
heightM: "",
|
||||||
|
bmi: "",
|
||||||
|
bloodType: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const [isGuiaConvenio, setIsGuiaConvenio] = useState(false);
|
const [isGuiaConvenio, setIsGuiaConvenio] = useState(false);
|
||||||
@ -122,169 +141,66 @@ export default function EditarPacientePage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchPatient() {
|
async function fetchPatient() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}`);
|
const res = await patientsService.getById(patientId);
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
||||||
const json = await res.json();
|
|
||||||
const p = json?.data || json;
|
|
||||||
// Map API snake_case/nested to local camelCase form
|
// Map API snake_case/nested to local camelCase form
|
||||||
setFormData({
|
setFormData({
|
||||||
nome: p?.nome ?? "",
|
id: res[0]?.id ?? "",
|
||||||
cpf: p?.cpf ?? "",
|
nome: res[0]?.full_name ?? "",
|
||||||
rg: p?.rg ?? "",
|
nomeSocial: res[0]?.social_name ?? "",
|
||||||
sexo: p?.sexo ?? "",
|
cpf: res[0]?.cpf ?? "",
|
||||||
dataNascimento: p?.data_nascimento ?? p?.dataNascimento ?? "",
|
rg: res[0]?.rg ?? "",
|
||||||
etnia: p?.etnia ?? "",
|
documentType: res[0]?.document_type ?? "",
|
||||||
raca: p?.raca ?? "",
|
documentNumber: res[0]?.document_number ?? "",
|
||||||
naturalidade: p?.naturalidade ?? "",
|
sexo: res[0]?.sex ?? "",
|
||||||
nacionalidade: p?.nacionalidade ?? "",
|
dataNascimento: res[0]?.birth_date ?? "",
|
||||||
profissao: p?.profissao ?? "",
|
ethnicity: res[0]?.ethnicity ?? "",
|
||||||
estadoCivil: p?.estado_civil ?? p?.estadoCivil ?? "",
|
race: res[0]?.race ?? "",
|
||||||
nomeMae: p?.nome_mae ?? p?.nomeMae ?? "",
|
naturality: res[0]?.naturality ?? "",
|
||||||
profissaoMae: p?.profissao_mae ?? p?.profissaoMae ?? "",
|
nationality: res[0]?.nationality ?? "",
|
||||||
nomePai: p?.nome_pai ?? p?.nomePai ?? "",
|
profession: res[0]?.profession ?? "",
|
||||||
profissaoPai: p?.profissao_pai ?? p?.profissaoPai ?? "",
|
maritalStatus: res[0]?.marital_status ?? "",
|
||||||
nomeResponsavel: p?.nome_responsavel ?? p?.nomeResponsavel ?? "",
|
motherName: res[0]?.mother_name ?? "",
|
||||||
cpfResponsavel: p?.cpf_responsavel ?? p?.cpfResponsavel ?? "",
|
motherProfession: res[0]?.mother_profession ?? "",
|
||||||
nomeEsposo: p?.nome_esposo ?? p?.nomeEsposo ?? "",
|
fatherName: res[0]?.father_name ?? "",
|
||||||
email: p?.contato?.email ?? p?.email ?? "",
|
fatherProfession: res[0]?.father_profession ?? "",
|
||||||
celular: p?.contato?.celular ?? p?.celular ?? "",
|
guardianName: res[0]?.guardian_name ?? "",
|
||||||
telefone1: p?.contato?.telefone1 ?? p?.telefone1 ?? "",
|
guardianCpf: res[0]?.guardian_cpf ?? "",
|
||||||
telefone2: p?.contato?.telefone2 ?? p?.telefone2 ?? "",
|
spouseName: res[0]?.spouse_name ?? "",
|
||||||
cep: p?.endereco?.cep ?? p?.cep ?? "",
|
rnInInsurance: res[0]?.rn_in_insurance ?? false,
|
||||||
endereco: p?.endereco?.logradouro ?? p?.endereco ?? "",
|
legacyCode: res[0]?.legacy_code ?? "",
|
||||||
numero: p?.endereco?.numero ?? p?.numero ?? "",
|
notes: res[0]?.notes ?? "",
|
||||||
complemento: p?.endereco?.complemento ?? p?.complemento ?? "",
|
email: res[0]?.email ?? "",
|
||||||
bairro: p?.endereco?.bairro ?? p?.bairro ?? "",
|
phoneMobile: res[0]?.phone_mobile ?? "",
|
||||||
cidade: p?.endereco?.cidade ?? p?.cidade ?? "",
|
phone1: res[0]?.phone1 ?? "",
|
||||||
estado: p?.endereco?.estado ?? p?.estado ?? "",
|
phone2: res[0]?.phone2 ?? "",
|
||||||
tipoSanguineo: p?.tipo_sanguineo ?? p?.tipoSanguineo ?? "",
|
cep: res[0]?.cep ?? "",
|
||||||
peso: p?.peso ? String(p.peso) : "",
|
street: res[0]?.street ?? "",
|
||||||
altura: p?.altura ? String(p.altura) : "",
|
number: res[0]?.number ?? "",
|
||||||
alergias: p?.alergias ?? "",
|
complement: res[0]?.complement ?? "",
|
||||||
convenio: p?.convenio ?? "",
|
neighborhood: res[0]?.neighborhood ?? "",
|
||||||
plano: p?.plano ?? "",
|
city: res[0]?.city ?? "",
|
||||||
numeroMatricula: p?.numero_matricula ?? p?.numeroMatricula ?? "",
|
state: res[0]?.state ?? "",
|
||||||
validadeCarteira: p?.validade_carteira ?? p?.validadeCarteira ?? "",
|
reference: res[0]?.reference ?? "",
|
||||||
observacoes: p?.observacoes ?? "",
|
vip: res[0]?.vip ?? false,
|
||||||
|
lastVisitAt: res[0]?.last_visit_at ?? "",
|
||||||
|
nextAppointmentAt: res[0]?.next_appointment_at ?? "",
|
||||||
|
createdAt: res[0]?.created_at ?? "",
|
||||||
|
updatedAt: res[0]?.updated_at ?? "",
|
||||||
|
createdBy: res[0]?.created_by ?? "",
|
||||||
|
updatedBy: res[0]?.updated_by ?? "",
|
||||||
|
weightKg: res[0]?.weight_kg ? String(res[0].weight_kg) : "",
|
||||||
|
heightM: res[0]?.height_m ? String(res[0].height_m) : "",
|
||||||
|
bmi: res[0]?.bmi ? String(res[0].bmi) : "",
|
||||||
|
bloodType: res[0]?.blood_type ?? "",
|
||||||
});
|
});
|
||||||
const foto = p?.foto_url || p?.fotoUrl;
|
|
||||||
if (foto) setPhotoUrl(foto);
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
toast({ title: "Erro", description: e?.message || "Falha ao carregar paciente" });
|
toast({ title: "Erro", description: e?.message || "Falha ao carregar paciente" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function fetchAnexos() {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}/anexos`);
|
|
||||||
if (!res.ok) return;
|
|
||||||
const json = await res.json();
|
|
||||||
const items = Array.isArray(json?.data) ? json.data : json;
|
|
||||||
setAnexos(Array.isArray(items) ? items : []);
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
fetchPatient();
|
fetchPatient();
|
||||||
fetchAnexos();
|
|
||||||
}, [patientId, toast]);
|
}, [patientId, toast]);
|
||||||
|
|
||||||
const onPickPhoto = () => fileInputRef.current?.click();
|
|
||||||
|
|
||||||
const onPhotoSelected = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
try {
|
|
||||||
setIsUploadingPhoto(true);
|
|
||||||
const form = new FormData();
|
|
||||||
// Common field name: 'foto'; also append 'file' for compatibility with some mocks
|
|
||||||
form.append("foto", file);
|
|
||||||
form.append("file", file);
|
|
||||||
|
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}/foto`, {
|
|
||||||
method: "POST",
|
|
||||||
body: form,
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(`Falha no upload (HTTP ${res.status})`);
|
|
||||||
}
|
|
||||||
let msg = "Foto enviada com sucesso";
|
|
||||||
try {
|
|
||||||
const payload = await res.json();
|
|
||||||
if (payload?.success === false) {
|
|
||||||
throw new Error(payload?.message || "A API retornou erro");
|
|
||||||
}
|
|
||||||
if (payload?.message) msg = String(payload.message);
|
|
||||||
if (payload?.data?.foto_url || payload?.foto_url || payload?.url) {
|
|
||||||
setPhotoUrl(payload.data?.foto_url ?? payload.foto_url ?? payload.url);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Ignore JSON parse errors
|
|
||||||
}
|
|
||||||
toast({ title: "Sucesso", description: msg });
|
|
||||||
} catch (err: any) {
|
|
||||||
toast({ title: "Erro", description: err?.message || "Não foi possível enviar a foto" });
|
|
||||||
} finally {
|
|
||||||
setIsUploadingPhoto(false);
|
|
||||||
// clear the input to allow re-selecting the same file
|
|
||||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Remove patient photo via API
|
|
||||||
const onRemovePhoto = async () => {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}/foto`, {
|
|
||||||
method: "DELETE",
|
|
||||||
});
|
|
||||||
if (!res.ok) throw new Error(`Falha ao remover foto (HTTP ${res.status})`);
|
|
||||||
setPhotoUrl(null);
|
|
||||||
toast({ title: "Sucesso", description: "Foto removida" });
|
|
||||||
} catch (err: any) {
|
|
||||||
toast({ title: "Erro", description: err?.message || "Não foi possível remover a foto" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Anexos helpers
|
|
||||||
const onPickAnexo = () => anexoInputRef.current?.click();
|
|
||||||
|
|
||||||
const onAnexoSelected = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
try {
|
|
||||||
setIsUploadingAnexo(true);
|
|
||||||
const form = new FormData();
|
|
||||||
form.append("anexo", file);
|
|
||||||
form.append("file", file);
|
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}/anexos`, {
|
|
||||||
method: "POST",
|
|
||||||
body: form,
|
|
||||||
});
|
|
||||||
if (!res.ok) throw new Error(`Falha ao enviar anexo (HTTP ${res.status})`);
|
|
||||||
// Refresh anexos list
|
|
||||||
try {
|
|
||||||
const refreshed = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}/anexos`);
|
|
||||||
const json = await refreshed.json();
|
|
||||||
const items = Array.isArray(json?.data) ? json.data : json;
|
|
||||||
setAnexos(Array.isArray(items) ? items : []);
|
|
||||||
} catch {}
|
|
||||||
toast({ title: "Sucesso", description: "Anexo adicionado" });
|
|
||||||
} catch (err: any) {
|
|
||||||
toast({ title: "Erro", description: err?.message || "Não foi possível enviar o anexo" });
|
|
||||||
} finally {
|
|
||||||
setIsUploadingAnexo(false);
|
|
||||||
if (anexoInputRef.current) anexoInputRef.current.value = "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDeleteAnexo = async (anexoId: string | number) => {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}/anexos/${anexoId}`, { method: "DELETE" });
|
|
||||||
if (!res.ok) throw new Error(`Falha ao remover anexo (HTTP ${res.status})`);
|
|
||||||
setAnexos((prev) => prev.filter((a) => String(a.id) !== String(anexoId)));
|
|
||||||
toast({ title: "Sucesso", description: "Anexo removido" });
|
|
||||||
} catch (err: any) {
|
|
||||||
toast({ title: "Erro", description: err?.message || "Não foi possível remover o anexo" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleInputChange = (field: string, value: string) => {
|
const handleInputChange = (field: string, value: string) => {
|
||||||
setFormData((prev) => ({ ...prev, [field]: value }));
|
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||||
};
|
};
|
||||||
@ -293,97 +209,38 @@ export default function EditarPacientePage() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Build API payload (snake_case)
|
// Build API payload (snake_case)
|
||||||
const payload = {
|
const payload = {
|
||||||
nome: formData.nome,
|
full_name: formData.nome || null,
|
||||||
cpf: formData.cpf,
|
cpf: formData.cpf || null,
|
||||||
rg: formData.rg || null,
|
|
||||||
sexo: formData.sexo || null,
|
|
||||||
data_nascimento: formData.dataNascimento || null,
|
|
||||||
etnia: formData.etnia || null,
|
|
||||||
raca: formData.raca || null,
|
|
||||||
naturalidade: formData.naturalidade || null,
|
|
||||||
nacionalidade: formData.nacionalidade || null,
|
|
||||||
profissao: formData.profissao || null,
|
|
||||||
estado_civil: formData.estadoCivil || null,
|
|
||||||
nome_mae: formData.nomeMae || null,
|
|
||||||
profissao_mae: formData.profissaoMae || null,
|
|
||||||
nome_pai: formData.nomePai || null,
|
|
||||||
profissao_pai: formData.profissaoPai || null,
|
|
||||||
nome_responsavel: formData.nomeResponsavel || null,
|
|
||||||
cpf_responsavel: formData.cpfResponsavel || null,
|
|
||||||
contato: {
|
|
||||||
email: formData.email || null,
|
email: formData.email || null,
|
||||||
celular: formData.celular || null,
|
phone_mobile: formData.phoneMobile || null,
|
||||||
telefone1: formData.telefone1 || null,
|
birth_date: formData.dataNascimento || null,
|
||||||
telefone2: formData.telefone2 || null,
|
social_name: formData.nomeSocial || null,
|
||||||
},
|
sex: formData.sexo || null,
|
||||||
endereco: {
|
blood_type: formData.bloodType || null,
|
||||||
|
weight_kg: formData.weightKg ? Number(formData.weightKg) : null,
|
||||||
|
height_m: formData.heightM ? Number(formData.heightM) : null,
|
||||||
|
street: formData.street || null,
|
||||||
|
number: formData.number || null,
|
||||||
|
complement: formData.complement || null,
|
||||||
|
neighborhood: formData.neighborhood || null,
|
||||||
|
city: formData.city || null,
|
||||||
|
state: formData.state || null,
|
||||||
cep: formData.cep || null,
|
cep: formData.cep || null,
|
||||||
logradouro: formData.endereco || null,
|
|
||||||
numero: formData.numero || null,
|
|
||||||
complemento: formData.complemento || null,
|
|
||||||
bairro: formData.bairro || null,
|
|
||||||
cidade: formData.cidade || null,
|
|
||||||
estado: formData.estado || null,
|
|
||||||
},
|
|
||||||
observacoes: formData.observacoes || null,
|
|
||||||
convenio: formData.convenio || null,
|
|
||||||
plano: formData.plano || null,
|
|
||||||
numero_matricula: formData.numeroMatricula || null,
|
|
||||||
validade_carteira: formData.validadeCarteira || null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(payload)
|
||||||
|
console.log(JSON.stringify(payload))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}`, {
|
const res = await patientsService.update(patientId, JSON.stringify(payload));
|
||||||
method: "PUT",
|
console.log(res[0])
|
||||||
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
router.push("/secretary/pacientes");
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
if (!res.ok) throw new Error(`Falha ao atualizar (HTTP ${res.status})`);
|
|
||||||
toast({ title: "Sucesso", description: "Paciente atualizado com sucesso" });
|
|
||||||
router.push("/pacientes");
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
toast({ title: "Erro", description: err?.message || "Não foi possível atualizar o paciente" });
|
toast({ title: "Erro", description: err?.message || "Não foi possível atualizar o paciente" });
|
||||||
|
console.log("deu ruim")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate CPF on blur
|
|
||||||
const validateCpf = async (cpf: string) => {
|
|
||||||
if (!cpf) return;
|
|
||||||
try {
|
|
||||||
const res = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ cpf }),
|
|
||||||
});
|
|
||||||
const json = await res.json();
|
|
||||||
if (json?.success === false) {
|
|
||||||
throw new Error(json?.message || "CPF inválido");
|
|
||||||
}
|
|
||||||
if (json?.message) toast({ title: "CPF", description: String(json.message) });
|
|
||||||
} catch (err: any) {
|
|
||||||
toast({ title: "CPF inválido", description: err?.message || "Falha na validação de CPF" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// CEP lookup on blur
|
|
||||||
const lookupCep = async (cep: string) => {
|
|
||||||
const onlyDigits = cep?.replace(/\D/g, "");
|
|
||||||
if (!onlyDigits) return;
|
|
||||||
try {
|
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/utils/cep/${onlyDigits}`);
|
|
||||||
if (!res.ok) return;
|
|
||||||
const data = await res.json();
|
|
||||||
const d = data?.data || data;
|
|
||||||
setFormData((prev) => ({
|
|
||||||
...prev,
|
|
||||||
endereco: d?.logradouro ?? prev.endereco,
|
|
||||||
bairro: d?.bairro ?? prev.bairro,
|
|
||||||
cidade: d?.localidade ?? d?.cidade ?? prev.cidade,
|
|
||||||
estado: d?.uf ?? d?.estado ?? prev.estado,
|
|
||||||
complemento: d?.complemento ?? prev.complemento,
|
|
||||||
}));
|
|
||||||
} catch {}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SecretaryLayout>
|
<SecretaryLayout>
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
@ -403,8 +260,8 @@ export default function EditarPacientePage() {
|
|||||||
<div className="bg-white rounded-lg border border-gray-200 p-6">
|
<div className="bg-white rounded-lg border border-gray-200 p-6">
|
||||||
<h2 className="text-lg font-semibold text-gray-900 mb-6">Anexos</h2>
|
<h2 className="text-lg font-semibold text-gray-900 mb-6">Anexos</h2>
|
||||||
<div className="flex items-center gap-3 mb-4">
|
<div className="flex items-center gap-3 mb-4">
|
||||||
<input ref={anexoInputRef} type="file" className="hidden" onChange={onAnexoSelected} />
|
<input ref={anexoInputRef} type="file" className="hidden" />
|
||||||
<Button type="button" variant="outline" onClick={onPickAnexo} disabled={isUploadingAnexo}>
|
<Button type="button" variant="outline" disabled={isUploadingAnexo}>
|
||||||
<Paperclip className="w-4 h-4 mr-2" /> {isUploadingAnexo ? "Enviando..." : "Adicionar anexo"}
|
<Paperclip className="w-4 h-4 mr-2" /> {isUploadingAnexo ? "Enviando..." : "Adicionar anexo"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@ -418,7 +275,7 @@ export default function EditarPacientePage() {
|
|||||||
<Paperclip className="w-4 h-4 text-gray-500 shrink-0" />
|
<Paperclip className="w-4 h-4 text-gray-500 shrink-0" />
|
||||||
<span className="text-sm text-gray-800 truncate">{a.nome || a.filename || `Anexo ${a.id}`}</span>
|
<span className="text-sm text-gray-800 truncate">{a.nome || a.filename || `Anexo ${a.id}`}</span>
|
||||||
</div>
|
</div>
|
||||||
<Button type="button" variant="ghost" className="text-red-600" onClick={() => onDeleteAnexo(a.id)}>
|
<Button type="button" variant="ghost" className="text-red-600">
|
||||||
<Trash2 className="w-4 h-4 mr-1" /> Remover
|
<Trash2 className="w-4 h-4 mr-1" /> Remover
|
||||||
</Button>
|
</Button>
|
||||||
</li>
|
</li>
|
||||||
@ -446,12 +303,12 @@ export default function EditarPacientePage() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<input ref={fileInputRef} type="file" accept="image/*" className="hidden" onChange={onPhotoSelected} />
|
<input ref={fileInputRef} type="file" accept="image/*" className="hidden" />
|
||||||
<Button type="button" variant="outline" onClick={onPickPhoto} disabled={isUploadingPhoto}>
|
<Button type="button" variant="outline" disabled={isUploadingPhoto}>
|
||||||
{isUploadingPhoto ? "Enviando..." : "Enviar foto"}
|
{isUploadingPhoto ? "Enviando..." : "Enviar foto"}
|
||||||
</Button>
|
</Button>
|
||||||
{photoUrl && (
|
{photoUrl && (
|
||||||
<Button type="button" variant="ghost" onClick={onRemovePhoto} disabled={isUploadingPhoto}>
|
<Button type="button" variant="ghost" disabled={isUploadingPhoto}>
|
||||||
Remover
|
Remover
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@ -465,7 +322,7 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="cpf">CPF *</Label>
|
<Label htmlFor="cpf">CPF *</Label>
|
||||||
<Input id="cpf" value={formData.cpf} onChange={(e) => handleInputChange("cpf", e.target.value)} onBlur={() => validateCpf(formData.cpf)} placeholder="000.000.000-00" required />
|
<Input id="cpf" value={formData.cpf} onChange={(e) => handleInputChange("cpf", e.target.value)} placeholder="000.000.000-00" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@ -477,12 +334,12 @@ export default function EditarPacientePage() {
|
|||||||
<Label>Sexo *</Label>
|
<Label>Sexo *</Label>
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input type="radio" id="masculino" name="sexo" value="masculino" checked={formData.sexo === "masculino"} onChange={(e) => handleInputChange("sexo", e.target.value)} className="w-4 h-4 text-blue-600" />
|
<input type="radio" id="Masculino" name="sexo" value="Masculino" checked={formData.sexo === "Masculino"} onChange={(e) => handleInputChange("sexo", e.target.value)} className="w-4 h-4 text-blue-600" />
|
||||||
<Label htmlFor="masculino">Masculino</Label>
|
<Label htmlFor="Masculino">Masculino</Label>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input type="radio" id="feminino" name="sexo" value="feminino" checked={formData.sexo === "feminino"} onChange={(e) => handleInputChange("sexo", e.target.value)} className="w-4 h-4 text-blue-600" />
|
<input type="radio" id="Feminino" name="sexo" value="Feminino" checked={formData.sexo === "Feminino"} onChange={(e) => handleInputChange("sexo", e.target.value)} className="w-4 h-4 text-blue-600" />
|
||||||
<Label htmlFor="feminino">Feminino</Label>
|
<Label htmlFor="Feminino">Feminino</Label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -494,7 +351,7 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="etnia">Etnia</Label>
|
<Label htmlFor="etnia">Etnia</Label>
|
||||||
<Select value={formData.etnia} onValueChange={(value) => handleInputChange("etnia", value)}>
|
<Select value={formData.ethnicity} onValueChange={(value) => handleInputChange("ethnicity", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -510,7 +367,7 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="raca">Raça</Label>
|
<Label htmlFor="raca">Raça</Label>
|
||||||
<Select value={formData.raca} onValueChange={(value) => handleInputChange("raca", value)}>
|
<Select value={formData.race} onValueChange={(value) => handleInputChange("race", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -524,12 +381,12 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="naturalidade">Naturalidade</Label>
|
<Label htmlFor="naturalidade">Naturalidade</Label>
|
||||||
<Input id="naturalidade" value={formData.naturalidade} onChange={(e) => handleInputChange("naturalidade", e.target.value)} />
|
<Input id="naturalidade" value={formData.naturality} onChange={(e) => handleInputChange("naturality", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="nacionalidade">Nacionalidade</Label>
|
<Label htmlFor="nacionalidade">Nacionalidade</Label>
|
||||||
<Select value={formData.nacionalidade} onValueChange={(value) => handleInputChange("nacionalidade", value)}>
|
<Select value={formData.nationality} onValueChange={(value) => handleInputChange("nationality", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -542,12 +399,12 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="profissao">Profissão</Label>
|
<Label htmlFor="profissao">Profissão</Label>
|
||||||
<Input id="profissao" value={formData.profissao} onChange={(e) => handleInputChange("profissao", e.target.value)} />
|
<Input id="profissao" value={formData.profession} onChange={(e) => handleInputChange("profession", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="estadoCivil">Estado civil</Label>
|
<Label htmlFor="estadoCivil">Estado civil</Label>
|
||||||
<Select value={formData.estadoCivil} onValueChange={(value) => handleInputChange("estadoCivil", value)}>
|
<Select value={formData.maritalStatus} onValueChange={(value) => handleInputChange("maritalStatus", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -562,37 +419,37 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="nomeMae">Nome da mãe</Label>
|
<Label htmlFor="nomeMae">Nome da mãe</Label>
|
||||||
<Input id="nomeMae" value={formData.nomeMae} onChange={(e) => handleInputChange("nomeMae", e.target.value)} />
|
<Input id="nomeMae" value={formData.motherName} onChange={(e) => handleInputChange("motherName", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="profissaoMae">Profissão da mãe</Label>
|
<Label htmlFor="profissaoMae">Profissão da mãe</Label>
|
||||||
<Input id="profissaoMae" value={formData.profissaoMae} onChange={(e) => handleInputChange("profissaoMae", e.target.value)} />
|
<Input id="profissaoMae" value={formData.motherProfession} onChange={(e) => handleInputChange("motherProfession", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="nomePai">Nome do pai</Label>
|
<Label htmlFor="nomePai">Nome do pai</Label>
|
||||||
<Input id="nomePai" value={formData.nomePai} onChange={(e) => handleInputChange("nomePai", e.target.value)} />
|
<Input id="nomePai" value={formData.fatherName} onChange={(e) => handleInputChange("fatherName", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="profissaoPai">Profissão do pai</Label>
|
<Label htmlFor="profissaoPai">Profissão do pai</Label>
|
||||||
<Input id="profissaoPai" value={formData.profissaoPai} onChange={(e) => handleInputChange("profissaoPai", e.target.value)} />
|
<Input id="profissaoPai" value={formData.fatherProfession} onChange={(e) => handleInputChange("fatherProfession", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="nomeResponsavel">Nome do responsável</Label>
|
<Label htmlFor="nomeResponsavel">Nome do responsável</Label>
|
||||||
<Input id="nomeResponsavel" value={formData.nomeResponsavel} onChange={(e) => handleInputChange("nomeResponsavel", e.target.value)} />
|
<Input id="nomeResponsavel" value={formData.guardianName} onChange={(e) => handleInputChange("guardianName", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="cpfResponsavel">CPF do responsável</Label>
|
<Label htmlFor="cpfResponsavel">CPF do responsável</Label>
|
||||||
<Input id="cpfResponsavel" value={formData.cpfResponsavel} onChange={(e) => handleInputChange("cpfResponsavel", e.target.value)} placeholder="000.000.000-00" />
|
<Input id="cpfResponsavel" value={formData.guardianCpf} onChange={(e) => handleInputChange("guardianCpf", e.target.value)} placeholder="000.000.000-00" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="nomeEsposo">Nome do esposo(a)</Label>
|
<Label htmlFor="nomeEsposo">Nome do esposo(a)</Label>
|
||||||
<Input id="nomeEsposo" value={formData.nomeEsposo} onChange={(e) => handleInputChange("nomeEsposo", e.target.value)} />
|
<Input id="nomeEsposo" value={formData.spouseName} onChange={(e) => handleInputChange("spouseName", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -605,7 +462,7 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<Label htmlFor="observacoes">Observações</Label>
|
<Label htmlFor="observacoes">Observações</Label>
|
||||||
<Textarea id="observacoes" value={formData.observacoes} onChange={(e) => handleInputChange("observacoes", e.target.value)} placeholder="Digite observações sobre o paciente..." className="mt-2" />
|
<Textarea id="observacoes" value={formData.notes} onChange={(e) => handleInputChange("notes", e.target.value)} placeholder="Digite observações sobre o paciente..." className="mt-2" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -621,17 +478,17 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="celular">Celular</Label>
|
<Label htmlFor="celular">Celular</Label>
|
||||||
<Input id="celular" value={formData.celular} onChange={(e) => handleInputChange("celular", e.target.value)} placeholder="(00) 00000-0000" />
|
<Input id="celular" value={formData.phoneMobile} onChange={(e) => handleInputChange("phoneMobile", e.target.value)} placeholder="(00) 00000-0000" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="telefone1">Telefone 1</Label>
|
<Label htmlFor="telefone1">Telefone 1</Label>
|
||||||
<Input id="telefone1" value={formData.telefone1} onChange={(e) => handleInputChange("telefone1", e.target.value)} placeholder="(00) 0000-0000" />
|
<Input id="telefone1" value={formData.phone1} onChange={(e) => handleInputChange("phone1", e.target.value)} placeholder="(00) 0000-0000" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="telefone2">Telefone 2</Label>
|
<Label htmlFor="telefone2">Telefone 2</Label>
|
||||||
<Input id="telefone2" value={formData.telefone2} onChange={(e) => handleInputChange("telefone2", e.target.value)} placeholder="(00) 0000-0000" />
|
<Input id="telefone2" value={formData.phone2} onChange={(e) => handleInputChange("phone2", e.target.value)} placeholder="(00) 0000-0000" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -643,37 +500,37 @@ export default function EditarPacientePage() {
|
|||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="cep">CEP</Label>
|
<Label htmlFor="cep">CEP</Label>
|
||||||
<Input id="cep" value={formData.cep} onChange={(e) => handleInputChange("cep", e.target.value)} onBlur={() => lookupCep(formData.cep)} placeholder="00000-000" />
|
<Input id="cep" value={formData.cep} onChange={(e) => handleInputChange("cep", e.target.value)} placeholder="00000-000" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="endereco">Endereço</Label>
|
<Label htmlFor="endereco">Endereço</Label>
|
||||||
<Input id="endereco" value={formData.endereco} onChange={(e) => handleInputChange("endereco", e.target.value)} />
|
<Input id="endereco" value={formData.street} onChange={(e) => handleInputChange("street", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="numero">Número</Label>
|
<Label htmlFor="numero">Número</Label>
|
||||||
<Input id="numero" value={formData.numero} onChange={(e) => handleInputChange("numero", e.target.value)} />
|
<Input id="numero" value={formData.number} onChange={(e) => handleInputChange("number", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="complemento">Complemento</Label>
|
<Label htmlFor="complemento">Complemento</Label>
|
||||||
<Input id="complemento" value={formData.complemento} onChange={(e) => handleInputChange("complemento", e.target.value)} />
|
<Input id="complemento" value={formData.complement} onChange={(e) => handleInputChange("complement", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="bairro">Bairro</Label>
|
<Label htmlFor="bairro">Bairro</Label>
|
||||||
<Input id="bairro" value={formData.bairro} onChange={(e) => handleInputChange("bairro", e.target.value)} />
|
<Input id="bairro" value={formData.neighborhood} onChange={(e) => handleInputChange("neighborhood", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="cidade">Cidade</Label>
|
<Label htmlFor="cidade">Cidade</Label>
|
||||||
<Input id="cidade" value={formData.cidade} onChange={(e) => handleInputChange("cidade", e.target.value)} />
|
<Input id="cidade" value={formData.city} onChange={(e) => handleInputChange("city", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="estado">Estado</Label>
|
<Label htmlFor="estado">Estado</Label>
|
||||||
<Select value={formData.estado} onValueChange={(value) => handleInputChange("estado", value)}>
|
<Select value={formData.state} onValueChange={(value) => handleInputChange("state", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -718,7 +575,7 @@ export default function EditarPacientePage() {
|
|||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="tipoSanguineo">Tipo Sanguíneo</Label>
|
<Label htmlFor="tipoSanguineo">Tipo Sanguíneo</Label>
|
||||||
<Select value={formData.tipoSanguineo} onValueChange={(value) => handleInputChange("tipoSanguineo", value)}>
|
<Select value={formData.bloodType} onValueChange={(value) => handleInputChange("bloodType", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -737,23 +594,23 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="peso">Peso (kg)</Label>
|
<Label htmlFor="peso">Peso (kg)</Label>
|
||||||
<Input id="peso" type="number" value={formData.peso} onChange={(e) => handleInputChange("peso", e.target.value)} placeholder="0.0" />
|
<Input id="peso" type="number" value={formData.weightKg} onChange={(e) => handleInputChange("weightKg", e.target.value)} placeholder="0.0" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="altura">Altura (m)</Label>
|
<Label htmlFor="altura">Altura (m)</Label>
|
||||||
<Input id="altura" type="number" step="0.01" value={formData.altura} onChange={(e) => handleInputChange("altura", e.target.value)} placeholder="0.00" />
|
<Input id="altura" type="number" step="0.01" value={formData.heightM} onChange={(e) => handleInputChange("heightM", e.target.value)} placeholder="0.00" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>IMC</Label>
|
<Label>IMC</Label>
|
||||||
<Input value={formData.peso && formData.altura ? (Number.parseFloat(formData.peso) / Number.parseFloat(formData.altura) ** 2).toFixed(2) : ""} disabled placeholder="Calculado automaticamente" />
|
<Input value={formData.weightKg && formData.heightM ? (Number.parseFloat(formData.weightKg) / Number.parseFloat(formData.heightM) ** 2).toFixed(2) : ""} disabled placeholder="Calculado automaticamente" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<Label htmlFor="alergias">Alergias</Label>
|
<Label htmlFor="alergias">Alergias</Label>
|
||||||
<Textarea id="alergias" value={formData.alergias} onChange={(e) => handleInputChange("alergias", e.target.value)} placeholder="Ex: AAS, Dipirona, etc." className="mt-2" />
|
<Textarea id="alergias" onChange={(e) => handleInputChange("alergias", e.target.value)} placeholder="Ex: AAS, Dipirona, etc." className="mt-2" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -764,7 +621,7 @@ export default function EditarPacientePage() {
|
|||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="convenio">Convênio</Label>
|
<Label htmlFor="convenio">Convênio</Label>
|
||||||
<Select value={formData.convenio} onValueChange={(value) => handleInputChange("convenio", value)}>
|
<Select onValueChange={(value) => handleInputChange("convenio", value)}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecione" />
|
<SelectValue placeholder="Selecione" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@ -780,17 +637,17 @@ export default function EditarPacientePage() {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="plano">Plano</Label>
|
<Label htmlFor="plano">Plano</Label>
|
||||||
<Input id="plano" value={formData.plano} onChange={(e) => handleInputChange("plano", e.target.value)} />
|
<Input id="plano" onChange={(e) => handleInputChange("plano", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="numeroMatricula">Nº de matrícula</Label>
|
<Label htmlFor="numeroMatricula">Nº de matrícula</Label>
|
||||||
<Input id="numeroMatricula" value={formData.numeroMatricula} onChange={(e) => handleInputChange("numeroMatricula", e.target.value)} />
|
<Input id="numeroMatricula" onChange={(e) => handleInputChange("numeroMatricula", e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="validadeCarteira">Validade da Carteira</Label>
|
<Label htmlFor="validadeCarteira">Validade da Carteira</Label>
|
||||||
<Input id="validadeCarteira" type="date" value={formData.validadeCarteira} onChange={(e) => handleInputChange("validadeCarteira", e.target.value)} disabled={validadeIndeterminada} />
|
<Input id="validadeCarteira" type="date" onChange={(e) => handleInputChange("validadeCarteira", e.target.value)} disabled={validadeIndeterminada} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -803,7 +660,7 @@ export default function EditarPacientePage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end gap-4">
|
<div className="flex justify-end gap-4">
|
||||||
<Link href="/pacientes">
|
<Link href="/secretary/pacientes">
|
||||||
<Button type="button" variant="outline">
|
<Button type="button" variant="outline">
|
||||||
Cancelar
|
Cancelar
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -71,7 +71,7 @@ export default function NovoPacientePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sex = apiPayload.sex;
|
const sex = apiPayload.sex;
|
||||||
const allowedSex = ["masculino", "feminino", "outro"];
|
const allowedSex = ["Masculino", "Feminino", "outro"];
|
||||||
if (!sex || !allowedSex.includes(sex)) {
|
if (!sex || !allowedSex.includes(sex)) {
|
||||||
errors.push("Sexo é obrigatório e deve ser masculino, feminino ou outro.");
|
errors.push("Sexo é obrigatório e deve ser masculino, feminino ou outro.");
|
||||||
}
|
}
|
||||||
@ -102,6 +102,7 @@ export default function NovoPacientePage() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await patientsService.create(apiPayload);
|
const res = await patientsService.create(apiPayload);
|
||||||
|
console.log(res)
|
||||||
|
|
||||||
let message = "Paciente cadastrado com sucesso";
|
let message = "Paciente cadastrado com sucesso";
|
||||||
try {
|
try {
|
||||||
@ -202,11 +203,11 @@ export default function NovoPacientePage() {
|
|||||||
<Label className="text-sm font-medium text-gray-700">Sexo</Label>
|
<Label className="text-sm font-medium text-gray-700">Sexo</Label>
|
||||||
<div className="flex gap-4 mt-2">
|
<div className="flex gap-4 mt-2">
|
||||||
<label className="flex items-center gap-2">
|
<label className="flex items-center gap-2">
|
||||||
<input type="radio" name="sexo" value="masculino" className="text-blue-600" />
|
<input type="radio" name="sexo" value="Masculino" className="text-blue-600" />
|
||||||
<span className="text-sm">Masculino</span>
|
<span className="text-sm">Masculino</span>
|
||||||
</label>
|
</label>
|
||||||
<label className="flex items-center gap-2">
|
<label className="flex items-center gap-2">
|
||||||
<input type="radio" name="sexo" value="feminino" className="text-blue-600" />
|
<input type="radio" name="sexo" value="Feminino" className="text-blue-600" />
|
||||||
<span className="text-sm">Feminino</span>
|
<span className="text-sm">Feminino</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@ -438,7 +439,7 @@ export default function NovoPacientePage() {
|
|||||||
<SelectItem value="+55">+55</SelectItem>
|
<SelectItem value="+55">+55</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<Input name="celular" placeholder="(XX) XXXXX-XXXX" className="rounded-l-none" />
|
<Input id="celular" name="celular" placeholder="(XX) XXXXX-XXXX" className="rounded-l-none" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -342,6 +342,7 @@ export default function PacientesPage() {
|
|||||||
<p><strong>CEP:</strong> {patientDetails.cep ?? "-"}</p>
|
<p><strong>CEP:</strong> {patientDetails.cep ?? "-"}</p>
|
||||||
<p><strong>Criado em:</strong> {patientDetails.created_at ?? "-"}</p>
|
<p><strong>Criado em:</strong> {patientDetails.created_at ?? "-"}</p>
|
||||||
<p><strong>Atualizado em:</strong> {patientDetails.updated_at ?? "-"}</p>
|
<p><strong>Atualizado em:</strong> {patientDetails.updated_at ?? "-"}</p>
|
||||||
|
<p><strong>Id:</strong> {patientDetails.id ?? "-"}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
|
|||||||
@ -4,7 +4,7 @@ const BASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
|||||||
const API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
const API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
||||||
var tempToken;
|
var tempToken;
|
||||||
|
|
||||||
async function login() {
|
export async function login() {
|
||||||
const response = await fetch("https://yuanqfswhberkoevtmfr.supabase.co/auth/v1/token?grant_type=password", {
|
const response = await fetch("https://yuanqfswhberkoevtmfr.supabase.co/auth/v1/token?grant_type=password", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@ -21,7 +21,11 @@ async function login() {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
await login()
|
|
||||||
|
async function run(){
|
||||||
|
await login()
|
||||||
|
}
|
||||||
|
run()
|
||||||
|
|
||||||
async function request(endpoint, options = {}) {
|
async function request(endpoint, options = {}) {
|
||||||
const token = localStorage.getItem("token"); // token do usuário, salvo no login
|
const token = localStorage.getItem("token"); // token do usuário, salvo no login
|
||||||
@ -41,10 +45,20 @@ async function request(endpoint, options = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
const text = await response.text();
|
||||||
|
console.error("Erro HTTP:", response.status, text);
|
||||||
throw new Error(`Erro HTTP: ${response.status}`);
|
throw new Error(`Erro HTTP: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
// Lê a resposta como texto
|
||||||
|
const text = await response.text();
|
||||||
|
|
||||||
|
// Se não tiver conteúdo (204 ou 201 sem body), retorna null
|
||||||
|
if (!text) return null;
|
||||||
|
|
||||||
|
// Se tiver conteúdo, parseia como JSON
|
||||||
|
console.log(JSON.parse(text))
|
||||||
|
return JSON.parse(text);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro na requisição:", error);
|
console.error("Erro na requisição:", error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user