Começo da funcionalidade de CPF
This commit is contained in:
parent
f37865d251
commit
cdc6d39f77
@ -13,16 +13,27 @@ const FormNovaConsulta = ({ onCancel }) => {
|
|||||||
if(resultado === false){ setAcessibilidade({...acessibilidade, [id]:true}); console.log('mudou')}
|
if(resultado === false){ setAcessibilidade({...acessibilidade, [id]:true}); console.log('mudou')}
|
||||||
|
|
||||||
else if(resultado === true){ setAcessibilidade({...acessibilidade, [id]:false})}
|
else if(resultado === true){ setAcessibilidade({...acessibilidade, [id]:false})}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log(id)
|
console.log(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const FormatCPF = (valor) => {
|
||||||
|
|
||||||
|
|
||||||
|
console.log(valor)
|
||||||
|
|
||||||
|
const digits = String(valor).replace(/\D/g, '').slice(0, 11);
|
||||||
|
BuscarPacienteExistentePeloCPF(valor)
|
||||||
|
|
||||||
|
return digits
|
||||||
|
.replace(/(\d{3})(\d)/, '$1.$2')
|
||||||
|
.replace(/(\d{3})(\d)/, '$1.$2')
|
||||||
|
.replace(/(\d{3})(\d{1,2})$/, '$1-$2');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const BuscarCPFnoBancodeDados = (cpf) => {
|
|
||||||
|
const BuscarCPFnoBancodeDados = async (cpf) => {
|
||||||
|
|
||||||
var myHeaders = new Headers();
|
var myHeaders = new Headers();
|
||||||
myHeaders.append("Authorization", "Bearer <token>");
|
myHeaders.append("Authorization", "Bearer <token>");
|
||||||
@ -39,16 +50,40 @@ const FormNovaConsulta = ({ onCancel }) => {
|
|||||||
redirect: 'follow'
|
redirect: 'follow'
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requestOptions)
|
const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requestOptions);
|
||||||
.then(response => response.text())
|
const result = await response.json();
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const BuscarPacienteExistentePeloCPF = async (value) => {
|
||||||
|
|
||||||
|
if(isNaN(value[13]) === false && value.length === 14)try {
|
||||||
|
const result = await BuscarCPFnoBancodeDados(value);
|
||||||
|
console.log("Resultado:", result);
|
||||||
|
|
||||||
|
if (result.data.existe === true){
|
||||||
|
|
||||||
|
var myHeaders = new Headers();
|
||||||
|
myHeaders.append("Authorization", "Bearer <token>");
|
||||||
|
|
||||||
|
var requestOptions = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: myHeaders,
|
||||||
|
redirect: 'follow'
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/", requestOptions)
|
||||||
|
.then(response => response.json())
|
||||||
.then(result => console.log(result))
|
.then(result => console.log(result))
|
||||||
.catch(error => console.log('error', error));
|
.catch(error => console.log('error', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
const BuscarPacienteExistentePeloCPF = (value) => {
|
|
||||||
|
|
||||||
if(isNaN(value[13]) === false){
|
|
||||||
BuscarCPFnoBancodeDados(value)
|
} catch (error) {
|
||||||
|
console.log("error", error);
|
||||||
}
|
}
|
||||||
//BuscarCPFnoBancodeDados(value)
|
//BuscarCPFnoBancodeDados(value)
|
||||||
|
|
||||||
@ -75,9 +110,9 @@ fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requ
|
|||||||
|
|
||||||
<div className="campo-de-input">
|
<div className="campo-de-input">
|
||||||
<label>CPF do paciente</label>
|
<label>CPF do paciente</label>
|
||||||
<InputMask mask="999.999.999-99" placeholder="000.000.000-00" onChange={(e) => BuscarPacienteExistentePeloCPF(e.target.value)}>
|
|
||||||
{(inputProps) => <input {...inputProps} type="text" name="cpf" />}
|
<input type="text" name="cpf" placeholder="000.000.000-00" onChange={(e) => e.target.value = FormatCPF(e.target.value)} />
|
||||||
</InputMask>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="campo-de-input">
|
<div className="campo-de-input">
|
||||||
|
|||||||
@ -31,7 +31,7 @@ function PatientCadastroManager( {setCurrentPage} ) {
|
|||||||
.then(result => console.log(result))
|
.then(result => console.log(result))
|
||||||
.catch(error => console.log('error', error));
|
.catch(error => console.log('error', error));
|
||||||
|
|
||||||
alert(`Paciente "${patientData.nome}" salvo com sucesso!`); //altere isso para integração com backend
|
alert(`Paciente "${patientData.nome}" !`); //altere isso para integração com backend
|
||||||
// Após salvar, voltamos para a tela de lista
|
// Após salvar, voltamos para a tela de lista
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -59,9 +59,6 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Função para excluir paciente
|
// Função para excluir paciente
|
||||||
const deletePatient = async (id) => {
|
const deletePatient = async (id) => {
|
||||||
DeleteAnexo(id)
|
DeleteAnexo(id)
|
||||||
@ -79,45 +76,7 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
.catch((error) => console.log("Deu problema", error));
|
.catch((error) => console.log("Deu problema", error));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Função para marcar/desmarcar VIP
|
|
||||||
const toggleVIP = async (id, atual) => {
|
|
||||||
const novoStatus = atual === true ? false : true;
|
|
||||||
|
|
||||||
await fetch(
|
|
||||||
`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`,
|
|
||||||
{
|
|
||||||
method: "PUT",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ vip: novoStatus }),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then(() => {
|
|
||||||
setPacientes((prev) =>
|
|
||||||
prev.map((p) => (p.id === id ? { ...p, vip: novoStatus } : p))
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((error) => console.log("Erro ao atualizar VIP:", error));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Função para atualizar convênio/particular
|
|
||||||
const updateConvenio = async (id, convenio) => {
|
|
||||||
await fetch(
|
|
||||||
`https://mock.apidog.com/m1/1053378-0-default/pacientes/${id}`,
|
|
||||||
{
|
|
||||||
method: "PUT",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ convenio }),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then(() => {
|
|
||||||
setPacientes((prev) =>
|
|
||||||
prev.map((p) => (p.id === id ? { ...p, convenio } : p))
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((error) => console.log("Erro ao atualizar convênio:", error));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Requisição inicial para buscar pacientes
|
// Requisição inicial para buscar pacientes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user