From 87d734071f3024fa6562d68702b1d64d16530e03 Mon Sep 17 00:00:00 2001 From: jp-lima Date: Mon, 29 Sep 2025 11:36:03 -0300 Subject: [PATCH] =?UTF-8?q?Form=20do=20m=C3=A9dico=20organizado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/doctors/DoctorForm.jsx | 153 +++++++++--------------- src/components/patients/PatientForm.jsx | 118 ++++++++---------- src/components/utils/Formatar/Format.js | 23 ++++ src/pages/DoctorDetails.jsx | 76 +++--------- 4 files changed, 142 insertions(+), 228 deletions(-) create mode 100644 src/components/utils/Formatar/Format.js diff --git a/src/components/doctors/DoctorForm.jsx b/src/components/doctors/DoctorForm.jsx index 7044d17e..7e3681c7 100644 --- a/src/components/doctors/DoctorForm.jsx +++ b/src/components/doctors/DoctorForm.jsx @@ -98,10 +98,10 @@ function DoctorForm({ onSave, onCancel, formData, setFormData }) { if (!data.erro) { setFormData((prev) => ({ ...prev, - rua: data.logradouro || '', - bairro: data.bairro || '', - cidade: data.localidade || '', - estado: data.uf || '' + street: data.logradouro || '', + neighborhood: data.bairro || '', + city: data.localidade || '', + state: data.uf || '' })); } else { setModalMsg('CEP não encontrado!'); @@ -115,15 +115,16 @@ function DoctorForm({ onSave, onCancel, formData, setFormData }) { }; const handleSubmit = () => { - if (!formData.nome || !formData.cpf || !formData.genero || !formData.dataNascimento ) { - setModalMsg('Por favor, preencha: Nome, CPF, Gênero, Data de Nascimento.'); + if (!formData.full_name || !formData.cpf || !formData.birth_date ) { + setModalMsg('Por favor, preencha: Nome, CPF, Data de Nascimento.'); setShowModal(true); + } onSave( { - ...formData, crm_uf:'SE',crm:'1234' + ...formData } ); @@ -210,69 +211,56 @@ function DoctorForm({ onSave, onCancel, formData, setFormData }) { -
- - -
-
- - -
-
- - -
-
+
-
-
- - -
-
- - + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
- - -
-
- - -
-
- - -
-
- - + +
+
- @@ -289,34 +277,6 @@ function DoctorForm({ onSave, onCancel, formData, setFormData }) {
-
- - -
-
- - -
- - {/* CAMPOS MOVIDOS */} -
- - -
-
- -
- - - {formData.anexos ? formData.anexos.name : 'Nenhum arquivo escolhido'} -
-
@@ -338,27 +298,27 @@ function DoctorForm({ onSave, onCancel, formData, setFormData }) {
- +
- +
- +
- +
- +
- +
@@ -380,16 +340,13 @@ function DoctorForm({ onSave, onCancel, formData, setFormData }) {
- +
- -
-
- - +
+ diff --git a/src/components/patients/PatientForm.jsx b/src/components/patients/PatientForm.jsx index 1c807c65..21f28877 100644 --- a/src/components/patients/PatientForm.jsx +++ b/src/components/patients/PatientForm.jsx @@ -1,5 +1,8 @@ import React, { useState, useEffect } from 'react'; import {Link} from 'react-router-dom' +// formatar número +// formatar CPF +import { FormatTelefones,FormatPeso } from '../utils/Formatar/Format'; function PatientForm({ onSave, onCancel, formData, setFormData }) { const [errorModalMsg, setErrorModalMsg] = useState(""); @@ -9,15 +12,6 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { const [pacienteExistente, setPacienteExistente] = useState(null); const [showSuccessModal, setShowSuccessModal] = useState(false); - const FormatTelefones = (valor) => { - 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 ReceberRespostaAPIdoCPF = async (cpf) =>{ var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer "); @@ -122,25 +116,16 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { }; // Lógica para calcular o IMC - /* useEffect(() => { + useEffect(() => { const peso = parseFloat(formData.peso); - const altura = parseFloat(formData.altura); + const altura = parseFloat(formData.height_m); if (peso > 0 && altura > 0) { const imcCalculado = peso / (altura * altura); - setFormData(prev => ({ ...prev, imc: imcCalculado.toFixed(2) })); + setFormData(prev => ({ ...prev, bmi: imcCalculado.toFixed(2) })); } else { - setFormData(prev => ({ ...prev, imc: '' })); + setFormData(prev => ({ ...prev, bmi: '' })); } }, [formData.peso, formData.altura]); -*/ - - const [enderecoData, setEnderecoData] = useState({}) - useEffect(() => {setEnderecoData(formData.endereco || {}); console.log(enderecoData)}, [formData.endereco]) - - const [contato, setContato] = useState({}) - - useEffect(() => {setContato(formData.contato || {})}, [formData.contato]) - const handleChange = (e) => { const { name, value, type, checked, files } = e.target; @@ -166,11 +151,10 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { if (name.includes('cpf')) { setFormData({...formData, cpf:FormatCPF(value) }); - } else if (name.includes('telefone')) { - let telefoneFormatado = FormatTelefones(value); - setContato(prev => ({ ...prev, [name]: telefoneFormatado })); - }else if(name.includes('endereco')) { - setEnderecoData(prev => ({ ...prev, [name.split('.')[1]]: value })); + } else if (name.includes('phone')) { + setFormData({ ...formData, [name]: FormatTelefones(value) }); + }else if(name.includes('weight') || name.includes('bmi') || name.includes('height')){ + setFormData({...formData,[name]: FormatPeso(value) }) }else{ setFormData({ ...formData, [name]: value }); } @@ -185,10 +169,10 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { if (!data.erro) { setFormData((prev) => ({ ...prev, - rua: data.logradouro || '', - bairro: data.bairro || '', - cidade: data.localidade || '', - estado: data.uf || '' + street: data.logradouro || '', + neighborhood: data.bairro || '', + city: data.localidade || '', + state: data.uf || '' })); } else { alert('CEP não encontrado!'); @@ -212,7 +196,7 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { } onSave({ - ...formData, + ...formData,bmi:12.0 }); setShowSuccessModal(true); }; @@ -278,7 +262,7 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
@@ -303,7 +287,7 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- @@ -312,11 +296,11 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
- @@ -327,20 +311,20 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
- +
- +
- + @@ -349,40 +333,36 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
- +
- +
- +
- +
- -
-
- - +
- +
- -
@@ -418,7 +398,7 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- @@ -432,15 +412,15 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
- +
- +
@@ -493,8 +473,8 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) { {/* PACIENTE VIP */}
- -
@@ -519,27 +499,27 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
- +
- +
- +
- +
- +
@@ -561,15 +541,15 @@ function PatientForm({ onSave, onCancel, formData, setFormData }) {
- +
- +
- +
diff --git a/src/components/utils/Formatar/Format.js b/src/components/utils/Formatar/Format.js new file mode 100644 index 00000000..47bf7098 --- /dev/null +++ b/src/components/utils/Formatar/Format.js @@ -0,0 +1,23 @@ + +const FormatPeso = (valor) => { + if (valor == null) return 0; + const str = String(valor).replace(',', '.'); + + const clean = str.replace(/[^0-9.]/g, ''); + console.log(parseFloat(clean)) + return parseFloat(clean); +} + + + +const FormatTelefones = (valor) => { + 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') + } + + + export {FormatTelefones, FormatPeso} \ No newline at end of file diff --git a/src/pages/DoctorDetails.jsx b/src/pages/DoctorDetails.jsx index 6eff1372..e3182c72 100644 --- a/src/pages/DoctorDetails.jsx +++ b/src/pages/DoctorDetails.jsx @@ -61,70 +61,27 @@ const Details = ({setCurrentPage }) => {

{doctor.full_name || "-"}

-
- -

{doctor.nomeSocial || "-"}

-

{doctor.birth_date || "-"}

-
- -

{doctor.sexo || "-"}

-
+

{doctor.cpf || "-"}

-

{doctor.rg || "-"}

+

{doctor.crm || "-"}

- -

{doctor.documento || "-"}

-
-
- -

{doctor.numeroDocumento || "-"}

-
- -
- -

{doctor.etniaRaca || "-"}

-
-
- -

{doctor.etniaRaca || "-"}

-
-
- -

{doctor.etniaRaca || "-"}

+ +

{doctor.crm_uf || "-"}

+
-

{doctor.profissao || "-"}

-
-
- -

{doctor.estadoCivil || "-"}

-
-
- -

{doctor.nomeConjuge || "-"}

-
-
- -

{doctor.outroId || "-"}

-
-
- -

{doctor.observacoes || "-"}

-
-
- -

{ "-"}

+

{doctor.specialty || "-"}

@@ -140,27 +97,27 @@ const Details = ({setCurrentPage }) => {
-

{doctor.rua || "-"}

+

{doctor.street || "-"}

-

{doctor.bairro || "-"}

+

{doctor.neighborhood || "-"}

-

{doctor.cidade || "-"}

+

{doctor.city || "-"}

-

{doctor.estado || "-"}

+

{doctor.state || "-"}

-

{doctor.numero || "-"}

+

{doctor.number || "-"}

-

{doctor.complemento || "-"}

+

{doctor.complement || "-"}

@@ -176,16 +133,13 @@ const Details = ({setCurrentPage }) => {
-

{doctor.telefone1 || "-"}

+

{doctor.phone_mobile || "-"}

-

{doctor.telefone2 || "-"}

-
-
- -

{doctor.telefone3 || "-"}

+

{doctor.phone2 || "-"}

+