From c5267f7b9ffe33f688cfc37c0f0e3f50352588a3 Mon Sep 17 00:00:00 2001 From: gilenosantos-a11y Date: Sat, 6 Sep 2025 18:22:57 -0300 Subject: [PATCH] Adicionando novas funcionalidades ao PatientForm --- src/components/patients/PatientForm.jsx | 357 ++++++++++++++++-------- 1 file changed, 241 insertions(+), 116 deletions(-) diff --git a/src/components/patients/PatientForm.jsx b/src/components/patients/PatientForm.jsx index f4eb448..3919c22 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -1,43 +1,31 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import InputMask from "react-input-mask"; function PatientForm({ onSave, onCancel, PatientDict }) { - const FormatTelefones = (valor) => { - - const digits = String(valor).replace(/\D/g, '').slice(0, 11); - - - return digits - .replace(/(\d)/, '($1') // 123 -> 123. - .replace(/(\d{2})(\d)/, '$1) $2' ) - .replace(/(\d)(\d{4})/, '$1 $2') - .replace(/(\d{4})(\d{4})/, '$1-$2') + const digits = String(valor).replace(/\D/g, '').slice(0, 11); + return digits + .replace(/(\d)/, '($1') + .replace(/(\d{2})(\d)/, '$1) $2' ) + .replace(/(\d)(\d{4})/, '$1 $2') + .replace(/(\d{4})(\d{4})/, '$1-$2') } - const FormatCPF = (valor) => { - - const digits = String(valor).replace(/\D/g, '').slice(0, 11); - - - - return digits - .replace(/(\d{3})(\d)/, '$1.$2') // 123 -> 123. - .replace(/(\d{3})(\d)/, '$1.$2') // 123.456 -> 123.456. - .replace(/(\d{3})(\d{1,2})$/, '$1-$2'); // 123.456.789 -> 123.456.789-01 - + const digits = String(valor).replace(/\D/g, '').slice(0, 11); + return digits + .replace(/(\d{3})(\d)/, '$1.$2') + .replace(/(\d{3})(\d)/, '$1.$2') + .replace(/(\d{3})(\d{1,2})$/, '$1-$2'); } - const [formData, setFormData] = useState({ + foto: null, nome: PatientDict.nome, nomeSocial: PatientDict.nome_social, dataNascimento: PatientDict.data_nascimento, genero: PatientDict.sexo, - documento: '', - numeroDocumento: '', cpf: PatientDict.cpf, profissao: PatientDict.profissao , nomeMae: PatientDict.nome_mae, @@ -59,50 +47,67 @@ function PatientForm({ onSave, onCancel, PatientDict }) { telefone1: PatientDict.celular, telefone2: '', telefone3: '', - observacoes: '' + observacoes: '', + rg: '', + documentoTipo: '', + numeroDocumento: '', + etniaRaca: '', + naturalidade: '', + nacionalidade: '', + estadoCivil: '', + rnConvenio: false, + + // NOVOS CAMPOS: INFORMAÇÕES MÉDICAS + tipoSanguineo: '', + peso: '', + altura: '', + imc: '', + alergias: '', + + // NOVOS CAMPOS: INFORMAÇÕES DE CONVÊNIO + convenio: '', + plano: '', + numeroMatricula: '', + validadeCarteira: '', + validadeIndeterminada: false, + + // NOVO CAMPO: ANEXOS + anexos: null, }); + // Lógica para calcular o IMC + useEffect(() => { + const peso = parseFloat(formData.peso); + const altura = parseFloat(formData.altura); + if (peso > 0 && altura > 0) { + const imcCalculado = peso / (altura * altura); + setFormData(prev => ({ ...prev, imc: imcCalculado.toFixed(2) })); + } else { + setFormData(prev => ({ ...prev, imc: '' })); + } + }, [formData.peso, formData.altura]); + + const handleChange = (e) => { - const { name, value } = e.target; - setFormData({ - ...formData, - [name]: value - }); - - - if(name.includes('cpf')){ - - let cpfFormatado = FormatCPF(e.target.value) - - setFormData({...formData, - [name]: cpfFormatado,} - )} - - else if(name.includes('telefone')){ - let telefoneFormatado = FormatTelefones(value) - - console.log(telefoneFormatado) - - - - setFormData({...formData, - [name]: telefoneFormatado - }) + const { name, value, type, checked, files } = e.target; + + if (type === 'checkbox') { + setFormData({ ...formData, [name]: checked }); + } else if (type === 'file') { + setFormData({ ...formData, [name]: files[0] }); + } else { + setFormData({ ...formData, [name]: value }); } - else if(name.includes('cep')){ - const digitsCep = String(value).replace(/\D/g, '').slice(0, 8); - setFormData({...formData, - [name]: digitsCep - }) - } - - - - }; - + if (name.includes('cpf')) { + let cpfFormatado = FormatCPF(value); + setFormData(prev => ({ ...prev, [name]: cpfFormatado })); + } else if (name.includes('telefone')) { + let telefoneFormatado = FormatTelefones(value); + setFormData(prev => ({ ...prev, [name]: telefoneFormatado })); + } + }; - // Função para buscar endereço pelo CEP const handleCepBlur = async () => { const cep = formData.cep.replace(/\D/g, ''); if (cep.length === 8) { @@ -127,61 +132,58 @@ function PatientForm({ onSave, onCancel, PatientDict }) { }; const handleSubmit = () => { - if (!formData.nome || !formData.cpf || !formData.genero || !formData.dataNascimento || !formData.email||!formData.telefone1){ - alert('Por favor, preencha: Nome ,CPF, Gênero, Data de nascimento, telefone e Email.'); + if (!formData.nome || !formData.cpf || !formData.genero || !formData.dataNascimento){ + alert('Por favor, preencha Nome ,CPF, Gênero e data de nascimento.'); return; } - onSave( - {nome: formData.nome, - nomeSocial: formData.nomeSocial, - dataNascimento: formData.dataNascimento, - genero: formData.genero, - documento: formData.documento, - numeroDocumento: formData.numeroDocumento, - cpf: formData.cpf, - profissao: formData.profissao, - nomeMae: formData.nomeMae, - profissaoMae: formData.profissaoMae, - nomePai: formData.nomePai, - profissaoPai: formData.profissaoPai, - nomeResponsavel: formData.nomeResponsavel, - cpfResponsavel: formData.cpfResponsavel, - nomeConjuge: formData.nomeConjuge, - outroId: formData.outroId, - endereco: { - cep: formData.cep, - cidade: formData.cidade, - estado: formData.estado, - bairro: formData.bairro, - logradouro: formData.rua, - numero: formData.numero, - complemento: formData.complemento, - }, - - contato: { - email: formData.email, - telefone1: formData.telefone1, - telefone2: formData.telefone2, - telefone3: formData.telefone3, - }, - - observacoes: formData.observacoes, -} - - - ); + onSave({ + ...formData, + endereco: { + cep: formData.cep, + cidade: formData.cidade, + estado: formData.estado, + bairro: formData.bairro, + logradouro: formData.rua, + numero: formData.numero, + complemento: formData.complemento, + }, + contato: { + email: formData.email, + telefone1: formData.telefone1, + telefone2: formData.telefone2, + telefone3: formData.telefone3, + }, + infoMedicas: { + tipoSanguineo: formData.tipoSanguineo, + peso: formData.peso, + altura: formData.altura, + imc: formData.imc, + alergias: formData.alergias, + }, + infoConvenio: { + convenio: formData.convenio, + plano: formData.plano, + numeroMatricula: formData.numeroMatricula, + validadeCarteira: formData.validadeCarteira, + validadeIndeterminada: formData.validadeIndeterminada, + }, + }); }; return (
-

MediConnect

+

MedicoConnect

{/* ------------------ DADOS PESSOAIS ------------------ */}
Dados Pessoais
- + + +
+
+
@@ -189,11 +191,11 @@ function PatientForm({ onSave, onCancel, PatientDict }) {
- +
- +
- - + + +
+
+ + +
+
+ +
- - + + +
+
+ + +
+
+ +
+
+ + +
@@ -249,6 +288,84 @@ function PatientForm({ onSave, onCancel, PatientDict }) {
+
+
+ + +
+
+
+ + {/* ------------------ INFORMAÇÕES MÉDICAS ------------------ */} +
Informações Médicas
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + {/* ------------------ INFORMAÇÕES DE CONVÊNIO ------------------ */} +
Informações de convênio
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
{/* ------------------ ENDEREÇO ------------------ */} @@ -288,11 +405,11 @@ function PatientForm({ onSave, onCancel, PatientDict }) {
Contato
- +
- +
@@ -306,11 +423,19 @@ function PatientForm({ onSave, onCancel, PatientDict }) {
{/* ------------------ INFORMAÇÕES ADICIONAIS ------------------ */} -
Informações Adicionais
+
Informações Adicionais
+ + {/* ------------------ ANEXOS DO PACIENTE ------------------ */} +
Anexos do Paciente
+
+ + + {formData.anexos ? formData.anexos.name : 'Nenhum arquivo escolhido'} +
{/* Botões */}
@@ -325,4 +450,4 @@ function PatientForm({ onSave, onCancel, PatientDict }) { ); } -export default PatientForm; +export default PatientForm; \ No newline at end of file